sched: implement task id allocation; remove thread id bitmap
This commit is contained in:
30
sched/task.c
30
sched/task.c
@@ -17,7 +17,10 @@ static struct object_type task_type = {
|
||||
static struct task *__kernel_task;
|
||||
static struct task *__idle_task;
|
||||
|
||||
static spin_lock_t task_list_lock;
|
||||
static spin_lock_t pid_map_lock = SPIN_LOCK_INIT;
|
||||
static DECLARE_BITMAP(pid_map, PID_MAX);
|
||||
|
||||
static spin_lock_t task_list_lock = SPIN_LOCK_INIT;
|
||||
static struct btree task_list;
|
||||
|
||||
BTREE_DEFINE_SIMPLE_GET(
|
||||
@@ -45,6 +48,31 @@ void idle(void)
|
||||
}
|
||||
}
|
||||
|
||||
static unsigned int pid_alloc(void)
|
||||
{
|
||||
unsigned long flags;
|
||||
spin_lock_irqsave(&pid_map_lock, &flags);
|
||||
|
||||
unsigned int pid = bitmap_lowest_clear(pid_map, PID_MAX);
|
||||
if (pid != BITMAP_NPOS) {
|
||||
bitmap_set(pid_map, pid);
|
||||
}
|
||||
|
||||
spin_unlock_irqrestore(&pid_map_lock, flags);
|
||||
|
||||
return pid;
|
||||
}
|
||||
|
||||
static void pid_free(unsigned int pid)
|
||||
{
|
||||
unsigned long flags;
|
||||
spin_lock_irqsave(&pid_map_lock, &flags);
|
||||
|
||||
bitmap_clear(pid_map, pid);
|
||||
|
||||
spin_unlock_irqrestore(&pid_map_lock, flags);
|
||||
}
|
||||
|
||||
kern_status_t setup_kernel_task(void)
|
||||
{
|
||||
__kernel_task = task_alloc();
|
||||
|
||||
Reference in New Issue
Block a user