Changes in kernel/generic/include/proc/thread.h [df58e44:7faabb7] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/include/proc/thread.h
rdf58e44 r7faabb7 40 40 #include <time/timeout.h> 41 41 #include <cpu.h> 42 #include <synch/rwlock.h> 42 43 #include <synch/spinlock.h> 43 44 #include <adt/avl.h> … … 47 48 #include <proc/uarg.h> 48 49 #include <udebug/udebug.h> 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[]; 50 51 #define THREAD_STACK_SIZE STACK_SIZE 52 #define THREAD_NAME_BUFLEN 20 53 54 extern 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 */ 64 #define THREAD_FLAG_WIRED (1 << 0) 65 62 */ 63 #define THREAD_FLAG_WIRED (1 << 0) 66 64 /** Thread was migrated to another CPU and has not run yet. */ 67 #define THREAD_FLAG_STOLEN (1 << 1) 68 65 #define THREAD_FLAG_STOLEN (1 << 1) 69 66 /** Thread executes in userspace. */ 70 #define THREAD_FLAG_USPACE (1 << 2) 71 67 #define THREAD_FLAG_USPACE (1 << 2) 72 68 /** Thread will be attached by the caller. */ 73 #define THREAD_FLAG_NOATTACH (1 << 3) 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; 74 88 75 89 /** Thread structure. There is one per thread. */ 76 90 typedef struct thread { 77 link_t rq_link; 78 link_t wq_link; 79 link_t th_link; 80 91 link_t rq_link; /**< Run queue link. */ 92 link_t wq_link; /**< Wait queue link. */ 93 link_t th_link; /**< Links to threads within containing task. */ 94 81 95 /** Threads linkage to the threads_tree. */ 82 96 avltree_node_t threads_tree_node; … … 86 100 * Protects the whole thread structure except list links above. 87 101 */ 88 IRQ_SPINLOCK_DECLARE(lock);89 102 SPINLOCK_DECLARE(lock); 103 90 104 char name[THREAD_NAME_BUFLEN]; 91 105 92 106 /** Function implementing the thread. */ 93 void (* thread_code)(void *);107 void (* thread_code)(void *); 94 108 /** Argument passed to thread_code() function. */ 95 109 void *thread_arg; 96 97 /** 98 * From here, the stored context is restored 99 * when the thread isscheduled.110 111 /** 112 * From here, the stored context is restored when the thread is 113 * scheduled. 100 114 */ 101 115 context_t saved_context; 102 103 /** 104 * From here, the stored timeout context 105 * is restored when sleep times out. 116 /** 117 * From here, the stored timeout context is restored when sleep times 118 * out. 106 119 */ 107 120 context_t sleep_timeout_context; 108 109 /** 110 * From here, the stored interruption context 111 * is restored when sleep is interrupted. 121 /** 122 * From here, the stored interruption context is restored when sleep is 123 * interrupted. 112 124 */ 113 125 context_t sleep_interruption_context; 114 126 115 127 /** If true, the thread can be interrupted from sleep. */ 116 128 bool sleep_interruptible; … … 120 132 timeout_t sleep_timeout; 121 133 /** Flag signalling sleep timeout in progress. */ 122 volatile booltimeout_pending;123 134 volatile int timeout_pending; 135 124 136 /** 125 137 * True if this thread is executing copy_from_uspace(). … … 127 139 */ 128 140 bool in_copy_from_uspace; 129 130 141 /** 131 142 * True if this thread is executing copy_to_uspace(). … … 138 149 * thread_exit() before returning to userspace. 139 150 */ 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; 151 bool interrupted; 147 152 148 153 /** If true, thread_join_timeout() cannot be used on this thread. */ … … 152 157 /** Link used in the joiner_head list. */ 153 158 link_t joiner_link; 154 159 155 160 fpu_context_t *saved_fpu_context; 156 161 int fpu_context_exists; 157 162 158 163 /* 159 164 * Defined only if thread doesn't run. … … 162 167 */ 163 168 int fpu_context_engaged; 164 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 165 177 /** Thread's state. */ 166 178 state_t state; 167 179 /** Thread's flags. */ 168 unsignedint flags;180 int flags; 169 181 170 182 /** Thread's CPU. */ … … 172 184 /** Containing task. */ 173 185 task_t *task; 174 186 175 187 /** Ticks before preemption. */ 176 188 uint64_t ticks; 177 189 178 190 /** Thread accounting. */ 179 uint64_t ucycles; 180 uint64_t kcycles; 191 uint64_t cycles; 181 192 /** Last sampled cycle. */ 182 193 uint64_t last_cycle; 183 /** Thread doesn't affect accumulated accounting. */ 194 /** Thread doesn't affect accumulated accounting. */ 184 195 bool uncounted; 185 196 186 197 /** Thread's priority. Implemented as index to CPU->rq */ 187 198 int priority; … … 191 202 /** Architecture-specific data. */ 192 203 thread_arch_t arch; 193 204 194 205 /** Thread's kernel stack. */ 195 206 uint8_t *kstack; 196 207 197 208 #ifdef CONFIG_UDEBUG 198 209 /** Debugging stuff */ 199 210 udebug_thread_t udebug; 200 #endif /* CONFIG_UDEBUG */ 211 #endif 212 201 213 } thread_t; 202 214 … … 207 219 * 208 220 */ 209 IRQ_SPINLOCK_EXTERN(threads_lock);221 SPINLOCK_EXTERN(threads_lock); 210 222 211 223 /** AVL tree containing all threads. */ … … 213 225 214 226 extern void thread_init(void); 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 * );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); 219 231 extern void thread_exit(void) __attribute__((noreturn)); 220 232 221 233 #ifndef thread_create_arch 222 extern void thread_create_arch(thread_t *); 223 #endif 224 234 extern void thread_create_arch(thread_t *t); 235 #endif 225 236 #ifndef thr_constructor_arch 226 extern void thr_constructor_arch(thread_t *); 227 #endif 228 237 extern void thr_constructor_arch(thread_t *t); 238 #endif 229 239 #ifndef thr_destructor_arch 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 );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); 235 245 236 246 #define thread_join(t) \ 237 247 thread_join_timeout((t), SYNCH_NO_TIMEOUT, SYNCH_FLAGS_NONE) 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); 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); 248 257 249 258 /** Fpu context slab cache. */ … … 251 260 252 261 /* Thread syscall prototypes. */ 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); 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); 258 266 259 267 #endif
Note:
See TracChangeset
for help on using the changeset viewer.