From 60d1eb47786f9b2461067f65f62fde31d34f1089 Mon Sep 17 00:00:00 2001 From: Richard Braun Date: Wed, 31 May 2017 21:12:41 +0200 Subject: kern/{task,thread}: add the task_info and thread_trace shell commands --- kern/task.h | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'kern/task.h') diff --git a/kern/task.h b/kern/task.h index 67599399..cfe694bf 100644 --- a/kern/task.h +++ b/kern/task.h @@ -18,6 +18,7 @@ #ifndef _KERN_TASK_H #define _KERN_TASK_H +#include #include #include #include @@ -32,6 +33,7 @@ * Task structure. */ struct task { + unsigned long nr_refs; struct spinlock lock; struct list node; struct list threads; @@ -44,6 +46,28 @@ struct task { */ extern struct task *kernel_task; +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 */ + } +} + /* * Initialize the task module. */ @@ -54,6 +78,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. */ @@ -64,6 +97,15 @@ 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. * -- cgit v1.2.3