Home | History | Annotate | Download | only in librumpuser

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;
151 TAILQ_FOREACH_SAFE(thread, &thread_list, thread_list, tmp) {
152 if (!is_runnable(thread) && thread->wakeup_time >= 0) {
153 if (thread->wakeup_time <= tm) {
154 thread->flags |= THREAD_TIMEDOUT;
155 wake(thread);
156 } else if (thread->wakeup_time < wakeup)
157 wakeup = thread->wakeup_time;
159 if (is_runnable(thread)) {
160 next = thread;
161 /* Put this thread on the end of the list */
162 TAILQ_REMOVE(&thread_list, thread, thread_list);
163 TAILQ_INSERT_TAIL(&thread_list, thread, thread_list);
181 TAILQ_FOREACH_SAFE(thread, &exited_threads, thread_list, tmp) {
182 if (thread != prev) {
183 TAILQ_REMOVE(&exited_threads, thread, thread_list);
184 if ((thread->flags & THREAD_EXTSTACK) == 0)
185 munmap(thread->ctx.uc_stack.ss_sp, STACKSIZE);
186 free(thread->name);
187 free(thread);
201 ctx->uc_link = NULL; /* TODO may link to main thread */
207 struct thread *
211 struct thread *thread = calloc(1, sizeof(struct thread));
213 if (!thread) {
222 free(thread);
227 thread->flags = THREAD_EXTSTACK;
229 create_ctx(&thread->ctx, stack, stack_size, f, data);
231 thread->name = strdup(name);
232 thread->cookie = cookie;
235 thread->wakeup_time = -1;
236 thread->lwp = NULL;
237 set_runnable(thread);
238 TAILQ_INSERT_TAIL(&thread_list, thread, thread_list);
240 return thread;
244 switch_threads(struct thread *prev, struct thread *next)
259 struct thread *jw_thread;
260 struct thread *jw_wanted;
268 struct thread *thread = get_current();
272 while (thread->flags & THREAD_MUSTJOIN) {
273 thread->flags |= THREAD_JOINED;
277 if (jw_iter->jw_wanted == thread) {
282 block(thread);
286 /* Remove from the thread list */
287 TAILQ_REMOVE(&thread_list, thread, thread_list);
288 clear_runnable(thread);
290 TAILQ_INSERT_HEAD(&exited_threads, thread, thread_list);
300 join_thread(struct thread *joinable)
303 struct thread *thread = get_current();
307 /* wait for exiting thread to hit thread_exit() */
310 jw.jw_thread = thread;
313 block(thread);
318 /* signal exiting thread that we have seen it and it may now exit */
327 struct thread *thread = get_current();
329 thread->wakeup_time = now() + millisecs;
330 clear_runnable(thread);
336 struct thread *thread = get_current();
338 thread->wakeup_time = millisecs;
339 clear_runnable(thread);
346 struct thread *thread = get_current();
353 thread->wakeup_time = now() + (millisecs - real_now);
355 clear_runnable(thread);
358 rv = !!(thread->flags & THREAD_TIMEDOUT);
359 thread->flags &= ~THREAD_TIMEDOUT;
363 void wake(struct thread *thread)
366 thread->wakeup_time = -1;
367 set_runnable(thread);
370 void block(struct thread *thread)
373 thread->wakeup_time = -1;
374 clear_runnable(thread);
377 int is_runnable(struct thread *thread)
380 return thread->flags & RUNNABLE_FLAG;
383 void set_runnable(struct thread *thread)
386 thread->flags |= RUNNABLE_FLAG;
389 void clear_runnable(struct thread *thread)
392 thread->flags &= ~RUNNABLE_FLAG;
398 struct thread *thread = calloc(1, sizeof(struct thread));
400 if (!thread) {
404 thread->name = strdup("init");
405 thread->flags = 0;
406 thread->wakeup_time = -1;
407 thread->lwp = NULL;
408 set_runnable(thread);
409 TAILQ_INSERT_TAIL(&thread_list, thread, thread_list);
410 current_thread = thread;
420 struct thread *
586 /* thread functions */
590 struct thread *who;
643 struct thread *thr;
652 * _ensure_ it's set before the thread runs (and could exit).
1018 struct thread *thread;
1026 thread = get_current();
1027 thread->lwp = l;
1030 thread = get_current();
1031 assert(thread->lwp == l);
1032 thread->lwp = NULL;