diff options
author | marcus <marcus> | 2004-10-27 20:39:55 +0000 |
---|---|---|
committer | marcus <marcus> | 2004-10-27 20:39:55 +0000 |
commit | 071a92cac3ea4b69d6c6cc7b0b4747ec06b68584 (patch) | |
tree | 512a6aabeb7ebf3880a27fffdc3ce09ef539f81b /task/task-class.c | |
parent | 479d2af28ab27e53c2c24be97c2639f948435be5 (diff) |
2004-10-27 Marcus Brinkmann <marcus@gnu.org>
* Makefile.am (task_SOURCES): Add physmem-user.h, physmem-user.c,
malloc-wrap.c, mmap.c and task-class.c.
(EXTRA_task_SOURCES): New target.
* physmem-user.h, physmem-user.h, malloc.c, malloc-wrap.c, mmap.c,
task-class.c: New files.
* task.h (task_class_init, task_alloc): Add prototypes.
* task.c: Include <hurd/startup.h> and <hurd/wortel.h>
(__hurd_startup_data): New declaration.
(create_bootstrap_caps, get_task_id, setup_threads, task_server):
New functions.
(first_free_thread_no): New global variable.
(main): Call setup_threads and initialize server_thread. Call
task_class_init. Create task bucket. Create manager thread and
start it.
Diffstat (limited to 'task/task-class.c')
-rw-r--r-- | task/task-class.c | 139 |
1 files changed, 139 insertions, 0 deletions
diff --git a/task/task-class.c b/task/task-class.c new file mode 100644 index 0000000..f439468 --- /dev/null +++ b/task/task-class.c @@ -0,0 +1,139 @@ +/* task-class.c - Task class for the task server. + Copyright (C) 2003, 2004 Free Software Foundation, Inc. + Written by Marcus Brinkmann. + + This file is part of the GNU Hurd. + + The GNU Hurd is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU Hurd is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#if HAVE_CONFIG_H +#include <config.h> +#endif + +#include <stdlib.h> + +#include <l4.h> +#include <hurd/cap-server.h> +#include <hurd/wortel.h> + +#include "task.h" + + +struct task +{ + /* The capability object must be the first member of this + struct. */ + struct hurd_cap_obj obj; + + /* 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; + + +static void +task_reinit (hurd_cap_class_t cap_class, hurd_cap_obj_t obj) +{ + task_t task = (task_t) obj; + unsigned int i; + + /* Destroy all threads. */ + for (i = 0; i < task->nr_threads; i++) + { + /* FIXME: We are ignoring an error here. */ + wortel_thread_control (task->threads[i], l4_nilthread, l4_nilthread, + l4_nilthread, (void *) -1); + /* FIXME: Return the thread number to the list of free thread + numbers for future allocation. */ + } + + /* FIXME: Return the task ID to the list of free task IDs for future + allocation. */ +} + + +error_t +task_thread_alloc (hurd_cap_rpc_context_t ctx) +{ + return 0; +} + + +error_t +task_demuxer (hurd_cap_rpc_context_t ctx) +{ + error_t err = 0; + + switch (l4_msg_label (ctx->msg)) + { + /* TASK_THREAD_ALLOC */ + case 256: + err = task_thread_alloc (ctx); + break; + + default: + err = EOPNOTSUPP; + } + + return err; +} + + + +static struct hurd_cap_class task_class; + +/* Initialize the task class subsystem. */ +error_t +task_class_init () +{ + return hurd_cap_class_init (&task_class, sizeof (struct task), + __alignof__ (struct task), + NULL, NULL, task_reinit, NULL, + task_demuxer); +} + + +/* Allocate a new task object with the task ID TASK_ID and the + NR_THREADS threads listed in THREADS (which are already allocated + for that task. The object returned is locked and has one + 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) +{ + error_t err; + task_t task; + + err = hurd_cap_class_alloc (&task_class, (hurd_cap_obj_t *) &task); + if (err) + return err; + + assert (nr_threads <= MAX_THREADS); + task->nr_threads = nr_threads; + memcpy (task->threads, threads, sizeof (l4_thread_id_t) * nr_threads); + + *r_obj = &task->obj; + return 0; +} |