diff options
author | Richard Braun <rbraun@sceen.net> | 2014-06-18 23:35:45 +0200 |
---|---|---|
committer | Richard Braun <rbraun@sceen.net> | 2014-06-18 23:35:45 +0200 |
commit | 701a5d9cf5a9416eb8303d703049bf1d4c6c69f0 (patch) | |
tree | 0b0fa70492a01df7fb9511ccd388e220f7fc150d /kern/thread.h | |
parent | 6b5c9352dc34ef945259994b16c3e1fa1783aef4 (diff) |
kern/thread: add thread_join
This change affects more files than it apparently would at first glance.
This is because circular dependencies can easily be created between the
thread, mutex, condition and spinlock modules. As a result, some of the
types of these modules are now defined in kern/types.h.
Diffstat (limited to 'kern/thread.h')
-rw-r--r-- | kern/thread.h | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/kern/thread.h b/kern/thread.h index aa5dc4f7..d1c5f53a 100644 --- a/kern/thread.h +++ b/kern/thread.h @@ -39,6 +39,7 @@ #include <kern/list.h> #include <kern/macros.h> #include <kern/param.h> +#include <kern/types.h> #include <machine/atomic.h> #include <machine/cpu.h> #include <machine/tcb.h> @@ -59,7 +60,8 @@ struct thread_ts_runq; /* * Thread flags. */ -#define THREAD_YIELD 0x1UL /* Must yield the processor ASAP */ +#define THREAD_YIELD 0x1UL /* Must yield the processor ASAP */ +#define THREAD_DETACHED 0x2UL /* Resources automatically released on exit */ /* * Thread states. @@ -172,6 +174,11 @@ struct thread { /* Thread-specific data */ void *tsd[THREAD_KEYS_MAX]; + /* Members related to termination */ + struct mutex join_lock; + struct condition join_cond; + int exited; + /* Read-only members */ struct task *task; struct list task_node; @@ -181,11 +188,14 @@ struct thread { void *arg; } __aligned(CPU_L1_SIZE); +#define THREAD_ATTR_DETACHED 0x1 + /* * Thread creation attributes. */ struct thread_attr { const char *name; + unsigned long flags; struct cpumap *cpumap; struct task *task; unsigned char policy; @@ -196,6 +206,7 @@ struct thread_attr { * Initialize thread creation attributes with default values. * * It is guaranteed that these default values include : + * - thread is joinable * - no processor affinity * - task is inherited from parent thread * - policy is time-sharing @@ -208,6 +219,7 @@ static inline void thread_attr_init(struct thread_attr *attr, const char *name) { attr->name = name; + attr->flags = 0; attr->cpumap = NULL; attr->task = NULL; attr->policy = THREAD_SCHED_POLICY_TS; @@ -215,6 +227,12 @@ thread_attr_init(struct thread_attr *attr, const char *name) } static inline void +thread_attr_set_detached(struct thread_attr *attr) +{ + attr->flags |= THREAD_ATTR_DETACHED; +} + +static inline void thread_attr_set_cpumap(struct thread_attr *attr, struct cpumap *cpumap) { attr->cpumap = cpumap; @@ -268,6 +286,11 @@ int thread_create(struct thread **threadp, const struct thread_attr *attr, void __noreturn thread_exit(void); /* + * Wait for the given thread to terminate and release its resources. + */ +void thread_join(struct thread *thread); + +/* * Make the current thread sleep while waiting for an event. * * The interlock is used to synchronize the thread state with respect to |