mirror of
https://github.com/drasko/codezero.git
synced 2026-04-17 17:29:04 +02:00
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.
This commit is contained in:
@@ -11,8 +11,7 @@ void thread_id_pool_init(void);
|
|||||||
int thread_id_new(void);
|
int thread_id_new(void);
|
||||||
int thread_id_del(int tid);
|
int thread_id_del(int tid);
|
||||||
|
|
||||||
void thread_destroy_current(void);
|
void task_destroy_current(void);
|
||||||
int thread_destroy(struct task_ids *ids);
|
void task_make_zombie(struct ktcb *task);
|
||||||
void thread_make_zombie(struct ktcb *task);
|
|
||||||
|
|
||||||
#endif /* __THREAD_H__ */
|
#endif /* __THREAD_H__ */
|
||||||
|
|||||||
@@ -41,14 +41,10 @@ int sys_thread_switch(void)
|
|||||||
* already gone, the state is already TASK_INACTIVE so the pager
|
* already gone, the state is already TASK_INACTIVE so the pager
|
||||||
* won't sleep at all.
|
* 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;
|
int ret = 0;
|
||||||
|
|
||||||
if (!(task = tcb_find(tid)))
|
|
||||||
return -ESRCH;
|
|
||||||
|
|
||||||
if (task->state == TASK_INACTIVE)
|
if (task->state == TASK_INACTIVE)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
@@ -106,7 +102,7 @@ int thread_recycle(struct task_ids *ids)
|
|||||||
if (!(task = tcb_find(ids->tid)))
|
if (!(task = tcb_find(ids->tid)))
|
||||||
return -ESRCH;
|
return -ESRCH;
|
||||||
|
|
||||||
if ((ret = thread_suspend(ids->tid, 0)) < 0)
|
if ((ret = task_suspend(task, 0)) < 0)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -128,27 +124,23 @@ int thread_recycle(struct task_ids *ids)
|
|||||||
return 0;
|
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;
|
int ret;
|
||||||
|
|
||||||
printk("%s: Destroying (%d)\n", __FUNCTION__, tid);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Pager destroying itself
|
* Pager destroying itself
|
||||||
*/
|
*/
|
||||||
if (tid == current->tid) {
|
if (task == current) {
|
||||||
thread_destroy_current();
|
task_destroy_current();
|
||||||
|
|
||||||
|
/* It should not return */
|
||||||
BUG();
|
BUG();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(task = tcb_find(tid)))
|
if ((ret = task_suspend(task, 0)) < 0)
|
||||||
return -ESRCH;
|
|
||||||
|
|
||||||
if ((ret = thread_suspend(tid, 0)) < 0)
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
/* Remove tcb from global list so any callers will get -ESRCH */
|
/* Remove tcb from global list so any callers will get -ESRCH */
|
||||||
@@ -167,7 +159,7 @@ int thread_destroy(l4id_t tid)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void thread_make_zombie(struct ktcb *task)
|
void task_make_zombie(struct ktcb *task)
|
||||||
{
|
{
|
||||||
/* Remove from its list, callers get -ESRCH */
|
/* Remove from its list, callers get -ESRCH */
|
||||||
tcb_remove(task);
|
tcb_remove(task);
|
||||||
@@ -192,7 +184,7 @@ void thread_make_zombie(struct ktcb *task)
|
|||||||
* address or voluntarily. All threads managed also get
|
* address or voluntarily. All threads managed also get
|
||||||
* destroyed.
|
* destroyed.
|
||||||
*/
|
*/
|
||||||
void thread_destroy_current(void)
|
void task_destroy_current(void)
|
||||||
{
|
{
|
||||||
struct ktcb *task, *n;
|
struct ktcb *task, *n;
|
||||||
|
|
||||||
@@ -204,7 +196,7 @@ void thread_destroy_current(void)
|
|||||||
if (task->tid == current->tid)
|
if (task->tid == current->tid)
|
||||||
continue;
|
continue;
|
||||||
spin_unlock(&curcont->ktcb_list.list_lock);
|
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_lock(&curcont->ktcb_list.list_lock);
|
||||||
}
|
}
|
||||||
spin_unlock(&curcont->ktcb_list.list_lock);
|
spin_unlock(&curcont->ktcb_list.list_lock);
|
||||||
@@ -215,13 +207,8 @@ void thread_destroy_current(void)
|
|||||||
sched_suspend_sync();
|
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))
|
if (!mutex_trylock(&task->thread_control_lock))
|
||||||
return -EAGAIN;
|
return -EAGAIN;
|
||||||
|
|
||||||
@@ -230,9 +217,11 @@ int thread_resume(struct task_ids *ids)
|
|||||||
|
|
||||||
/* Release lock and return */
|
/* Release lock and return */
|
||||||
mutex_unlock(&task->thread_control_lock);
|
mutex_unlock(&task->thread_control_lock);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Runs a thread for the first time */
|
/* Runs a thread for the first time */
|
||||||
int thread_start(struct task_ids *ids)
|
int thread_start(struct task_ids *ids)
|
||||||
{
|
{
|
||||||
@@ -420,6 +409,39 @@ out_err:
|
|||||||
return 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
|
* 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
|
* 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);
|
ret = thread_start(ids);
|
||||||
break;
|
break;
|
||||||
case THREAD_SUSPEND:
|
case THREAD_SUSPEND:
|
||||||
ret = thread_suspend(ids->tid, 0);
|
ret = thread_suspend(ids);
|
||||||
break;
|
break;
|
||||||
case THREAD_RESUME:
|
case THREAD_RESUME:
|
||||||
ret = thread_resume(ids);
|
ret = thread_resume(ids);
|
||||||
break;
|
break;
|
||||||
case THREAD_DESTROY:
|
case THREAD_DESTROY:
|
||||||
ret = thread_destroy(ids->tid);
|
ret = thread_destroy(ids);
|
||||||
break;
|
break;
|
||||||
case THREAD_RECYCLE:
|
case THREAD_RECYCLE:
|
||||||
ret = thread_recycle(ids);
|
ret = thread_recycle(ids);
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ void fault_ipc_to_pager(u32 faulty_pc, u32 fsr, u32 far)
|
|||||||
if (current->tid == current->pagerid) {
|
if (current->tid == current->pagerid) {
|
||||||
printk("Pager (%d) self-faulting. Exiting.\n",
|
printk("Pager (%d) self-faulting. Exiting.\n",
|
||||||
current->tid);
|
current->tid);
|
||||||
thread_destroy_current();
|
task_destroy_current();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Send ipc to the task's pager */
|
/* Send ipc to the task's pager */
|
||||||
|
|||||||
@@ -241,7 +241,7 @@ void sched_suspend_sync(void)
|
|||||||
preempt_enable();
|
preempt_enable();
|
||||||
|
|
||||||
if (current->flags & TASK_EXITING)
|
if (current->flags & TASK_EXITING)
|
||||||
thread_make_zombie(current);
|
task_make_zombie(current);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Async wake up any waiting pagers
|
* Async wake up any waiting pagers
|
||||||
|
|||||||
Reference in New Issue
Block a user