summaryrefslogtreecommitdiff
path: root/kern/sched.c
diff options
context:
space:
mode:
authorHanjie Wu <hanjiew@andrew.cmu.edu>2023-04-24 00:02:27 -0400
committerHanjie Wu <hanjiew@andrew.cmu.edu>2023-04-24 00:02:27 -0400
commite021b8f12ad129c0bdbda3111bb93a170e21ae41 (patch)
tree229879c8f03278388b2140ce5ce016c0354df0f0 /kern/sched.c
parent4e6e2ced7f047a9a0439eb6d001b1a77daadfdff (diff)
new console
Diffstat (limited to 'kern/sched.c')
-rw-r--r--kern/sched.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/kern/sched.c b/kern/sched.c
index 35e8a58..fbb5c6c 100644
--- a/kern/sched.c
+++ b/kern/sched.c
@@ -15,11 +15,11 @@
#include <x86/seg.h>
#include <asm_instr.h>
-#include <pts.h>
#include <loader.h>
#include <malloc.h>
#include <mm.h>
#include <paging.h>
+#include <pts.h>
#include <pv.h>
#include <sched.h>
#include <sync.h>
@@ -334,10 +334,13 @@ alloc_tcb_fail:
}
void destroy_thread(thread_t* t) {
+ process_t* p = t->process;
mutex_lock(&t->pts->lock);
t->pts->refcount--;
+ if (p->pv != NULL) {
+ queue_detach(&t->pts->pvs, &p->pv->pts_link);
+ }
mutex_unlock(&t->pts->lock);
- process_t* p = t->process;
sfree(t->stack, K_STACK_SIZE);
sfree(t, sizeof(thread_t));
mutex_lock(&p->refcount_lock);
@@ -664,16 +667,19 @@ void kill_current() {
spl_unlock(&ready_lock, old_if);
}
}
+ p = current->process;
mutex_lock(&current->pts->lock);
current->pts->refcount--;
+ if (p->pv != NULL) {
+ queue_detach(&current->pts->pvs, &p->pv->pts_link);
+ }
mutex_unlock(&current->pts->lock);
if (current->rb_node.parent != NULL) {
remove_thread(current);
}
- p = current->process;
mutex_lock(&p->refcount_lock);
p->refcount--;
queue_detach(&p->threads, &current->process_link);