scheduler: thread sleep queue pointers

This commit is contained in:
Matheus
2023-05-15 22:38:03 -03:00
parent 96bb14c88a
commit 8e59a38e4c
2 changed files with 8 additions and 6 deletions
+2
View File
@@ -17,6 +17,8 @@ typedef struct thread_t {
void *kernelstacktop; void *kernelstacktop;
struct thread_t *next; struct thread_t *next;
struct thread_t *prev; struct thread_t *prev;
struct thread_t *sleepnext;
struct thread_t *sleepprev;
struct proc_t *proc; struct proc_t *proc;
struct cpu_t *cpu; struct cpu_t *cpu;
context_t context; context_t context;
+6 -6
View File
@@ -6,24 +6,24 @@ static void insert(semaphore_t *sem, thread_t *thread) {
if (sem->head == NULL) { if (sem->head == NULL) {
sem->head = thread; sem->head = thread;
sem->tail = thread; sem->tail = thread;
thread->next = NULL; thread->sleepnext = NULL;
thread->prev = NULL; thread->sleepprev = NULL;
return; return;
} }
sem->tail->next = _cpu()->thread; sem->tail->sleepnext = _cpu()->thread;
_cpu()->thread->prev = sem->tail; _cpu()->thread->sleepprev = sem->tail;
} }
static thread_t *get(semaphore_t *sem) { static thread_t *get(semaphore_t *sem) {
thread_t *thread = sem->head; thread_t *thread = sem->head;
__assert(thread); __assert(thread);
sem->head = sem->head->next; sem->head = sem->head->sleepnext;
if (sem->head == NULL) if (sem->head == NULL)
sem->tail = NULL; sem->tail = NULL;
else else
sem->head->prev = NULL; sem->head->sleepprev = NULL;
return thread; return thread;
} }