Skip to content

Commit

Permalink
sched: remove thread state cleanup to prep for refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
jewelcodes committed Jan 16, 2025
1 parent b831890 commit 094eb34
Showing 1 changed file with 1 addition and 57 deletions.
58 changes: 1 addition & 57 deletions src/sched/cleanup.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,61 +19,5 @@
void threadCleanup(Thread *t) {
platformCleanThread(t->context, t->highest);

Process *pc = getProcess(t->pid);
Process *pq = getProcessQueue();
Thread *tq;

while(pq) {
if(!pq->threadCount || !pq->threads) {
pq = pq->next;
continue;
}

for(int i = 0; i < pq->threadCount; i++) {
if(pq->threads[i] == t) {
if(i != pq->threadCount-1)
memmove(&pq->threads[i], &pq->threads[i+1], (pq->threadCount-i) * sizeof(Thread *));
else
pq->threads[i] = NULL;

pq->threadCount--;
break;
} else {
// remove from the next queues as well
tq = pq->threads[i];
if(tq->next == t) tq->next = t->next;
}
}

pq = pq->next;
}

// now remove the process that contains this thread if necessary
if(!pc->threadCount) {
pq = getProcessQueue();

while(pq) {
if(pq->next == pc) pq->next = pc->next;
pq = pq->next;
}

pq = getProcess(pc->parent);
for(int i = 0; i < pq->childrenCount; i++) {
if(pq->children[i] == pc) {
if(i != pq->childrenCount-1)
memmove(&pq->children[i], &pq->children[i+1], (pq->childrenCount-i) * sizeof(Process *));
else
pq->children[i] = NULL;

pq->childrenCount--;
break;
}
}

free(pc->children);
free(pc->threads);
free(pc);
}

free(t);
/* TODO: properly re-implement this after implementing per-CPU run queue */
}

0 comments on commit 094eb34

Please sign in to comment.