diff options
Diffstat (limited to 'kern/task.h')
-rw-r--r-- | kern/task.h | 59 |
1 files changed, 55 insertions, 4 deletions
diff --git a/kern/task.h b/kern/task.h index 67599399..1711fbee 100644 --- a/kern/task.h +++ b/kern/task.h @@ -18,6 +18,8 @@ #ifndef _KERN_TASK_H #define _KERN_TASK_H +#include <kern/atomic.h> +#include <kern/init.h> #include <kern/list.h> #include <kern/spinlock.h> #include <kern/thread.h> @@ -32,6 +34,7 @@ * Task structure. */ struct task { + unsigned long nr_refs; struct spinlock lock; struct list node; struct list threads; @@ -44,10 +47,33 @@ struct task { */ extern struct task *kernel_task; -/* - * Initialize the task module. - */ -void task_setup(void); +static inline void +task_ref(struct task *task) +{ + unsigned long nr_refs; + + nr_refs = atomic_fetch_add(&task->nr_refs, 1, ATOMIC_RELAXED); + assert(nr_refs != (unsigned long)-1); +} + +static inline void +task_unref(struct task *task) +{ + unsigned long nr_refs; + + nr_refs = atomic_fetch_sub_acq_rel(&task->nr_refs, 1); + assert(nr_refs != 0); + + if (nr_refs == 1) { + /* TODO Task destruction */ + } +} + +static inline struct vm_map * +task_get_vm_map(const struct task *task) +{ + return task->map; +} /* * Create a task. @@ -55,6 +81,15 @@ void task_setup(void); int task_create(struct task **taskp, const char *name); /* + * Look up a task from its name. + * + * If a task is found, it gains a reference. Otherwise, NULL is returned. + * + * This function is meant for debugging only. + */ +struct task * task_lookup(const char *name); + +/* * Add a thread to a task. */ void task_add_thread(struct task *task, struct thread *thread); @@ -65,10 +100,26 @@ void task_add_thread(struct task *task, struct thread *thread); void task_remove_thread(struct task *task, struct thread *thread); /* + * Look up a thread in a task from its name. + * + * If a thread is found, it gains a reference, Otherwise, NULL is returned. + * + * This function is meant for debugging only. + */ +struct thread * task_lookup_thread(struct task *task, const char *name); + +/* * Display task information. * * If task is NULL, this function displays all tasks. */ void task_info(struct task *task); +/* + * This init operation provides : + * - task creation + * - module fully initialized + */ +INIT_OP_DECLARE(task_setup); + #endif /* _KERN_TASK_H */ |