From 884e5778c9b66b943eb02d8437bc0b26a219e2ec Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Tue, 8 Sep 2009 21:06:34 -0700 Subject: core: simple thread library Simple thread library with the intent of making lwIP easier to port. -- Modified to use milliseconds instead of jiffies, as lwIP expresses everything in milliseconds. EWB Signed-off-by: H. Peter Anvin Signed-off-by: Eric W. Biederman --- core/thread/timeout.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 core/thread/timeout.c (limited to 'core/thread/timeout.c') diff --git a/core/thread/timeout.c b/core/thread/timeout.c new file mode 100644 index 00000000..2ca0782e --- /dev/null +++ b/core/thread/timeout.c @@ -0,0 +1,39 @@ +/* + * timeout.c + * + */ + +#include "thread.h" + +/* + * __thread_process_timeouts() + * + * Look for threads that have timed out. This should be called + * under interrupt lock, before calling __schedule(). + */ +void __thread_process_timeouts(void) +{ + struct thread *curr = current(); + struct thread_list *tp; + struct thread *t; + mstime_t now = ms_timer(); + struct thread_block *block; + mstime_t timeout; + + /* The current thread is obviously running, so no need to check... */ + for (tp = curr->list.next; tp != &curr->list; tp = tp->next) { + t = container_of(tp, struct thread, list); + if ((block = t->blocked) && (timeout = block->timeout)) { + if ((mstimediff_t)(timeout - now) <= 0) { + struct semaphore *sem = block->semaphore; + /* Remove us from the queue and increase the count */ + block->list.next->prev = block->list.prev; + block->list.prev->next = block->list.next; + sem->count++; + + t->blocked = NULL; + block->timed_out = true; + } + } + } +} -- cgit v1.2.1 From cd8b37053cc36014379fefdecf1d409bc7dc5b45 Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Thu, 10 Sep 2009 17:50:26 -0700 Subject: thread: add support for locking the scheduler Add support for locking the scheduler; this is needed for the pm return hook to operate properly. Signed-off-by: H. Peter Anvin --- core/thread/timeout.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'core/thread/timeout.c') diff --git a/core/thread/timeout.c b/core/thread/timeout.c index 2ca0782e..409ad6d7 100644 --- a/core/thread/timeout.c +++ b/core/thread/timeout.c @@ -33,6 +33,8 @@ void __thread_process_timeouts(void) t->blocked = NULL; block->timed_out = true; + + __schedule(); /* Normally sets just __need_schedule */ } } } -- cgit v1.2.1