if required, the waken task will remove from the timer queue

This commit is contained in:
Stefan Lankes 2011-08-26 21:55:16 +02:00
parent 416a798adc
commit 7e3c06f47b
2 changed files with 18 additions and 2 deletions

View file

@ -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*);

View file

@ -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) {