diff options
author | Alex Auvolat <alex@adnab.me> | 2015-03-11 16:22:40 +0100 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2015-03-11 16:22:40 +0100 |
commit | 9b9ef5a2c0ec8e66c7da24c4229d89a90a10e914 (patch) | |
tree | 471cb88f003eb58ce84342f2e7ab7effda04ce2d /src/kernel/core/worker.c | |
parent | a7ff74cdf2835625282491242ede57b05ceaa782 (diff) | |
download | kogata-9b9ef5a2c0ec8e66c7da24c4229d89a90a10e914.tar.gz kogata-9b9ef5a2c0ec8e66c7da24c4229d89a90a10e914.zip |
Bugfixing in progress. Strange bug: wait_on adds to waiters but later not in waiters.
Diffstat (limited to 'src/kernel/core/worker.c')
-rw-r--r-- | src/kernel/core/worker.c | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/src/kernel/core/worker.c b/src/kernel/core/worker.c index cb7bf34..6852329 100644 --- a/src/kernel/core/worker.c +++ b/src/kernel/core/worker.c @@ -49,21 +49,24 @@ void worker_thread(void* x) { while (true) { mutex_lock(&tasks_mutex); - worker_task_t *t = btree_upper(tasks, &zero64); - next_task_time = (t == 0 ? UINT64_MAX : t->time); - if (t != 0 && t->time <= time) { - btree_remove_v(tasks, &t->time, t); + + worker_task_t *next_task = btree_upper(tasks, &zero64); + next_task_time = (next_task == 0 ? UINT64_MAX : next_task->time); + + if (next_task != 0 && next_task->time <= time) { + btree_remove_v(tasks, &next_task->time, next_task); } else { - t = 0; + next_task = 0; } + mutex_unlock(&tasks_mutex); - if (t != 0) { - prng_add_entropy((uint8_t*)&t, sizeof(t)); + if (next_task != 0) { + prng_add_entropy((uint8_t*)&next_task, sizeof(next_task)); // do task :-) - t->fun(t->data); - free(t); + next_task->fun(next_task->data); + free(next_task); } else { ASSERT(wait_on(current_thread)); } @@ -79,11 +82,12 @@ bool worker_push_in(int usecs, entry_t fun, void* data) { t->data = data; mutex_lock(&tasks_mutex); + btree_add(tasks, &t->time, t); - mutex_unlock(&tasks_mutex); - if (t->time < next_task_time) next_task_time = t->time; + mutex_unlock(&tasks_mutex); + return true; } @@ -95,6 +99,7 @@ void notify_time_pass(int usecs) { time += usecs; if (next_task_time <= time) { for (int i = 0; i < nworkers; i++) { + if (workers[i] == 0) continue; if (resume_on(workers[i])) break; } } |