Releasing debian version 6.03~pre1+dfsg-3.
[syslinux-debian/hramrach.git] / core / thread / timeout.c
blob409ad6d7952ed630fc56576b48eb73b889ba1a11
1 /*
2 * timeout.c
4 */
6 #include "thread.h"
8 /*
9 * __thread_process_timeouts()
11 * Look for threads that have timed out. This should be called
12 * under interrupt lock, before calling __schedule().
14 void __thread_process_timeouts(void)
16 struct thread *curr = current();
17 struct thread_list *tp;
18 struct thread *t;
19 mstime_t now = ms_timer();
20 struct thread_block *block;
21 mstime_t timeout;
23 /* The current thread is obviously running, so no need to check... */
24 for (tp = curr->list.next; tp != &curr->list; tp = tp->next) {
25 t = container_of(tp, struct thread, list);
26 if ((block = t->blocked) && (timeout = block->timeout)) {
27 if ((mstimediff_t)(timeout - now) <= 0) {
28 struct semaphore *sem = block->semaphore;
29 /* Remove us from the queue and increase the count */
30 block->list.next->prev = block->list.prev;
31 block->list.prev->next = block->list.next;
32 sem->count++;
34 t->blocked = NULL;
35 block->timed_out = true;
37 __schedule(); /* Normally sets just __need_schedule */