summaryrefslogtreecommitdiff
path: root/kern/thread.c
diff options
context:
space:
mode:
authorRichard Braun <rbraun@sceen.net>2017-02-14 20:43:38 +0100
committerRichard Braun <rbraun@sceen.net>2017-02-14 20:43:38 +0100
commit9391ff21c546aad1f2ac0054c92d817591b2d5ae (patch)
treee20783f1c2d1a603ac6192bb30f703406c76681a /kern/thread.c
parentbd8cf49f471162fa2a5d5556014aeafae4cff644 (diff)
kern/thread: add reference counter
Counting thread references seems unavoidable for the near-future changes that are currently brewing.
Diffstat (limited to 'kern/thread.c')
-rw-r--r--kern/thread.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/kern/thread.c b/kern/thread.c
index eb6f11a5..1631d9a5 100644
--- a/kern/thread.c
+++ b/kern/thread.c
@@ -1593,6 +1593,7 @@ thread_bootstrap_common(unsigned int cpu)
/* Initialize only what's needed during bootstrap */
booter = &thread_booters[cpu];
+ booter->nr_refs = 0; /* Make sure booters aren't destroyed */
booter->flags = 0;
booter->preempt = 1;
cpumap_fill(&booter->cpumap);
@@ -1699,6 +1700,7 @@ thread_init(struct thread *thread, void *stack, const struct thread_attr *attr,
cpumap = (attr->cpumap == NULL) ? &caller->cpumap : attr->cpumap;
assert(attr->policy < ARRAY_SIZE(thread_policy_table));
+ thread->nr_refs = 1;
thread->flags = 0;
thread->runq = NULL;
thread_set_wchan(thread, thread, "init");
@@ -1763,7 +1765,7 @@ thread_unlock_runq(struct thread_runq *runq, unsigned long flags)
spinlock_unlock_intr_restore(&runq->lock, flags);
}
-static void
+void
thread_destroy(struct thread *thread)
{
struct thread_runq *runq;
@@ -1796,7 +1798,7 @@ thread_join_common(struct thread *thread)
mutex_unlock(&thread->join_lock);
- thread_destroy(thread);
+ thread_unref(thread);
}
static void