From 62c4249d95e11a4cc8970d83de7d343161f9e232 Mon Sep 17 00:00:00 2001 From: Bahadir Balban Date: Mon, 19 Oct 2009 19:24:40 +0300 Subject: [PATCH] Renamed many thread_* line of calls. Renamed so that task_* gets a ktcb directly, and thread_* line of calls make the search for the ktcb. --- include/l4/generic/thread.h | 5 +-- src/api/thread.c | 78 ++++++++++++++++++++++++------------- src/arch/arm/exception.c | 2 +- src/generic/scheduler.c | 2 +- 4 files changed, 54 insertions(+), 33 deletions(-) diff --git a/include/l4/generic/thread.h b/include/l4/generic/thread.h index f269ab3..a2779a9 100644 --- a/include/l4/generic/thread.h +++ b/include/l4/generic/thread.h @@ -11,8 +11,7 @@ void thread_id_pool_init(void); int thread_id_new(void); int thread_id_del(int tid); -void thread_destroy_current(void); -int thread_destroy(struct task_ids *ids); -void thread_make_zombie(struct ktcb *task); +void task_destroy_current(void); +void task_make_zombie(struct ktcb *task); #endif /* __THREAD_H__ */ diff --git a/src/api/thread.c b/src/api/thread.c index 6d831c1..1f65dc4 100644 --- a/src/api/thread.c +++ b/src/api/thread.c @@ -41,14 +41,10 @@ int sys_thread_switch(void) * already gone, the state is already TASK_INACTIVE so the pager * won't sleep at all. */ -int thread_suspend(l4id_t tid, unsigned int flags) +int task_suspend(struct ktcb *task, unsigned int flags) { - struct ktcb *task; int ret = 0; - if (!(task = tcb_find(tid))) - return -ESRCH; - if (task->state == TASK_INACTIVE) return 0; @@ -106,7 +102,7 @@ int thread_recycle(struct task_ids *ids) if (!(task = tcb_find(ids->tid))) return -ESRCH; - if ((ret = thread_suspend(ids->tid, 0)) < 0) + if ((ret = task_suspend(task, 0)) < 0) return ret; /* @@ -128,27 +124,23 @@ int thread_recycle(struct task_ids *ids) return 0; } -void thread_destroy_current(); +void task_destroy_current(); -int thread_destroy(l4id_t tid) +int task_destroy(struct ktcb *task) { - struct ktcb *task; int ret; - printk("%s: Destroying (%d)\n", __FUNCTION__, tid); - /* * Pager destroying itself */ - if (tid == current->tid) { - thread_destroy_current(); + if (task == current) { + task_destroy_current(); + + /* It should not return */ BUG(); } - if (!(task = tcb_find(tid))) - return -ESRCH; - - if ((ret = thread_suspend(tid, 0)) < 0) + if ((ret = task_suspend(task, 0)) < 0) return ret; /* Remove tcb from global list so any callers will get -ESRCH */ @@ -167,7 +159,7 @@ int thread_destroy(l4id_t tid) return 0; } -void thread_make_zombie(struct ktcb *task) +void task_make_zombie(struct ktcb *task) { /* Remove from its list, callers get -ESRCH */ tcb_remove(task); @@ -192,7 +184,7 @@ void thread_make_zombie(struct ktcb *task) * address or voluntarily. All threads managed also get * destroyed. */ -void thread_destroy_current(void) +void task_destroy_current(void) { struct ktcb *task, *n; @@ -204,7 +196,7 @@ void thread_destroy_current(void) if (task->tid == current->tid) continue; spin_unlock(&curcont->ktcb_list.list_lock); - thread_suspend(task->tid, TASK_EXITING); + task_suspend(task, TASK_EXITING); spin_lock(&curcont->ktcb_list.list_lock); } spin_unlock(&curcont->ktcb_list.list_lock); @@ -215,13 +207,8 @@ void thread_destroy_current(void) sched_suspend_sync(); } -int thread_resume(struct task_ids *ids) +int task_resume(struct ktcb *task) { - struct ktcb *task; - - if (!(task = tcb_find(ids->tid))) - return -ESRCH; - if (!mutex_trylock(&task->thread_control_lock)) return -EAGAIN; @@ -230,9 +217,11 @@ int thread_resume(struct task_ids *ids) /* Release lock and return */ mutex_unlock(&task->thread_control_lock); + return 0; } + /* Runs a thread for the first time */ int thread_start(struct task_ids *ids) { @@ -420,6 +409,39 @@ out_err: return err; } + +static inline int thread_resume(struct task_ids *ids) +{ + struct ktcb *task; + + if (!(task = tcb_find(ids->tid))) + return -ESRCH; + + return task_resume(task); +} + +static inline int thread_suspend(struct task_ids *ids) +{ + struct ktcb *task; + + if (!(task = tcb_find(ids->tid))) + return -ESRCH; + + return task_suspend(task, 0); +} + +static inline int thread_destroy(struct task_ids *ids) +{ + struct ktcb *task; + + printk("%s: Destroying (%d)\n", __FUNCTION__, ids->tid); + + if (!(task = tcb_find(ids->tid))) + return -ESRCH; + + return task_destroy(task); +} + /* * Creates, destroys and modifies threads. Also implicitly creates an address * space for a thread that doesn't already have one, or destroys it if the last @@ -441,13 +463,13 @@ int sys_thread_control(unsigned int flags, struct task_ids *ids) ret = thread_start(ids); break; case THREAD_SUSPEND: - ret = thread_suspend(ids->tid, 0); + ret = thread_suspend(ids); break; case THREAD_RESUME: ret = thread_resume(ids); break; case THREAD_DESTROY: - ret = thread_destroy(ids->tid); + ret = thread_destroy(ids); break; case THREAD_RECYCLE: ret = thread_recycle(ids); diff --git a/src/arch/arm/exception.c b/src/arch/arm/exception.c index ade6818..fc1866f 100644 --- a/src/arch/arm/exception.c +++ b/src/arch/arm/exception.c @@ -113,7 +113,7 @@ void fault_ipc_to_pager(u32 faulty_pc, u32 fsr, u32 far) if (current->tid == current->pagerid) { printk("Pager (%d) self-faulting. Exiting.\n", current->tid); - thread_destroy_current(); + task_destroy_current(); } /* Send ipc to the task's pager */ diff --git a/src/generic/scheduler.c b/src/generic/scheduler.c index b1c1a9c..6b2cee0 100644 --- a/src/generic/scheduler.c +++ b/src/generic/scheduler.c @@ -241,7 +241,7 @@ void sched_suspend_sync(void) preempt_enable(); if (current->flags & TASK_EXITING) - thread_make_zombie(current); + task_make_zombie(current); /* * Async wake up any waiting pagers