From 503f176e001ddf15e6e32bc912cf10b5764bc23b Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Wed, 4 Mar 2015 11:51:30 +0100 Subject: Process exiting & thread termination. IMPORTANT NOTE FOLLOWS. Threads may now communicate via wait_on(void* ressource) and resume_on (void* ressource). Previous pause() is replaced by wait_on(current_thread) and resume(thread) by resume_on(thread). wait_on(x) may return false, indicating that the reason for returning is NOT that resume_on(x) was called but something else happenned. Typically false indicates that the curent thread is being killed and must terminate its kernel-land processing as soon as possible. --- src/kernel/core/worker.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/kernel/core/worker.c') diff --git a/src/kernel/core/worker.c b/src/kernel/core/worker.c index e50085a..c3fa04d 100644 --- a/src/kernel/core/worker.c +++ b/src/kernel/core/worker.c @@ -36,7 +36,10 @@ void start_workers(int n) { nworkers = n; for (int i = 0; i < n; i++) { workers[i] = new_thread(worker_thread, 0); - dbg_printf("New worker thread: 0x%p\n", workers[i]); + if (workers[i] != 0) { + dbg_printf("New worker thread: 0x%p\n", workers[i]); + start_thread(workers[i]); + } } } @@ -59,7 +62,7 @@ void worker_thread(void* x) { t->fun(t->data); free(t); } else { - pause(); + ASSERT(wait_on(current_thread)); } } } @@ -89,7 +92,7 @@ void worker_notify_time(int usecs) { time += usecs; if (next_task_time <= time) { for (int i = 0; i < nworkers; i++) { - if (resume_thread(workers[i])) break; + if (resume_on(workers[i])) break; } } } -- cgit v1.2.3