scheduler: use a linked list for threads in a process instead of a table

This commit is contained in:
Matheus
2024-05-29 12:55:10 -03:00
parent 5f7791cd08
commit 9260c8cb96
6 changed files with 95 additions and 98 deletions
+18 -8
View File
@@ -102,16 +102,26 @@ syscallret_t syscall_waitpid(context_t *context, pid_t pid, int *status, int opt
MUTEX_RELEASE(&proc->mutex);
for (int i = 0; i < iterator->threadtablesize && zombie; ++i) {
if (iterator->threads[i] == NULL)
continue;
if (zombie) {
bool intstatus = interrupt_set(false);
spinlock_acquire(&iterator->threadlistlock);
volatile int *flags = (volatile int *)(&iterator->threads[i]->flags);
// wait until the thread can actually be unallocated
while ((*flags & SCHED_THREAD_FLAGS_DEAD) == 0)
sched_yield();
thread_t *threadlist = iterator->threadlist;
iterator->threadlist = NULL;
sched_destroythread(iterator->threads[i]);
spinlock_release(&iterator->threadlistlock);
interrupt_set(intstatus);
while (threadlist) {
thread_t *freethread = threadlist;
threadlist = threadlist->procnext;
volatile int *flags = (volatile int *)(&freethread->flags);
// wait until the thread can actually be unallocated
while ((*flags & SCHED_THREAD_FLAGS_DEAD) == 0)
sched_yield();
sched_destroythread(freethread);
}
}
ret.ret = iterator->pid;