summaryrefslogtreecommitdiff
path: root/kern/task.h
diff options
context:
space:
mode:
authorRichard Braun <rbraun@sceen.net>2017-05-31 21:12:41 +0200
committerRichard Braun <rbraun@sceen.net>2017-05-31 21:12:41 +0200
commit60d1eb47786f9b2461067f65f62fde31d34f1089 (patch)
tree578bad3cd9a20dc58ae9539112c92a81d07ff55c /kern/task.h
parentccefd921e76ba4ca7f3d6b54691315c0718b039c (diff)
kern/{task,thread}: add the task_info and thread_trace shell commands
Diffstat (limited to 'kern/task.h')
-rw-r--r--kern/task.h42
1 files changed, 42 insertions, 0 deletions
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 <kern/atomic.h>
#include <kern/list.h>
#include <kern/spinlock.h>
#include <kern/thread.h>
@@ -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.
*/
@@ -55,6 +79,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,6 +98,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.
*
* If task is NULL, this function displays all tasks.