From 46fcdc9b31ba4e57a0e929f8ca8e32f791f438a8 Mon Sep 17 00:00:00 2001 From: Bahadir Balban Date: Fri, 24 Oct 2008 14:59:25 +0300 Subject: [PATCH] Added same global task management mechanism from mm0 to fs0 --- tasks/fs0/include/globals.h | 13 +++++++++++++ tasks/fs0/src/task.c | 35 ++++++++++++++++++++++++----------- 2 files changed, 37 insertions(+), 11 deletions(-) create mode 100644 tasks/fs0/include/globals.h diff --git a/tasks/fs0/include/globals.h b/tasks/fs0/include/globals.h new file mode 100644 index 0000000..d21bc0d --- /dev/null +++ b/tasks/fs0/include/globals.h @@ -0,0 +1,13 @@ +#ifndef __GLOBALS_H__ +#define __GLOBALS_H__ + +struct global_list { + int total; + struct list_head list; +}; + +extern struct global_list global_vm_files; +extern struct global_list global_vm_objects; +extern struct global_list global_tasks; + +#endif /* __GLOBALS_H__ */ diff --git a/tasks/fs0/src/task.c b/tasks/fs0/src/task.c index 3653ac1..aa2517d 100644 --- a/tasks/fs0/src/task.c +++ b/tasks/fs0/src/task.c @@ -17,17 +17,32 @@ #include #include #include +#include + +struct global_list global_tasks = { + .list = { &global_tasks.list, &global_tasks.list }, + .total = 0, +}; + +void global_add_task(struct tcb *task) +{ + BUG_ON(!list_empty(&task->list)); + list_add_tail(&task->list, &global_tasks.list); + global_tasks.total++; +} +void global_remove_task(struct tcb *task) +{ + BUG_ON(list_empty(&task->list)); + list_del_init(&task->list); + BUG_ON(--global_tasks.total < 0); +} -struct tcb_head { - struct list_head list; - int total; /* Total threads */ -} tcb_head; struct tcb *find_task(int tid) { struct tcb *t; - list_for_each_entry(t, &tcb_head.list, list) + list_for_each_entry(t, &global_tasks.list, list) if (t->tid == tid) return t; return 0; @@ -43,8 +58,6 @@ struct tcb *create_tcb(void) t->fdpool = id_pool_new_init(TASK_FILES_MAX); INIT_LIST_HEAD(&t->list); - list_add_tail(&t->list, &tcb_head.list); - tcb_head.total++; return t; } @@ -53,8 +66,7 @@ void destroy_tcb(struct tcb *t) { kfree(t->fdpool); - list_del(&t->list); - tcb_head.total--; + global_remove_task(t); kfree(t); } @@ -120,6 +132,8 @@ int pager_notify_fork(struct tcb *sender, l4id_t parid, id_pool_copy(child->fdpool, parent->fdpool, TASK_FILES_MAX); memcpy(child->fd, parent->fd, TASK_FILES_MAX * sizeof(int)); + global_add_task(child); + // printf("%s/%s: Exiting...\n", __TASKNAME__, __FUNCTION__); return 0; } @@ -193,6 +207,7 @@ int init_task_structs(struct task_data_head *tdata_head) /* shm attach to the utcbs for all these tasks except own */ if (t->tid != self_tid()) task_utcb_attach(t); + global_add_task(t); } return 0; @@ -202,8 +217,6 @@ int init_task_data(void) { struct task_data_head *tdata_head; - INIT_LIST_HEAD(&tcb_head.list); - /* Read how many tasks and tids of each */ BUG_ON((tdata_head = receive_pager_taskdata()) < 0);