summaryrefslogtreecommitdiffstats
path: root/src/kernel/scheduler.C
blob: b96dd7c7b311023e8295c7f049afcf1417cf893c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <kernel/task.H>
#include <kernel/scheduler.H>
#include <kernel/taskmgr.H>

void Scheduler::addTask(task_t* t)
{
    if (iv_idleTask != t)
    {
	iv_taskList[iv_direction ? 0 : 1].push(t);
    }
}

void Scheduler::returnRunnable()
{
    this->addTask(TaskManager::getCurrentTask());
}

void Scheduler::setNextRunnable()
{
    task_t* t = NULL;

    bool direction = iv_direction;
    t = iv_taskList[direction ? 1 : 0].pop();

    if (NULL == t)
    {
	t = iv_taskList[direction ? 0 : 1].pop();
	__sync_bool_compare_and_swap(&iv_direction, direction, !direction);
    }

    if (NULL == t)
    {
	t = iv_idleTask;
    }
    
    TaskManager::setCurrentTask(t);
}
OpenPOWER on IntegriCloud