From 7e3c06f47bb721d39084b62ab462811663bb81d6 Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Fri, 26 Aug 2011 21:55:16 +0200 Subject: [PATCH] if required, the waken task will remove from the timer queue --- include/metalsvm/tasks_types.h | 1 + kernel/tasks.c | 19 +++++++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/include/metalsvm/tasks_types.h b/include/metalsvm/tasks_types.h index fc1072de..d1fd7cf0 100644 --- a/include/metalsvm/tasks_types.h +++ b/include/metalsvm/tasks_types.h @@ -57,6 +57,7 @@ extern "C" { #define TASK_DEFAULT_FLAGS 0 #define TASK_FPU_INIT (1 << 0) #define TASK_FPU_USED (1 << 1) +#define TASK_TIMER (1 << 2) typedef int (*entry_point_t)(void*); typedef int (STDCALL *internal_entry_point_t)(void*); diff --git a/kernel/tasks.c b/kernel/tasks.c index 57fccdba..4101bcda 100644 --- a/kernel/tasks.c +++ b/kernel/tasks.c @@ -859,14 +859,27 @@ int wakeup_task(tid_t id) prio = task->prio; core_id = task->last_core; - if (task_table[id].status == TASK_BLOCKED) { - task_table[id].status = TASK_READY; + if (task->status == TASK_BLOCKED) { + task->status = TASK_READY; ret = 0; spinlock_lock(&runqueues[core_id].lock); // increase the number of ready tasks runqueues[core_id].nr_tasks++; + // do we need to remove from timer queue? + if (task->flags & TASK_TIMER) { + task->flags &= ~TASK_TIMER; + if (task->prev) + task->prev->next = task->next; + if (task->next) + task->next->prev = task->prev; + if (runqueues[core_id].timers.first == task) + runqueues[core_id].timers.first = task->next; + if (runqueues[core_id].timers.last == task) + runqueues[core_id].timers.last = task->prev; + } + // add task to the runqueue if (!runqueues[core_id].queue[prio-1].last) { runqueues[core_id].queue[prio-1].last = runqueues[core_id].queue[prio-1].first = task; @@ -959,6 +972,7 @@ int set_timer(uint64_t deadline) if (curr_task->status == TASK_RUNNING) { curr_task->status = TASK_BLOCKED; curr_task->timeout = deadline; + curr_task->flags |= TASK_TIMER; ret = 0; spinlock_lock(&runqueues[core_id].lock); @@ -1181,6 +1195,7 @@ void scheduler(void) runqueues[core_id].timers.first = runqueues[core_id].timers.first->next; if (!runqueues[core_id].timers.first) runqueues[core_id].timers.last = NULL; + task->flags &= ~TASK_TIMER; // wakeup task if (task->status == TASK_BLOCKED) {