Changes in kernel/generic/include/proc/thread.h [7faabb7:df58e44] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/include/proc/thread.h
r7faabb7 rdf58e44 40 40 #include <time/timeout.h> 41 41 #include <cpu.h> 42 #include <synch/rwlock.h>43 42 #include <synch/spinlock.h> 44 43 #include <adt/avl.h> … … 48 47 #include <proc/uarg.h> 49 48 #include <udebug/udebug.h> 50 51 #define THREAD_STACK_SIZE STACK_SIZE 52 #define THREAD_NAME_BUFLEN 20 53 54 extern char *thread_states[]; 49 #include <sysinfo/abi.h> 50 51 #define THREAD_STACK_SIZE STACK_SIZE 52 #define THREAD_NAME_BUFLEN 20 53 54 extern const char *thread_states[]; 55 55 56 56 /* Thread flags */ … … 60 60 * When using this flag, the caller must set cpu in the thread_t 61 61 * structure manually before calling thread_ready (even on uniprocessor). 62 */ 63 #define THREAD_FLAG_WIRED (1 << 0) 62 * 63 */ 64 #define THREAD_FLAG_WIRED (1 << 0) 65 64 66 /** Thread was migrated to another CPU and has not run yet. */ 65 #define THREAD_FLAG_STOLEN (1 << 1) 67 #define THREAD_FLAG_STOLEN (1 << 1) 68 66 69 /** Thread executes in userspace. */ 67 #define THREAD_FLAG_USPACE (1 << 2) 70 #define THREAD_FLAG_USPACE (1 << 2) 71 68 72 /** Thread will be attached by the caller. */ 69 #define THREAD_FLAG_NOATTACH (1 << 3) 70 71 /** Thread states. */ 72 typedef enum { 73 /** It is an error, if thread is found in this state. */ 74 Invalid, 75 /** State of a thread that is currently executing on some CPU. */ 76 Running, 77 /** Thread in this state is waiting for an event. */ 78 Sleeping, 79 /** State of threads in a run queue. */ 80 Ready, 81 /** Threads are in this state before they are first readied. */ 82 Entering, 83 /** After a thread calls thread_exit(), it is put into Exiting state. */ 84 Exiting, 85 /** Threads that were not detached but exited are Lingering. */ 86 Lingering 87 } state_t; 73 #define THREAD_FLAG_NOATTACH (1 << 3) 88 74 89 75 /** Thread structure. There is one per thread. */ 90 76 typedef struct thread { 91 link_t rq_link; 92 link_t wq_link; 93 link_t th_link; 94 77 link_t rq_link; /**< Run queue link. */ 78 link_t wq_link; /**< Wait queue link. */ 79 link_t th_link; /**< Links to threads within containing task. */ 80 95 81 /** Threads linkage to the threads_tree. */ 96 82 avltree_node_t threads_tree_node; … … 100 86 * Protects the whole thread structure except list links above. 101 87 */ 102 SPINLOCK_DECLARE(lock);103 88 IRQ_SPINLOCK_DECLARE(lock); 89 104 90 char name[THREAD_NAME_BUFLEN]; 105 91 106 92 /** Function implementing the thread. */ 107 void (* 93 void (*thread_code)(void *); 108 94 /** Argument passed to thread_code() function. */ 109 95 void *thread_arg; 110 111 /** 112 * From here, the stored context is restored when the thread is113 * scheduled.96 97 /** 98 * From here, the stored context is restored 99 * when the thread is scheduled. 114 100 */ 115 101 context_t saved_context; 116 /** 117 * From here, the stored timeout context is restored when sleep times 118 * out. 102 103 /** 104 * From here, the stored timeout context 105 * is restored when sleep times out. 119 106 */ 120 107 context_t sleep_timeout_context; 121 /** 122 * From here, the stored interruption context is restored when sleep is 123 * interrupted. 108 109 /** 110 * From here, the stored interruption context 111 * is restored when sleep is interrupted. 124 112 */ 125 113 context_t sleep_interruption_context; 126 114 127 115 /** If true, the thread can be interrupted from sleep. */ 128 116 bool sleep_interruptible; … … 132 120 timeout_t sleep_timeout; 133 121 /** Flag signalling sleep timeout in progress. */ 134 volatile inttimeout_pending;135 122 volatile bool timeout_pending; 123 136 124 /** 137 125 * True if this thread is executing copy_from_uspace(). … … 139 127 */ 140 128 bool in_copy_from_uspace; 129 141 130 /** 142 131 * True if this thread is executing copy_to_uspace(). … … 149 138 * thread_exit() before returning to userspace. 150 139 */ 151 bool interrupted; 140 bool interrupted; 141 142 /** 143 * If true, the scheduler will print a stack trace 144 * to the kernel console upon scheduling this thread. 145 */ 146 bool btrace; 152 147 153 148 /** If true, thread_join_timeout() cannot be used on this thread. */ … … 157 152 /** Link used in the joiner_head list. */ 158 153 link_t joiner_link; 159 154 160 155 fpu_context_t *saved_fpu_context; 161 156 int fpu_context_exists; 162 157 163 158 /* 164 159 * Defined only if thread doesn't run. … … 167 162 */ 168 163 int fpu_context_engaged; 169 170 rwlock_type_t rwlock_holder_type; 171 172 /** Callback fired in scheduler before the thread is put asleep. */ 173 void (* call_me)(void *); 174 /** Argument passed to call_me(). */ 175 void *call_me_with; 176 164 177 165 /** Thread's state. */ 178 166 state_t state; 179 167 /** Thread's flags. */ 180 int flags;168 unsigned int flags; 181 169 182 170 /** Thread's CPU. */ … … 184 172 /** Containing task. */ 185 173 task_t *task; 186 174 187 175 /** Ticks before preemption. */ 188 176 uint64_t ticks; 189 177 190 178 /** Thread accounting. */ 191 uint64_t cycles; 179 uint64_t ucycles; 180 uint64_t kcycles; 192 181 /** Last sampled cycle. */ 193 182 uint64_t last_cycle; 194 /** Thread doesn't affect accumulated accounting. */ 183 /** Thread doesn't affect accumulated accounting. */ 195 184 bool uncounted; 196 185 197 186 /** Thread's priority. Implemented as index to CPU->rq */ 198 187 int priority; … … 202 191 /** Architecture-specific data. */ 203 192 thread_arch_t arch; 204 193 205 194 /** Thread's kernel stack. */ 206 195 uint8_t *kstack; 207 196 208 197 #ifdef CONFIG_UDEBUG 209 198 /** Debugging stuff */ 210 199 udebug_thread_t udebug; 211 #endif 212 200 #endif /* CONFIG_UDEBUG */ 213 201 } thread_t; 214 202 … … 219 207 * 220 208 */ 221 SPINLOCK_EXTERN(threads_lock);209 IRQ_SPINLOCK_EXTERN(threads_lock); 222 210 223 211 /** AVL tree containing all threads. */ … … 225 213 226 214 extern void thread_init(void); 227 extern thread_t *thread_create(void (* func)(void *), void *arg, task_t *task,228 int flags, char *name, bool uncounted);229 extern void thread_attach(thread_t * t, task_t *task);230 extern void thread_ready(thread_t * t);215 extern thread_t *thread_create(void (*)(void *), void *, task_t *, 216 unsigned int, const char *, bool); 217 extern void thread_attach(thread_t *, task_t *); 218 extern void thread_ready(thread_t *); 231 219 extern void thread_exit(void) __attribute__((noreturn)); 232 220 233 221 #ifndef thread_create_arch 234 extern void thread_create_arch(thread_t *t); 235 #endif 222 extern void thread_create_arch(thread_t *); 223 #endif 224 236 225 #ifndef thr_constructor_arch 237 extern void thr_constructor_arch(thread_t *t); 238 #endif 226 extern void thr_constructor_arch(thread_t *); 227 #endif 228 239 229 #ifndef thr_destructor_arch 240 extern void thr_destructor_arch(thread_t * t);241 #endif 242 243 extern void thread_sleep(uint32_t sec);244 extern void thread_usleep(uint32_t usec);230 extern void thr_destructor_arch(thread_t *); 231 #endif 232 233 extern void thread_sleep(uint32_t); 234 extern void thread_usleep(uint32_t); 245 235 246 236 #define thread_join(t) \ 247 237 thread_join_timeout((t), SYNCH_NO_TIMEOUT, SYNCH_FLAGS_NONE) 248 extern int thread_join_timeout(thread_t *t, uint32_t usec, int flags); 249 extern void thread_detach(thread_t *t); 250 251 extern void thread_register_call_me(void (* call_me)(void *), 252 void *call_me_with); 253 extern void thread_print_list(void); 254 extern void thread_destroy(thread_t *t); 255 extern void thread_update_accounting(void); 256 extern bool thread_exists(thread_t *t); 238 239 extern int thread_join_timeout(thread_t *, uint32_t, unsigned int); 240 extern void thread_detach(thread_t *); 241 242 extern void thread_print_list(bool); 243 extern void thread_destroy(thread_t *, bool); 244 extern thread_t *thread_find_by_id(thread_id_t); 245 extern void thread_update_accounting(bool); 246 extern bool thread_exists(thread_t *); 247 extern void thread_stack_trace(thread_id_t); 257 248 258 249 /** Fpu context slab cache. */ … … 260 251 261 252 /* Thread syscall prototypes. */ 262 extern unative_t sys_thread_create(uspace_arg_t *uspace_uarg, 263 char *uspace_name, size_t name_len, thread_id_t *uspace_thread_id); 264 extern unative_t sys_thread_exit(int uspace_status); 265 extern unative_t sys_thread_get_id(thread_id_t *uspace_thread_id); 253 extern sysarg_t sys_thread_create(uspace_arg_t *, char *, size_t, 254 thread_id_t *); 255 extern sysarg_t sys_thread_exit(int); 256 extern sysarg_t sys_thread_get_id(thread_id_t *); 257 extern sysarg_t sys_thread_usleep(uint32_t); 266 258 267 259 #endif
Note:
See TracChangeset
for help on using the changeset viewer.