Lines Matching refs:thread
95 static void join_thread(struct thread *);
96 static void switch_threads(struct thread *prev, struct thread *next);
97 static struct thread *get_current(void);
102 TAILQ_HEAD(thread_list, thread);
106 static struct thread *current_thread = NULL;
120 static struct thread *
141 struct thread *prev, *next, *thread, *tmp; in schedule() local
151 TAILQ_FOREACH_SAFE(thread, &thread_list, thread_list, tmp) { in schedule()
152 if (!is_runnable(thread) && thread->wakeup_time >= 0) { in schedule()
153 if (thread->wakeup_time <= tm) { in schedule()
154 thread->flags |= THREAD_TIMEDOUT; in schedule()
155 wake(thread); in schedule()
156 } else if (thread->wakeup_time < wakeup) in schedule()
157 wakeup = thread->wakeup_time; in schedule()
159 if (is_runnable(thread)) { in schedule()
160 next = thread; in schedule()
162 TAILQ_REMOVE(&thread_list, thread, thread_list); in schedule()
163 TAILQ_INSERT_TAIL(&thread_list, thread, thread_list); in schedule()
181 TAILQ_FOREACH_SAFE(thread, &exited_threads, thread_list, tmp) { in schedule()
182 if (thread != prev) { in schedule()
183 TAILQ_REMOVE(&exited_threads, thread, thread_list); in schedule()
184 if ((thread->flags & THREAD_EXTSTACK) == 0) in schedule()
185 munmap(thread->ctx.uc_stack.ss_sp, STACKSIZE); in schedule()
186 free(thread->name); in schedule()
187 free(thread); in schedule()
207 struct thread *
211 struct thread *thread = calloc(1, sizeof(struct thread)); in create_thread() local
213 if (!thread) { in create_thread()
222 free(thread); in create_thread()
227 thread->flags = THREAD_EXTSTACK; in create_thread()
229 create_ctx(&thread->ctx, stack, stack_size, f, data); in create_thread()
231 thread->name = strdup(name); in create_thread()
232 thread->cookie = cookie; in create_thread()
235 thread->wakeup_time = -1; in create_thread()
236 thread->lwp = NULL; in create_thread()
237 set_runnable(thread); in create_thread()
238 TAILQ_INSERT_TAIL(&thread_list, thread, thread_list); in create_thread()
240 return thread; in create_thread()
244 switch_threads(struct thread *prev, struct thread *next) in switch_threads()
259 struct thread *jw_thread;
260 struct thread *jw_wanted;
268 struct thread *thread = get_current(); in exit_thread() local
272 while (thread->flags & THREAD_MUSTJOIN) { in exit_thread()
273 thread->flags |= THREAD_JOINED; in exit_thread()
277 if (jw_iter->jw_wanted == thread) { in exit_thread()
282 block(thread); in exit_thread()
287 TAILQ_REMOVE(&thread_list, thread, thread_list); in exit_thread()
288 clear_runnable(thread); in exit_thread()
290 TAILQ_INSERT_HEAD(&exited_threads, thread, thread_list); in exit_thread()
300 join_thread(struct thread *joinable) in join_thread()
303 struct thread *thread = get_current(); in join_thread() local
310 jw.jw_thread = thread; in join_thread()
313 block(thread); in join_thread()
327 struct thread *thread = get_current(); in msleep() local
329 thread->wakeup_time = now() + millisecs; in msleep()
330 clear_runnable(thread); in msleep()
336 struct thread *thread = get_current(); in abssleep() local
338 thread->wakeup_time = millisecs; in abssleep()
339 clear_runnable(thread); in abssleep()
346 struct thread *thread = get_current(); in abssleep_real() local
353 thread->wakeup_time = now() + (millisecs - real_now); in abssleep_real()
355 clear_runnable(thread); in abssleep_real()
358 rv = !!(thread->flags & THREAD_TIMEDOUT); in abssleep_real()
359 thread->flags &= ~THREAD_TIMEDOUT; in abssleep_real()
363 void wake(struct thread *thread) in wake() argument
366 thread->wakeup_time = -1; in wake()
367 set_runnable(thread); in wake()
370 void block(struct thread *thread) in block() argument
373 thread->wakeup_time = -1; in block()
374 clear_runnable(thread); in block()
377 int is_runnable(struct thread *thread) in is_runnable() argument
380 return thread->flags & RUNNABLE_FLAG; in is_runnable()
383 void set_runnable(struct thread *thread) in set_runnable() argument
386 thread->flags |= RUNNABLE_FLAG; in set_runnable()
389 void clear_runnable(struct thread *thread) in clear_runnable() argument
392 thread->flags &= ~RUNNABLE_FLAG; in clear_runnable()
398 struct thread *thread = calloc(1, sizeof(struct thread)); in init_sched() local
400 if (!thread) { in init_sched()
404 thread->name = strdup("init"); in init_sched()
405 thread->flags = 0; in init_sched()
406 thread->wakeup_time = -1; in init_sched()
407 thread->lwp = NULL; in init_sched()
408 set_runnable(thread); in init_sched()
409 TAILQ_INSERT_TAIL(&thread_list, thread, thread_list); in init_sched()
410 current_thread = thread; in init_sched()
420 struct thread *
590 struct thread *who;
643 struct thread *thr; in rumpuser_thread_create()
1018 struct thread *thread; in rumpuser_curlwpop() local
1026 thread = get_current(); in rumpuser_curlwpop()
1027 thread->lwp = l; in rumpuser_curlwpop()
1030 thread = get_current(); in rumpuser_curlwpop()
1031 assert(thread->lwp == l); in rumpuser_curlwpop()
1032 thread->lwp = NULL; in rumpuser_curlwpop()