diff options
Diffstat (limited to 'task/task.h')
-rw-r--r-- | task/task.h | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/task/task.h b/task/task.h index 746c192..be3e30a 100644 --- a/task/task.h +++ b/task/task.h @@ -18,10 +18,14 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ +#ifndef TASK_H +#define TASK_H 1 + #include <errno.h> #include <l4.h> #include <hurd/cap-server.h> +#include <hurd/ihash.h> #include "output.h" @@ -44,6 +48,30 @@ void switch_thread (l4_thread_id_t from, l4_thread_id_t to); /* Task objects. */ +struct task +{ + /* The capability object must be the first member of this + struct. */ + struct hurd_cap_obj obj; + + /* This is for fast removal from the task_id_to_task hash table. */ + hurd_ihash_locp_t locp; + + /* The task ID is used in the version field of the global thread ID, + so it is limited to L4_THREAD_VERSION_BITS (14/32) bits and must + not have its lower 6 bits set to all zero (because that indicates + a local thread ID). */ + l4_word_t task_id; + + /* FIXME: Just for testing and dummy stuff: A small table of the + threads in this task. */ +#define MAX_THREADS 4 + l4_thread_id_t threads[MAX_THREADS]; + unsigned int nr_threads; +}; +typedef struct task *task_t; + + /* Initialize the task class subsystem. */ error_t task_class_init (); @@ -53,3 +81,39 @@ error_t task_class_init (); reference. */ error_t task_alloc (l4_word_t task_id, unsigned int nr_threads, l4_thread_id_t *threads, hurd_cap_obj_t *r_obj); + + +extern pthread_mutex_t task_id_to_task_lock; + +/* The hash table mapping task IDs to tasks. */ +extern struct hurd_ihash task_id_to_task; + +/* Acquire a reference for the task with the task ID TASK_ID and + return the task object. If the task ID is not valid, return + NULL. */ +static inline task_t +task_id_get_task (hurd_task_id_t task_id) +{ + task_t task; + + pthread_mutex_lock (&task_id_to_task_lock); + task = hurd_ihash_find (&task_id_to_task, task_id); + if (task) + hurd_cap_obj_ref (&task->obj); + pthread_mutex_unlock (&task_id_to_task_lock); + + return task; +} + + +/* Enter the task TASK under its ID into the hash table, consuming one + reference. Mainly used by the bootstrap functions. */ +error_t task_id_enter (task_t task); + +/* Find a free task ID, enter the task TASK (which must not be locked) + into the hash table under this ID, acquiring reference. The new + task ID is returned in TASK_ID. If no free task ID is available, + EAGAIN is returned. */ +error_t task_id_add (task_t task, hurd_task_id_t *task_id_p); + +#endif /* TASK_H */ |