Rev 2089 | Rev 2096 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2089 | Rev 2093 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (c) 2001-2004 Jakub Jermar |
2 | * Copyright (c) 2001-2004 Jakub Jermar |
3 | * All rights reserved. |
3 | * All rights reserved. |
4 | * |
4 | * |
5 | * Redistribution and use in source and binary forms, with or without |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions |
6 | * modification, are permitted provided that the following conditions |
7 | * are met: |
7 | * are met: |
8 | * |
8 | * |
9 | * - Redistributions of source code must retain the above copyright |
9 | * - Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. |
10 | * notice, this list of conditions and the following disclaimer. |
11 | * - Redistributions in binary form must reproduce the above copyright |
11 | * - Redistributions in binary form must reproduce the above copyright |
12 | * notice, this list of conditions and the following disclaimer in the |
12 | * notice, this list of conditions and the following disclaimer in the |
13 | * documentation and/or other materials provided with the distribution. |
13 | * documentation and/or other materials provided with the distribution. |
14 | * - The name of the author may not be used to endorse or promote products |
14 | * - The name of the author may not be used to endorse or promote products |
15 | * derived from this software without specific prior written permission. |
15 | * derived from this software without specific prior written permission. |
16 | * |
16 | * |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | */ |
27 | */ |
28 | 28 | ||
29 | /** @addtogroup genericproc |
29 | /** @addtogroup genericproc |
30 | * @{ |
30 | * @{ |
31 | */ |
31 | */ |
32 | /** @file |
32 | /** @file |
33 | */ |
33 | */ |
34 | 34 | ||
35 | #ifndef KERN_THREAD_H_ |
35 | #ifndef KERN_THREAD_H_ |
36 | #define KERN_THREAD_H_ |
36 | #define KERN_THREAD_H_ |
37 | 37 | ||
38 | #include <synch/waitq.h> |
38 | #include <synch/waitq.h> |
39 | #include <proc/task.h> |
39 | #include <proc/task.h> |
40 | #include <cpu.h> |
40 | #include <cpu.h> |
41 | #include <synch/rwlock.h> |
41 | #include <synch/rwlock.h> |
42 | #include <adt/btree.h> |
42 | #include <adt/btree.h> |
43 | #include <mm/slab.h> |
43 | #include <mm/slab.h> |
44 | #include <arch/cpu.h> |
44 | #include <arch/cpu.h> |
45 | #include <mm/tlb.h> |
45 | #include <mm/tlb.h> |
46 | #include <proc/uarg.h> |
46 | #include <proc/uarg.h> |
47 | 47 | ||
48 | #define THREAD_STACK_SIZE STACK_SIZE |
48 | #define THREAD_STACK_SIZE STACK_SIZE |
49 | 49 | ||
50 | extern char *thread_states[]; |
50 | extern char *thread_states[]; |
51 | 51 | ||
52 | /* Thread flags */ |
52 | /* Thread flags */ |
53 | #define THREAD_FLAG_WIRED (1 << 0) /**< Thread cannot be migrated to another CPU. */ |
53 | #define THREAD_FLAG_WIRED (1 << 0) /**< Thread cannot be migrated to another CPU. */ |
54 | #define THREAD_FLAG_STOLEN (1 << 1) /**< Thread was migrated to another CPU and has not run yet. */ |
54 | #define THREAD_FLAG_STOLEN (1 << 1) /**< Thread was migrated to another CPU and has not run yet. */ |
55 | #define THREAD_FLAG_USPACE (1 << 2) /**< Thread executes in userspace. */ |
55 | #define THREAD_FLAG_USPACE (1 << 2) /**< Thread executes in userspace. */ |
56 | 56 | ||
57 | /** Thread list lock. |
57 | /** Thread list lock. |
58 | * |
58 | * |
59 | * This lock protects all link_t structures chained in threads_head. |
59 | * This lock protects all link_t structures chained in threads_head. |
60 | * Must be acquired before T.lock for each T of type thread_t. |
60 | * Must be acquired before T.lock for each T of type thread_t. |
61 | * |
61 | * |
62 | */ |
62 | */ |
63 | extern spinlock_t threads_lock; |
63 | SPINLOCK_EXTERN(threads_lock); |
64 | 64 | ||
65 | extern btree_t threads_btree; /**< B+tree containing all threads. */ |
65 | extern btree_t threads_btree; /**< B+tree containing all threads. */ |
66 | 66 | ||
67 | extern void thread_init(void); |
67 | extern void thread_init(void); |
68 | extern thread_t *thread_create(void (* func)(void *), void *arg, task_t *task, int flags, char *name, bool uncounted); |
68 | extern thread_t *thread_create(void (* func)(void *), void *arg, task_t *task, int flags, char *name, bool uncounted); |
69 | extern void thread_ready(thread_t *t); |
69 | extern void thread_ready(thread_t *t); |
70 | extern void thread_exit(void) __attribute__((noreturn)); |
70 | extern void thread_exit(void) __attribute__((noreturn)); |
71 | 71 | ||
72 | #ifndef thread_create_arch |
72 | #ifndef thread_create_arch |
73 | extern void thread_create_arch(thread_t *t); |
73 | extern void thread_create_arch(thread_t *t); |
74 | #endif |
74 | #endif |
75 | #ifndef thr_constructor_arch |
75 | #ifndef thr_constructor_arch |
76 | extern void thr_constructor_arch(thread_t *t); |
76 | extern void thr_constructor_arch(thread_t *t); |
77 | #endif |
77 | #endif |
78 | #ifndef thr_destructor_arch |
78 | #ifndef thr_destructor_arch |
79 | extern void thr_destructor_arch(thread_t *t); |
79 | extern void thr_destructor_arch(thread_t *t); |
80 | #endif |
80 | #endif |
81 | 81 | ||
82 | extern void thread_sleep(uint32_t sec); |
82 | extern void thread_sleep(uint32_t sec); |
83 | extern void thread_usleep(uint32_t usec); |
83 | extern void thread_usleep(uint32_t usec); |
84 | 84 | ||
85 | #define thread_join(t) thread_join_timeout((t), SYNCH_NO_TIMEOUT, SYNCH_FLAGS_NONE) |
85 | #define thread_join(t) thread_join_timeout((t), SYNCH_NO_TIMEOUT, SYNCH_FLAGS_NONE) |
86 | extern int thread_join_timeout(thread_t *t, uint32_t usec, int flags); |
86 | extern int thread_join_timeout(thread_t *t, uint32_t usec, int flags); |
87 | extern void thread_detach(thread_t *t); |
87 | extern void thread_detach(thread_t *t); |
88 | 88 | ||
89 | extern void thread_register_call_me(void (* call_me)(void *), void *call_me_with); |
89 | extern void thread_register_call_me(void (* call_me)(void *), void *call_me_with); |
90 | extern void thread_print_list(void); |
90 | extern void thread_print_list(void); |
91 | extern void thread_destroy(thread_t *t); |
91 | extern void thread_destroy(thread_t *t); |
92 | extern void thread_update_accounting(void); |
92 | extern void thread_update_accounting(void); |
93 | extern bool thread_exists(thread_t *t); |
93 | extern bool thread_exists(thread_t *t); |
94 | extern void thread_interrupt_sleep(thread_t *t); |
94 | extern void thread_interrupt_sleep(thread_t *t); |
95 | 95 | ||
96 | /* Fpu context slab cache */ |
96 | /* Fpu context slab cache */ |
97 | extern slab_cache_t *fpu_context_slab; |
97 | extern slab_cache_t *fpu_context_slab; |
98 | 98 | ||
99 | /** Thread syscall prototypes. */ |
99 | /** Thread syscall prototypes. */ |
100 | unative_t sys_thread_create(uspace_arg_t *uspace_uarg, char *uspace_name); |
100 | unative_t sys_thread_create(uspace_arg_t *uspace_uarg, char *uspace_name); |
101 | unative_t sys_thread_exit(int uspace_status); |
101 | unative_t sys_thread_exit(int uspace_status); |
102 | 102 | ||
103 | #endif |
103 | #endif |
104 | 104 | ||
105 | /** @} |
105 | /** @} |
106 | */ |
106 | */ |
107 | 107 |