Rev 1839 | Rev 1888 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 1839 | Rev 1854 | ||
|---|---|---|---|
| Line 50... | Line 50... | ||
| 50 | #include <mm/slab.h> |
50 | #include <mm/slab.h> |
| 51 | #include <proc/uarg.h> |
51 | #include <proc/uarg.h> |
| 52 | 52 | ||
| 53 | #define THREAD_STACK_SIZE STACK_SIZE |
53 | #define THREAD_STACK_SIZE STACK_SIZE |
| 54 | 54 | ||
| 55 | /**< Thread states. */ |
55 | /** Thread states. */ |
| 56 | enum state { |
56 | enum state { |
| 57 | Invalid, /**< It is an error, if thread is found in this state. */ |
57 | Invalid, /**< It is an error, if thread is found in this state. */ |
| 58 | Running, /**< State of a thread that is currently executing on some CPU. */ |
58 | Running, /**< State of a thread that is currently executing on some CPU. */ |
| 59 | Sleeping, /**< Thread in this state is waiting for an event. */ |
59 | Sleeping, /**< Thread in this state is waiting for an event. */ |
| 60 | Ready, /**< State of threads in a run queue. */ |
60 | Ready, /**< State of threads in a run queue. */ |
| Line 63... | Line 63... | ||
| 63 | Undead /**< Threads that were not detached but exited are in the Undead state. */ |
63 | Undead /**< Threads that were not detached but exited are in the Undead state. */ |
| 64 | }; |
64 | }; |
| 65 | 65 | ||
| 66 | extern char *thread_states[]; |
66 | extern char *thread_states[]; |
| 67 | 67 | ||
| 68 | /**< Join types. */ |
68 | /** Join types. */ |
| 69 | typedef enum { |
69 | typedef enum { |
| 70 | None, |
70 | None, |
| 71 | TaskClnp, /**< The thread will be joined by ktaskclnp thread. */ |
71 | TaskClnp, /**< The thread will be joined by ktaskclnp thread. */ |
| 72 | TaskGC /**< The thread will be joined by ktaskgc thread. */ |
72 | TaskGC /**< The thread will be joined by ktaskgc thread. */ |
| 73 | } thread_join_type_t; |
73 | } thread_join_type_t; |
| 74 | 74 | ||
| 75 | #define X_WIRED (1<<0) |
75 | /* Thread flags */ |
| - | 76 | #define THREAD_FLAG_WIRED (1<<0) /**< Thread cannot be migrated to another CPU. */ |
|
| - | 77 | #define THREAD_FLAG_STOLEN (1<<1) /**< Thread was migrated to another CPU and has not run yet. */ |
|
| 76 | #define X_STOLEN (1<<1) |
78 | #define THREAD_FLAG_USPACE (1<<2) /**< Thread executes in userspace. */ |
| 77 | 79 | ||
| 78 | #define THREAD_NAME_BUFLEN 20 |
80 | #define THREAD_NAME_BUFLEN 20 |
| 79 | 81 | ||
| 80 | /** Thread structure. There is one per thread. */ |
82 | /** Thread structure. There is one per thread. */ |
| 81 | struct thread { |
83 | struct thread { |
| Line 125... | Line 127... | ||
| 125 | int fpu_context_exists; |
127 | int fpu_context_exists; |
| 126 | 128 | ||
| 127 | /* |
129 | /* |
| 128 | * Defined only if thread doesn't run. |
130 | * Defined only if thread doesn't run. |
| 129 | * It means that fpu context is in CPU that last time executes this thread. |
131 | * It means that fpu context is in CPU that last time executes this thread. |
| 130 | * This disables migration |
132 | * This disables migration. |
| 131 | */ |
133 | */ |
| 132 | int fpu_context_engaged; |
134 | int fpu_context_engaged; |
| 133 | 135 | ||
| 134 | rwlock_type_t rwlock_holder_type; |
136 | rwlock_type_t rwlock_holder_type; |
| 135 | 137 | ||
| Line 147... | Line 149... | ||
| 147 | int priority; /**< Thread's priority. Implemented as index to CPU->rq */ |
149 | int priority; /**< Thread's priority. Implemented as index to CPU->rq */ |
| 148 | uint32_t tid; /**< Thread ID. */ |
150 | uint32_t tid; /**< Thread ID. */ |
| 149 | 151 | ||
| 150 | thread_arch_t arch; /**< Architecture-specific data. */ |
152 | thread_arch_t arch; /**< Architecture-specific data. */ |
| 151 | 153 | ||
| 152 | uint8_t *kstack; /**< Thread's kernel stack. */ |
154 | uint8_t *kstack; /**< Thread's kernel stack. */ |
| 153 | }; |
155 | }; |
| 154 | 156 | ||
| 155 | /** Thread list lock. |
157 | /** Thread list lock. |
| 156 | * |
158 | * |
| 157 | * This lock protects all link_t structures chained in threads_head. |
159 | * This lock protects all link_t structures chained in threads_head. |
| Line 168... | Line 170... | ||
| 168 | extern void thread_exit(void) __attribute__((noreturn)); |
170 | extern void thread_exit(void) __attribute__((noreturn)); |
| 169 | 171 | ||
| 170 | #ifndef thread_create_arch |
172 | #ifndef thread_create_arch |
| 171 | extern void thread_create_arch(thread_t *t); |
173 | extern void thread_create_arch(thread_t *t); |
| 172 | #endif |
174 | #endif |
| - | 175 | #ifndef thr_constructor_arch |
|
| - | 176 | extern void thr_constructor_arch(thread_t *t); |
|
| - | 177 | #endif |
|
| - | 178 | #ifndef thr_destructor_arch |
|
| - | 179 | extern void thr_destructor_arch(thread_t *t); |
|
| - | 180 | #endif |
|
| 173 | 181 | ||
| 174 | extern void thread_sleep(uint32_t sec); |
182 | extern void thread_sleep(uint32_t sec); |
| 175 | extern void thread_usleep(uint32_t usec); |
183 | extern void thread_usleep(uint32_t usec); |
| 176 | 184 | ||
| 177 | #define thread_join(t) thread_join_timeout((t), SYNCH_NO_TIMEOUT, SYNCH_FLAGS_NONE) |
185 | #define thread_join(t) thread_join_timeout((t), SYNCH_NO_TIMEOUT, SYNCH_FLAGS_NONE) |