From fdbc5adf83741d7e3af0c3f0ffdb59bdf42493b6 Mon Sep 17 00:00:00 2001 From: Kimplul Date: Thu, 4 Jul 2024 22:52:47 +0300 Subject: generalize orphants + Allow threads to make themselves become orphants --- src/tcb.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'src/tcb.c') diff --git a/src/tcb.c b/src/tcb.c index 73711c3..1287cef 100644 --- a/src/tcb.c +++ b/src/tcb.c @@ -127,7 +127,7 @@ struct tcb *create_thread(struct tcb *p) id_t tid = __alloc_tid(t); tcbs[tid] = t; t->tid = tid; - t->dead = false; + t->state = 0; if (likely(p)) { t->pid = p->pid; @@ -235,6 +235,10 @@ stat_t destroy_thread(struct tcb *t) unqueue_ipi(t); + /** @todo timers, irqs? theoretically we could allow them to stay and + * let the handler check if the thread is still interested in the + * interrupt */ + /* someone still relies on us existing, don't actually free thread data * quite yet */ if (t->refcount) @@ -255,9 +259,7 @@ stat_t destroy_proc(struct tcb *p) * the segfault handler if the thread has become orphaned. * Currently no segfault handler exists, though. */ - p->dead = true; - /* unreference ourselves */ - unreference_proc(p); + set_bits(p->state, TCB_ZOMBIE); /* clear all privately owned memory regions, keep shared ones alive for * now */ @@ -284,7 +286,7 @@ void unreference_proc(struct tcb *p) hard_assert(is_proc(p), RETURN_VOID); p->refcount--; - if (p->dead && p->refcount == 0) { + if (zombie(p) && p->refcount == 0) { dbg("thread %d is completely destroyed\n", p->tid); __destroy_thread_data(p); } -- cgit v1.3