diff --git a/ChangeLog b/ChangeLog index 462393b89d..f9b22e44a4 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11462,4 +11462,8 @@ * fs/procfs/fs_procfskmm.c: Add /proc/kmm entry that shows that state of the kernel heap. Only useful in PROTECTED and KERNEL build modes where there is a kernel heap (2016-02-06). + * sched/ and arch/: Replace explicit access to the OS internal data structure + g_readytorun() with the wrapper this_task() which hides the implementation + and will permit such things as more scalable representations of task queues + and SMP (2016-02-06). diff --git a/TODO b/TODO index a84666321a..7710e0bc1c 100644 --- a/TODO +++ b/TODO @@ -228,13 +228,9 @@ o Task/Scheduler (sched/) hidden behind simple accessor functions and so the internal data structures can be changed if need with very little impact. - The only area are the list structure is not well contained is - in the sequence of code that finds the current running task: - FAR struct tcb_s *rtcb = (FAT struc tcb_s *)g_readytorun.head; - - That needs to be hidden behind a macro (it would also be a problem - for any SMP implementation). + Explicity refereence to the list strucutre are hidden behnid + the macro this_task(). Status: Open Priority: Low. Things are just the way that we want them for the way diff --git a/arch b/arch index e15b5dec6a..5c9c3dc73e 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit e15b5dec6a20cce69ce6bfc18c808b92638a7bd3 +Subproject commit 5c9c3dc73e2ae5e87203801c6ab82e44a3f8fbec diff --git a/sched/environ/env_clearenv.c b/sched/environ/env_clearenv.c index acfb6b2f46..4085fd20da 100644 --- a/sched/environ/env_clearenv.c +++ b/sched/environ/env_clearenv.c @@ -74,7 +74,7 @@ int clearenv(void) { - FAR struct tcb_s *tcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *tcb = this_task(); DEBUGASSERT(tcb->group); env_release(tcb->group); diff --git a/sched/environ/env_dup.c b/sched/environ/env_dup.c index 542774f892..ffb68e2eaa 100644 --- a/sched/environ/env_dup.c +++ b/sched/environ/env_dup.c @@ -81,7 +81,7 @@ int env_dup(FAR struct task_group_s *group) { - FAR struct tcb_s *ptcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *ptcb = this_task(); FAR char *envp = NULL; size_t envlen; int ret = OK; diff --git a/sched/environ/env_getenv.c b/sched/environ/env_getenv.c index ae1408d045..0c28e6d970 100644 --- a/sched/environ/env_getenv.c +++ b/sched/environ/env_getenv.c @@ -94,7 +94,7 @@ FAR char *getenv(const char *name) /* Get a reference to the thread-private environ in the TCB. */ sched_lock(); - rtcb = (FAR struct tcb_s *)g_readytorun.head; + rtcb = this_task(); group = rtcb->group; /* Check if the variable exists */ diff --git a/sched/environ/env_getenvironptr.c b/sched/environ/env_getenvironptr.c index 447fff2b89..b54c41a0e5 100644 --- a/sched/environ/env_getenvironptr.c +++ b/sched/environ/env_getenvironptr.c @@ -85,7 +85,7 @@ FAR char **get_environ_ptr(void) /* Return a reference to the thread-private environ in the TCB. */ - FAR struct tcb_s *ptcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *ptcb = this_task(); if (ptcb->envp) { return &ptcb->envp->ev_env; diff --git a/sched/environ/env_setenv.c b/sched/environ/env_setenv.c index 250a14c365..8f5b38b1ac 100644 --- a/sched/environ/env_setenv.c +++ b/sched/environ/env_setenv.c @@ -124,7 +124,7 @@ int setenv(FAR const char *name, FAR const char *value, int overwrite) /* Get a reference to the thread-private environ in the TCB. */ sched_lock(); - rtcb = (FAR struct tcb_s *)g_readytorun.head; + rtcb = this_task(); group = rtcb->group; DEBUGASSERT(group); diff --git a/sched/environ/env_unsetenv.c b/sched/environ/env_unsetenv.c index 39a87265d9..ac96e49c1b 100644 --- a/sched/environ/env_unsetenv.c +++ b/sched/environ/env_unsetenv.c @@ -77,7 +77,7 @@ int unsetenv(FAR const char *name) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *rtcb = this_task(); FAR struct task_group_s *group = rtcb->group; FAR char *pvar; FAR char *newenvp; diff --git a/sched/errno/errno_getptr.c b/sched/errno/errno_getptr.c index c24bed5a49..4e47895a0b 100644 --- a/sched/errno/errno_getptr.c +++ b/sched/errno/errno_getptr.c @@ -97,11 +97,11 @@ FAR int *get_errno_ptr(void) * logic (see, for example, task_exit.c). * * There is also a corner case early in the initialization sequence: - * The ready to run list may not yet be initialized and g_readytorun.head + * The ready to run list may not yet be initialized and this_task() * may be NULL. */ - FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *rtcb = this_task(); if (rtcb && rtcb->task_state == TSTATE_TASK_RUNNING) { /* Yes.. the task is running normally. Return a reference to the diff --git a/sched/group/group_addrenv.c b/sched/group/group_addrenv.c index da25bdacdc..fcdd1a3e0c 100644 --- a/sched/group/group_addrenv.c +++ b/sched/group/group_addrenv.c @@ -114,7 +114,7 @@ int group_addrenv(FAR struct tcb_s *tcb) if (!tcb) { - tcb = (FAR struct tcb_s *)g_readytorun.head; + tcb = this_task(); } DEBUGASSERT(tcb && tcb->group); diff --git a/sched/group/group_free.c b/sched/group/group_free.c index c7b0342adb..3692b4495f 100644 --- a/sched/group/group_free.c +++ b/sched/group/group_free.c @@ -69,7 +69,7 @@ void group_free(FAR struct task_group_s *group, FAR void *mem) if (!group) { - FAR struct tcb_s *tcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *tcb = this_task(); DEBUGASSERT(tcb && tcb->group); group = tcb->group; } diff --git a/sched/group/group_join.c b/sched/group/group_join.c index 0e16f317a7..eab5bdbcc7 100644 --- a/sched/group/group_join.c +++ b/sched/group/group_join.c @@ -172,7 +172,7 @@ static inline int group_addmember(FAR struct task_group_s *group, pid_t pid) int group_bind(FAR struct pthread_tcb_s *tcb) { - FAR struct tcb_s *ptcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *ptcb = this_task(); DEBUGASSERT(ptcb && tcb && ptcb->group && !tcb->cmn.group); diff --git a/sched/group/group_malloc.c b/sched/group/group_malloc.c index f47a6f74aa..b8ed5c487e 100644 --- a/sched/group/group_malloc.c +++ b/sched/group/group_malloc.c @@ -92,7 +92,7 @@ FAR void *group_malloc(FAR struct task_group_s *group, size_t nbytes) if (!group) { - FAR struct tcb_s *tcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *tcb = this_task(); DEBUGASSERT(tcb && tcb->group); group = tcb->group; } diff --git a/sched/group/group_setuptaskfiles.c b/sched/group/group_setuptaskfiles.c index c9b08cc934..e106871250 100644 --- a/sched/group/group_setuptaskfiles.c +++ b/sched/group/group_setuptaskfiles.c @@ -89,7 +89,7 @@ static inline void sched_dupfiles(FAR struct task_tcb_s *tcb) { /* The parent task is the one at the head of the ready-to-run list */ - FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *rtcb = this_task(); FAR struct file *parent; FAR struct file *child; int i; @@ -147,7 +147,7 @@ static inline void sched_dupsockets(FAR struct task_tcb_s *tcb) { /* The parent task is the one at the head of the ready-to-run list */ - FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *rtcb = this_task(); FAR struct socket *parent; FAR struct socket *child; int i; diff --git a/sched/mqueue/mq_notify.c b/sched/mqueue/mq_notify.c index cb7a3aaffc..eff00d1083 100644 --- a/sched/mqueue/mq_notify.c +++ b/sched/mqueue/mq_notify.c @@ -127,10 +127,10 @@ * ****************************************************************************/ -int mq_notify(mqd_t mqdes, const struct sigevent *notification) +int mq_notify(mqd_t mqdes, FAR const struct sigevent *notification) { - struct tcb_s *rtcb; - struct mqueue_inode_s *msgq; + FAR struct tcb_s *rtcb; + FAR struct mqueue_inode_s *msgq; int errval; /* Was a valid message queue descriptor provided? */ @@ -150,7 +150,7 @@ int mq_notify(mqd_t mqdes, const struct sigevent *notification) /* Get the current process ID */ - rtcb = (struct tcb_s *)g_readytorun.head; + rtcb = this_task(); /* Is there already a notification attached */ diff --git a/sched/mqueue/mq_rcvinternal.c b/sched/mqueue/mq_rcvinternal.c index bcc7059b86..7c019e7d38 100644 --- a/sched/mqueue/mq_rcvinternal.c +++ b/sched/mqueue/mq_rcvinternal.c @@ -176,7 +176,7 @@ FAR struct mqueue_msg_s *mq_waitreceive(mqd_t mqdes) { /* Yes.. Block and try again */ - rtcb = (FAR struct tcb_s *)g_readytorun.head; + rtcb = this_task(); rtcb->msgwaitq = msgq; msgq->nwaitnotempty++; diff --git a/sched/mqueue/mq_sndinternal.c b/sched/mqueue/mq_sndinternal.c index b6580d25bb..0aaa61dad5 100644 --- a/sched/mqueue/mq_sndinternal.c +++ b/sched/mqueue/mq_sndinternal.c @@ -280,7 +280,7 @@ int mq_waitsend(mqd_t mqdes) * When we are unblocked, we will try again */ - rtcb = (FAR struct tcb_s *)g_readytorun.head; + rtcb = this_task(); rtcb->msgwaitq = msgq; msgq->nwaitnotfull++; diff --git a/sched/mqueue/mq_timedreceive.c b/sched/mqueue/mq_timedreceive.c index 858bf60e96..1e3d50d163 100644 --- a/sched/mqueue/mq_timedreceive.c +++ b/sched/mqueue/mq_timedreceive.c @@ -182,7 +182,7 @@ static void mq_rcvtimeout(int argc, wdparm_t pid) ssize_t mq_timedreceive(mqd_t mqdes, FAR char *msg, size_t msglen, FAR int *prio, FAR const struct timespec *abstime) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *rtcb = this_task(); FAR struct mqueue_msg_s *mqmsg; irqstate_t saved_state; int ret = ERROR; diff --git a/sched/mqueue/mq_timedsend.c b/sched/mqueue/mq_timedsend.c index 03fa03265e..90045436eb 100644 --- a/sched/mqueue/mq_timedsend.c +++ b/sched/mqueue/mq_timedsend.c @@ -183,7 +183,7 @@ static void mq_sndtimeout(int argc, wdparm_t pid) int mq_timedsend(mqd_t mqdes, FAR const char *msg, size_t msglen, int prio, FAR const struct timespec *abstime) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *rtcb = this_task(); FAR struct mqueue_inode_s *msgq; FAR struct mqueue_msg_s *mqmsg = NULL; irqstate_t saved_state; diff --git a/sched/paging/pg_miss.c b/sched/paging/pg_miss.c index d41821bc4f..945678f99a 100644 --- a/sched/paging/pg_miss.c +++ b/sched/paging/pg_miss.c @@ -121,7 +121,7 @@ void pg_miss(void) { - FAR struct tcb_s *ftcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *ftcb = this_task(); FAR struct tcb_s *wtcb; /* Sanity checking diff --git a/sched/paging/pg_worker.c b/sched/paging/pg_worker.c index a50f917d09..701076901a 100644 --- a/sched/paging/pg_worker.c +++ b/sched/paging/pg_worker.c @@ -279,7 +279,7 @@ static inline bool pg_dequeue(void) * if a new higher priority fill is required). */ - FAR struct tcb_s *wtcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *wtcb = this_task(); if (wtcb->sched_priority > CONFIG_PAGING_DEFPRIO && wtcb->sched_priority > g_pftcb->sched_priority) { @@ -456,7 +456,7 @@ static inline bool pg_startfill(void) static inline void pg_alldone(void) { - FAR struct tcb_s *wtcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *wtcb = this_task(); g_pftcb = NULL; pgllvdbg("New worker priority. %d->%d\n", wtcb->sched_priority, CONFIG_PAGING_DEFPRIO); diff --git a/sched/pthread/pthread_cancel.c b/sched/pthread/pthread_cancel.c index 8892dc6a43..a8ba2ee4c9 100644 --- a/sched/pthread/pthread_cancel.c +++ b/sched/pthread/pthread_cancel.c @@ -47,37 +47,13 @@ #include "sched/sched.h" #include "pthread/pthread.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ int pthread_cancel(pthread_t thread) { - struct tcb_s *tcb; + FAR struct tcb_s *tcb; /* First, make sure that the handle references a valid thread */ @@ -132,7 +108,7 @@ int pthread_cancel(pthread_t thread) * same as pthread_exit(PTHREAD_CANCELED). */ - if (tcb == (struct tcb_s *)g_readytorun.head) + if (tcb == this_task()) { pthread_exit(PTHREAD_CANCELED); } diff --git a/sched/pthread/pthread_condtimedwait.c b/sched/pthread/pthread_condtimedwait.c index 9a02ef912a..9fb2673a5b 100644 --- a/sched/pthread/pthread_condtimedwait.c +++ b/sched/pthread/pthread_condtimedwait.c @@ -182,7 +182,7 @@ static void pthread_condtimedout(int argc, uint32_t pid, uint32_t signo) int pthread_cond_timedwait(FAR pthread_cond_t *cond, FAR pthread_mutex_t *mutex, FAR const struct timespec *abstime) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *rtcb = this_task(); int ticks; int mypid = (int)getpid(); irqstate_t int_state; diff --git a/sched/pthread/pthread_create.c b/sched/pthread/pthread_create.c index 41c2a85799..3354067c31 100644 --- a/sched/pthread/pthread_create.c +++ b/sched/pthread/pthread_create.c @@ -165,7 +165,7 @@ static inline void pthread_addjoininfo(FAR struct task_group_s *group, static void pthread_start(void) { - FAR struct pthread_tcb_s *ptcb = (FAR struct pthread_tcb_s *)g_readytorun.head; + FAR struct pthread_tcb_s *ptcb = (FAR struct pthread_tcb_s *)this_task(); FAR struct task_group_s *group = ptcb->cmn.group; FAR struct join_s *pjoin = (FAR struct join_s *)ptcb->joininfo; pthread_addr_t exit_status; @@ -269,8 +269,7 @@ int pthread_create(FAR pthread_t *thread, FAR const pthread_attr_t *attr, #ifdef CONFIG_ARCH_ADDRENV /* Share the address environment of the parent task group. */ - ret = up_addrenv_attach(ptcb->cmn.group, - (FAR struct tcb_s *)g_readytorun.head); + ret = up_addrenv_attach(ptcb->cmn.group, this_task()); if (ret < 0) { errcode = -ret; diff --git a/sched/pthread/pthread_detach.c b/sched/pthread/pthread_detach.c index 587502cd66..7d8c829221 100644 --- a/sched/pthread/pthread_detach.c +++ b/sched/pthread/pthread_detach.c @@ -97,7 +97,7 @@ int pthread_detach(pthread_t thread) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *rtcb = this_task(); FAR struct task_group_s *group = rtcb->group; FAR struct join_s *pjoin; int ret; diff --git a/sched/pthread/pthread_exit.c b/sched/pthread/pthread_exit.c index 1fda5c2755..a384fbedf3 100644 --- a/sched/pthread/pthread_exit.c +++ b/sched/pthread/pthread_exit.c @@ -95,7 +95,7 @@ void pthread_exit(FAR void *exit_value) { - struct tcb_s *tcb = (struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *tcb = this_task(); int status; sdbg("exit_value=%p\n", exit_value); diff --git a/sched/pthread/pthread_getspecific.c b/sched/pthread/pthread_getspecific.c index 8a470455f0..e535600e0e 100644 --- a/sched/pthread/pthread_getspecific.c +++ b/sched/pthread/pthread_getspecific.c @@ -104,7 +104,7 @@ FAR void *pthread_getspecific(pthread_key_t key) { #if CONFIG_NPTHREAD_KEYS > 0 - FAR struct pthread_tcb_s *rtcb = (FAR struct pthread_tcb_s *)g_readytorun.head; + FAR struct pthread_tcb_s *rtcb = (FAR struct pthread_tcb_s *)this_task(); FAR struct task_group_s *group = rtcb->cmn.group; FAR void *ret = NULL; diff --git a/sched/pthread/pthread_join.c b/sched/pthread/pthread_join.c index 003f06ccef..7dbffe68ac 100644 --- a/sched/pthread/pthread_join.c +++ b/sched/pthread/pthread_join.c @@ -102,7 +102,7 @@ int pthread_join(pthread_t thread, FAR pthread_addr_t *pexit_value) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *rtcb = this_task(); FAR struct task_group_s *group = rtcb->group; FAR struct join_s *pjoin; int ret; diff --git a/sched/pthread/pthread_keycreate.c b/sched/pthread/pthread_keycreate.c index 03d8486b48..3589dd61c8 100644 --- a/sched/pthread/pthread_keycreate.c +++ b/sched/pthread/pthread_keycreate.c @@ -112,7 +112,7 @@ int pthread_key_create(FAR pthread_key_t *key, CODE void (*destructor)(FAR void *)) { #if CONFIG_NPTHREAD_KEYS > 0 - FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *rtcb = this_task(); FAR struct task_group_s *group = rtcb->group; int ret = EAGAIN; diff --git a/sched/pthread/pthread_kill.c b/sched/pthread/pthread_kill.c index 870cb15a41..a53842308a 100644 --- a/sched/pthread/pthread_kill.c +++ b/sched/pthread/pthread_kill.c @@ -94,7 +94,7 @@ int pthread_kill(pthread_t thread, int signo) */ #ifdef CONFIG_SCHED_HAVE_PARENT - FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *rtcb = this_task(); #endif FAR struct tcb_s *stcb; siginfo_t info; diff --git a/sched/pthread/pthread_setcancelstate.c b/sched/pthread/pthread_setcancelstate.c index 4d4ba360f9..d05e9c6acd 100644 --- a/sched/pthread/pthread_setcancelstate.c +++ b/sched/pthread/pthread_setcancelstate.c @@ -75,7 +75,7 @@ int pthread_setcancelstate(int state, FAR int *oldstate) { - struct tcb_s *tcb = (struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *tcb = this_task(); int ret = OK; /* Suppress context changes for a bit so that the flags are stable. (the diff --git a/sched/pthread/pthread_setspecific.c b/sched/pthread/pthread_setspecific.c index a91dc5e137..f78141c539 100644 --- a/sched/pthread/pthread_setspecific.c +++ b/sched/pthread/pthread_setspecific.c @@ -115,7 +115,7 @@ int pthread_setspecific(pthread_key_t key, FAR const void *value) { #if CONFIG_NPTHREAD_KEYS > 0 - FAR struct pthread_tcb_s *rtcb = (FAR struct pthread_tcb_s *)g_readytorun.head; + FAR struct pthread_tcb_s *rtcb = (FAR struct pthread_tcb_s *)this_task(); FAR struct task_group_s *group = rtcb->cmn.group; int ret = EINVAL; diff --git a/sched/sched/sched.h b/sched/sched/sched.h index 2924e5bef7..772711cc42 100644 --- a/sched/sched/sched.h +++ b/sched/sched/sched.h @@ -64,6 +64,14 @@ #define MAX_TASKS_MASK (CONFIG_MAX_TASKS-1) #define PIDHASH(pid) ((pid) & MAX_TASKS_MASK) +/* These are macros to access the current CPU and the current task on a CPU. + * These macros are intended to support a future SMP implementation. + */ + +#define current_task(cpu) ((FAR struct tcb_s *)g_readytorun.head) +#define this_cpu() (0) +#define this_task() (current_task(this_cpu)) + /**************************************************************************** * Public Type Definitions ****************************************************************************/ diff --git a/sched/sched/sched_addreadytorun.c b/sched/sched/sched_addreadytorun.c index 2ebfcc49fe..25f9e00e6c 100644 --- a/sched/sched/sched_addreadytorun.c +++ b/sched/sched/sched_addreadytorun.c @@ -100,7 +100,7 @@ bool sched_addreadytorun(FAR struct tcb_s *btcb) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *rtcb = this_task(); bool ret; /* Check if pre-emption is disabled for the current running task and if diff --git a/sched/sched/sched_cpuload.c b/sched/sched/sched_cpuload.c index 2cbef4c739..2c3d629c19 100644 --- a/sched/sched/sched_cpuload.c +++ b/sched/sched/sched_cpuload.c @@ -111,7 +111,7 @@ volatile uint32_t g_cpuload_total; void weak_function sched_process_cpuload(void) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *rtcb = this_task(); int hash_index; int i; diff --git a/sched/sched/sched_getfiles.c b/sched/sched/sched_getfiles.c index f0608a465d..7e634053d9 100644 --- a/sched/sched/sched_getfiles.c +++ b/sched/sched/sched_getfiles.c @@ -69,7 +69,7 @@ FAR struct filelist *sched_getfiles(void) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *rtcb = this_task(); FAR struct task_group_s *group = rtcb->group; /* The group may be NULL under certain conditions. For example, if diff --git a/sched/sched/sched_getparam.c b/sched/sched/sched_getparam.c index 44f9e885fa..0ab047f984 100644 --- a/sched/sched/sched_getparam.c +++ b/sched/sched/sched_getparam.c @@ -110,7 +110,7 @@ int sched_getparam (pid_t pid, FAR struct sched_param *param) /* Check if the task to restart is the calling task */ - rtcb = (FAR struct tcb_s *)g_readytorun.head; + rtcb = this_task(); if ((pid == 0) || (pid == rtcb->pid)) { /* Return the priority if the calling task. */ diff --git a/sched/sched/sched_getscheduler.c b/sched/sched/sched_getscheduler.c index dfbb0e2818..a1afddf28e 100644 --- a/sched/sched/sched_getscheduler.c +++ b/sched/sched/sched_getscheduler.c @@ -107,7 +107,7 @@ int sched_getscheduler(pid_t pid) if (!pid) { - tcb = (struct tcb_s *)g_readytorun.head; + tcb = this_task(); } else { diff --git a/sched/sched/sched_getsockets.c b/sched/sched/sched_getsockets.c index b292cd38ed..2601f90783 100644 --- a/sched/sched/sched_getsockets.c +++ b/sched/sched/sched_getsockets.c @@ -44,10 +44,6 @@ #if CONFIG_NSOCKET_DESCRIPTORS > 0 -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -70,7 +66,7 @@ FAR struct socketlist *sched_getsockets(void) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *rtcb = this_task(); FAR struct task_group_s *group = rtcb->group; DEBUGASSERT(group); diff --git a/sched/sched/sched_getstreams.c b/sched/sched/sched_getstreams.c index 29f3074b7a..91f3c9f6f3 100644 --- a/sched/sched/sched_getstreams.c +++ b/sched/sched/sched_getstreams.c @@ -41,10 +41,6 @@ #include #include "sched/sched.h" -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -69,7 +65,7 @@ FAR struct streamlist *sched_getstreams(void) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *rtcb = this_task(); FAR struct task_group_s *group = rtcb->group; DEBUGASSERT(group); diff --git a/sched/sched/sched_lock.c b/sched/sched/sched_lock.c index b01134d5c7..3f5020789c 100644 --- a/sched/sched/sched_lock.c +++ b/sched/sched/sched_lock.c @@ -45,30 +45,6 @@ #include #include "sched/sched.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Functionss - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -93,7 +69,7 @@ int sched_lock(void) { - struct tcb_s *rtcb = (struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *rtcb = this_task(); /* Check for some special cases: (1) rtcb may be NULL only during * early boot-up phases, and (2) sched_lock() should have no diff --git a/sched/sched/sched_lockcount.c b/sched/sched/sched_lockcount.c index b7f7730a73..c3a8ef1903 100644 --- a/sched/sched/sched_lockcount.c +++ b/sched/sched/sched_lockcount.c @@ -43,30 +43,6 @@ #include "sched/sched.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Functionss - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -91,7 +67,6 @@ int sched_lockcount(void) { - struct tcb_s *rtcb = (struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *rtcb = this_task(); return (int)rtcb->lockcount; } - diff --git a/sched/sched/sched_mergepending.c b/sched/sched/sched_mergepending.c index b5028e2008..c62bb70b55 100644 --- a/sched/sched/sched_mergepending.c +++ b/sched/sched/sched_mergepending.c @@ -46,26 +46,6 @@ #include "sched/sched.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -102,7 +82,7 @@ bool sched_mergepending(void) /* Initialize the inner search loop */ - rtrtcb = (FAR struct tcb_s *)g_readytorun.head; + rtrtcb = this_task(); /* Process every TCB in the g_pendingtasks list */ diff --git a/sched/sched/sched_processtimer.c b/sched/sched/sched_processtimer.c index 4a7b246434..33c3f583ac 100644 --- a/sched/sched/sched_processtimer.c +++ b/sched/sched/sched_processtimer.c @@ -58,18 +58,6 @@ # define CONFIG_SCHED_CPULOAD_TIMECONSTANT 2 #endif -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - /**************************************************************************** * Private Functions ****************************************************************************/ @@ -92,7 +80,7 @@ #if CONFIG_RR_INTERVAL > 0 || defined(CONFIG_SCHED_SPORADIC) static inline void sched_process_scheduler(void) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *rtcb = this_task(); #if CONFIG_RR_INTERVAL > 0 /* Check if the currently executing task uses round robin scheduling. */ diff --git a/sched/sched/sched_rrgetinterval.c b/sched/sched/sched_rrgetinterval.c index 5347f64166..3faefb44d2 100644 --- a/sched/sched/sched_rrgetinterval.c +++ b/sched/sched/sched_rrgetinterval.c @@ -91,7 +91,7 @@ int sched_rr_get_interval(pid_t pid, struct timespec *interval) if (!pid) { - rrtcb = (FAR struct tcb_s *)g_readytorun.head; + rrtcb = this_task(); } /* Return a special error code on invalid PID */ diff --git a/sched/sched/sched_self.c b/sched/sched/sched_self.c index 6302aa2208..97ba42d604 100644 --- a/sched/sched/sched_self.c +++ b/sched/sched/sched_self.c @@ -41,26 +41,6 @@ #include #include "sched/sched.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -77,7 +57,5 @@ FAR struct tcb_s *sched_self(void) { - return (FAR struct tcb_s *)g_readytorun.head; + return this_task(); } - - diff --git a/sched/sched/sched_setparam.c b/sched/sched/sched_setparam.c index cadda71bd3..2af8d82405 100644 --- a/sched/sched/sched_setparam.c +++ b/sched/sched/sched_setparam.c @@ -106,7 +106,7 @@ int sched_setparam(pid_t pid, FAR const struct sched_param *param) /* Check if the task to reprioritize is the calling task */ - rtcb = (FAR struct tcb_s *)g_readytorun.head; + rtcb = this_task(); if (pid == 0 || pid == rtcb->pid) { tcb = rtcb; diff --git a/sched/sched/sched_setpriority.c b/sched/sched/sched_setpriority.c index abb660cb3c..3089756eec 100644 --- a/sched/sched/sched_setpriority.c +++ b/sched/sched/sched_setpriority.c @@ -103,7 +103,7 @@ int sched_setpriority(FAR struct tcb_s *tcb, int sched_priority) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *rtcb = this_task(); tstate_t task_state; irqstate_t saved_state; diff --git a/sched/sched/sched_timerexpiration.c b/sched/sched/sched_timerexpiration.c index 41b12c4022..0c329e23cc 100644 --- a/sched/sched/sched_timerexpiration.c +++ b/sched/sched/sched_timerexpiration.c @@ -164,8 +164,8 @@ static struct timespec g_stop_time; #if CONFIG_RR_INTERVAL > 0 || defined(CONFIG_SCHED_SPORADIC) static inline uint32_t sched_process_scheduler(uint32_t ticks, bool noswitches) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; - FAR struct tcb_s *ntcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *rtcb = this_task(); + FAR struct tcb_s *ntcb = this_task(); uint32_t ret = 0; #if CONFIG_RR_INTERVAL > 0 @@ -212,7 +212,7 @@ static inline uint32_t sched_process_scheduler(uint32_t ticks, bool noswitches) * the new task at the head of the ready to run list. */ - ntcb = (FAR struct tcb_s *)g_readytorun.head; + ntcb = this_task(); /* Check if the new task at the head of the ready-to-run has changed. */ diff --git a/sched/sched/sched_unlock.c b/sched/sched/sched_unlock.c index 8c18aac6f1..15a5e9adb4 100644 --- a/sched/sched/sched_unlock.c +++ b/sched/sched/sched_unlock.c @@ -63,7 +63,7 @@ int sched_unlock(void) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *rtcb = this_task(); /* Check for some special cases: (1) rtcb may be NULL only during * early boot-up phases, and (2) sched_unlock() should have no @@ -118,7 +118,7 @@ int sched_unlock(void) * maximum. */ - if (rtcb != (FAR struct tcb_s *)g_readytorun.head) + if (rtcb != this_task()) { rtcb->timeslice = MSEC2TICK(CONFIG_RR_INTERVAL); } @@ -156,7 +156,7 @@ int sched_unlock(void) * change the currently active task. */ - if (rtcb == (FAR struct tcb_s *)g_readytorun.head) + if (rtcb == this_task()) { sched_timer_reassess(); } diff --git a/sched/sched/sched_waitid.c b/sched/sched/sched_waitid.c index 8c24744945..c6fd8d4501 100644 --- a/sched/sched/sched_waitid.c +++ b/sched/sched/sched_waitid.c @@ -154,7 +154,7 @@ static void exited_child(FAR struct tcb_s *rtcb, FAR struct child_status_s *chil int waitid(idtype_t idtype, id_t id, FAR siginfo_t *info, int options) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *rtcb = this_task(); FAR struct tcb_s *ctcb; #ifdef CONFIG_SCHED_CHILD_STATUS FAR struct child_status_s *child; diff --git a/sched/sched/sched_waitpid.c b/sched/sched/sched_waitpid.c index 84e197a288..4a669958c7 100644 --- a/sched/sched/sched_waitpid.c +++ b/sched/sched/sched_waitpid.c @@ -294,7 +294,7 @@ errout: #else pid_t waitpid(pid_t pid, int *stat_loc, int options) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *rtcb = this_task(); FAR struct tcb_s *ctcb; #ifdef CONFIG_SCHED_CHILD_STATUS FAR struct child_status_s *child; diff --git a/sched/sched/sched_yield.c b/sched/sched/sched_yield.c index 17d3bb0bbf..c55a925dac 100644 --- a/sched/sched/sched_yield.c +++ b/sched/sched/sched_yield.c @@ -43,30 +43,6 @@ #include "sched/sched.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -90,7 +66,7 @@ int sched_yield(void) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *rtcb = this_task(); /* This equivalent to just resetting the task priority to its current value * since this will cause the task to be rescheduled behind any other tasks diff --git a/sched/semaphore/sem_holder.c b/sched/semaphore/sem_holder.c index 3b5b2b7286..854747cb01 100644 --- a/sched/semaphore/sem_holder.c +++ b/sched/semaphore/sem_holder.c @@ -565,7 +565,7 @@ static int sem_restoreholderprio(FAR struct semholder_s *pholder, static int sem_restoreholderprioA(FAR struct semholder_s *pholder, FAR sem_t *sem, FAR void *arg) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *rtcb = this_task(); if (pholder->htcb != rtcb) { return sem_restoreholderprio(pholder, sem, arg); @@ -585,7 +585,7 @@ static int sem_restoreholderprioA(FAR struct semholder_s *pholder, static int sem_restoreholderprioB(FAR struct semholder_s *pholder, FAR sem_t *sem, FAR void *arg) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *rtcb = this_task(); if (pholder->htcb == rtcb) { (void)sem_restoreholderprio(pholder, sem, arg); @@ -691,7 +691,7 @@ static inline void sem_restorebaseprio_irq(FAR struct tcb_s *stcb, static inline void sem_restorebaseprio_task(FAR struct tcb_s *stcb, FAR sem_t *sem) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *rtcb = this_task(); FAR struct semholder_s *pholder; /* Perform the following actions only if a new thread was given a count. @@ -850,7 +850,7 @@ void sem_destroyholder(FAR sem_t *sem) void sem_addholder(FAR sem_t *sem) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *rtcb = this_task(); FAR struct semholder_s *pholder; /* Find or allocate a container for this new holder */ @@ -885,7 +885,7 @@ void sem_addholder(FAR sem_t *sem) void sem_boostpriority(FAR sem_t *sem) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *rtcb = this_task(); /* Boost the priority of every thread holding counts on this semaphore * that are lower in priority than the new thread that is waiting for a @@ -914,7 +914,7 @@ void sem_boostpriority(FAR sem_t *sem) void sem_releaseholder(FAR sem_t *sem) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *rtcb = this_task(); FAR struct semholder_s *pholder; /* Find the container for this holder */ diff --git a/sched/semaphore/sem_tickwait.c b/sched/semaphore/sem_tickwait.c index 804e1ed83c..66d4f446d7 100644 --- a/sched/semaphore/sem_tickwait.c +++ b/sched/semaphore/sem_tickwait.c @@ -82,7 +82,7 @@ int sem_tickwait(FAR sem_t *sem, systime_t start, uint32_t delay) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *rtcb = this_task(); irqstate_t flags; systime_t elapsed; int ret; diff --git a/sched/semaphore/sem_timedwait.c b/sched/semaphore/sem_timedwait.c index 106a8bc404..e5722d401b 100644 --- a/sched/semaphore/sem_timedwait.c +++ b/sched/semaphore/sem_timedwait.c @@ -94,7 +94,7 @@ int sem_timedwait(FAR sem_t *sem, FAR const struct timespec *abstime) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *rtcb = this_task(); irqstate_t flags; int ticks; int errcode; diff --git a/sched/semaphore/sem_trywait.c b/sched/semaphore/sem_trywait.c index 75c92dd7b5..e6d8830519 100644 --- a/sched/semaphore/sem_trywait.c +++ b/sched/semaphore/sem_trywait.c @@ -48,26 +48,6 @@ #include "sched/sched.h" #include "semaphore/semaphore.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -96,7 +76,7 @@ int sem_trywait(FAR sem_t *sem) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *rtcb = this_task(); irqstate_t saved_state; int ret = ERROR; diff --git a/sched/semaphore/sem_wait.c b/sched/semaphore/sem_wait.c index b7d5378295..7e88140b72 100644 --- a/sched/semaphore/sem_wait.c +++ b/sched/semaphore/sem_wait.c @@ -76,7 +76,7 @@ int sem_wait(FAR sem_t *sem) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *rtcb = this_task(); irqstate_t saved_state; int ret = ERROR; diff --git a/sched/signal/sig_action.c b/sched/signal/sig_action.c index 99b8aa51e8..8c88f55e12 100644 --- a/sched/signal/sig_action.c +++ b/sched/signal/sig_action.c @@ -58,18 +58,6 @@ (t)->sa_mask = (f)->sa_mask; \ (t)->sa_flags = (f)->sa_flags; } -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - /**************************************************************************** * Private Functions ****************************************************************************/ @@ -165,7 +153,7 @@ static FAR sigactq_t *sig_allocateaction(void) int sigaction(int signo, FAR const struct sigaction *act, FAR struct sigaction *oact) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *rtcb = this_task(); FAR sigactq_t *sigact; /* Since sigactions can only be installed from the running thread of diff --git a/sched/signal/sig_kill.c b/sched/signal/sig_kill.c index 08416f3a3e..0fa9930e8a 100644 --- a/sched/signal/sig_kill.c +++ b/sched/signal/sig_kill.c @@ -85,7 +85,7 @@ int kill(pid_t pid, int signo) { #ifdef CONFIG_SCHED_HAVE_PARENT - FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *rtcb = this_task(); #endif siginfo_t info; int ret; diff --git a/sched/signal/sig_mqnotempty.c b/sched/signal/sig_mqnotempty.c index 25ce0e3ae1..44b05b7aff 100644 --- a/sched/signal/sig_mqnotempty.c +++ b/sched/signal/sig_mqnotempty.c @@ -48,26 +48,6 @@ #include "sched/sched.h" #include "signal/signal.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functionss - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -90,7 +70,7 @@ int sig_mqnotempty(int pid, int signo, void *sival_ptr) #endif { #ifdef CONFIG_SCHED_HAVE_PARENT - FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *rtcb = this_task(); #endif siginfo_t info; int ret; diff --git a/sched/signal/sig_pending.c b/sched/signal/sig_pending.c index 7615096e41..fe0e537d1e 100644 --- a/sched/signal/sig_pending.c +++ b/sched/signal/sig_pending.c @@ -45,26 +45,6 @@ #include "sched/sched.h" #include "signal/signal.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -89,7 +69,7 @@ int sigpending(FAR sigset_t *set) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *rtcb = this_task(); int ret = ERROR; if (set) diff --git a/sched/signal/sig_procmask.c b/sched/signal/sig_procmask.c index 2e18c3cd9e..5f0c68e389 100644 --- a/sched/signal/sig_procmask.c +++ b/sched/signal/sig_procmask.c @@ -53,26 +53,6 @@ #include "sched/sched.h" #include "signal/signal.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -113,7 +93,7 @@ int sigprocmask(int how, FAR const sigset_t *set, FAR sigset_t *oset) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *rtcb = this_task(); sigset_t oldsigprocmask; irqstate_t saved_state; int ret = OK; diff --git a/sched/signal/sig_queue.c b/sched/signal/sig_queue.c index 8b09528f80..3daa59c155 100644 --- a/sched/signal/sig_queue.c +++ b/sched/signal/sig_queue.c @@ -48,26 +48,6 @@ #include "sched/sched.h" #include "signal/signal.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -112,7 +92,7 @@ int sigqueue(int pid, int signo, void *sival_ptr) #endif { #ifdef CONFIG_SCHED_HAVE_PARENT - FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *rtcb = this_task(); #endif siginfo_t info; int ret; diff --git a/sched/signal/sig_suspend.c b/sched/signal/sig_suspend.c index 6e9e964b70..56dc982991 100644 --- a/sched/signal/sig_suspend.c +++ b/sched/signal/sig_suspend.c @@ -49,26 +49,6 @@ #include "sched/sched.h" #include "signal/signal.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -110,7 +90,7 @@ int sigsuspend(FAR const sigset_t *set) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *rtcb = this_task(); sigset_t intersection; sigset_t saved_sigprocmask; FAR sigpendq_t *sigpend; diff --git a/sched/signal/sig_timedwait.c b/sched/signal/sig_timedwait.c index 7443fd17fc..ecf0798f87 100644 --- a/sched/signal/sig_timedwait.c +++ b/sched/signal/sig_timedwait.c @@ -66,18 +66,6 @@ #define SIG_WAIT_TIMEOUT 0xff -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - /**************************************************************************** * Private Functions ****************************************************************************/ @@ -175,7 +163,7 @@ static void sig_timeout(int argc, wdparm_t itcb) int sigtimedwait(FAR const sigset_t *set, FAR struct siginfo *info, FAR const struct timespec *timeout) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *rtcb = this_task(); sigset_t intersection; FAR sigpendq_t *sigpend; irqstate_t saved_state; diff --git a/sched/signal/sig_unmaskpendingsignal.c b/sched/signal/sig_unmaskpendingsignal.c index 5b22af6765..7781515e00 100644 --- a/sched/signal/sig_unmaskpendingsignal.c +++ b/sched/signal/sig_unmaskpendingsignal.c @@ -44,26 +44,6 @@ #include "sched/sched.h" #include "signal/signal.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -80,7 +60,7 @@ void sig_unmaskpendingsignal(void) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *rtcb = this_task(); sigset_t unmaskedset; FAR sigpendq_t *pendingsig; int signo; diff --git a/sched/task/exit.c b/sched/task/exit.c index f9011cb83c..582fe5a05c 100644 --- a/sched/task/exit.c +++ b/sched/task/exit.c @@ -49,30 +49,6 @@ #include "task/task.h" #include "sched/sched.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -93,7 +69,7 @@ void exit(int status) { - struct tcb_s *tcb = (struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *tcb = this_task(); /* Only the lower 8-bits of status are used */ diff --git a/sched/task/task_atexit.c b/sched/task/task_atexit.c index 07eab08644..ba26f3ab8c 100644 --- a/sched/task/task_atexit.c +++ b/sched/task/task_atexit.c @@ -52,30 +52,6 @@ #ifdef CONFIG_SCHED_ATEXIT -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -121,7 +97,7 @@ int atexit(void (*func)(void)) return on_exit((onexitfunc_t)func, NULL); #elif defined(CONFIG_SCHED_ATEXIT_MAX) && CONFIG_SCHED_ATEXIT_MAX > 1 - FAR struct tcb_s *tcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *tcb = this_task(); FAR struct task_group_s *group = tcb->group; int index; int ret = ERROR; @@ -155,7 +131,7 @@ int atexit(void (*func)(void)) return ret; #else - FAR struct tcb_s *tcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *tcb = this_task(); FAR struct task_group_s *group = tcb->group; int ret = ERROR; diff --git a/sched/task/task_delete.c b/sched/task/task_delete.c index fea823d5e8..5b4c0f747d 100644 --- a/sched/task/task_delete.c +++ b/sched/task/task_delete.c @@ -46,30 +46,6 @@ #include "sched/sched.h" #include "task/task.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -117,7 +93,7 @@ int task_delete(pid_t pid) /* Check if the task to delete is the calling task */ - rtcb = (FAR struct tcb_s *)g_readytorun.head; + rtcb = this_task(); if (pid == 0 || pid == rtcb->pid) { /* If it is, then what we really wanted to do was exit. Note that we diff --git a/sched/task/task_exit.c b/sched/task/task_exit.c index ce9c2ad38e..73eab8169f 100644 --- a/sched/task/task_exit.c +++ b/sched/task/task_exit.c @@ -48,30 +48,6 @@ #endif #include "task/task.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -106,7 +82,7 @@ int task_exit(void) { - FAR struct tcb_s *dtcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *dtcb = this_task(); FAR struct tcb_s *rtcb; int ret; @@ -119,7 +95,7 @@ int task_exit(void) */ (void)sched_removereadytorun(dtcb); - rtcb = (FAR struct tcb_s *)g_readytorun.head; + rtcb = this_task(); /* We are now in a bad state -- the head of the ready to run task list * does not correspond to the thread that is running. Disabling pre- diff --git a/sched/task/task_getpid.c b/sched/task/task_getpid.c index e1400d6bfd..2d972b039d 100644 --- a/sched/task/task_getpid.c +++ b/sched/task/task_getpid.c @@ -44,26 +44,6 @@ #include "sched/sched.h" #include "task/task.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -87,7 +67,7 @@ pid_t getpid(void) * with pid == 0 must be running. */ - rtcb = (FAR struct tcb_s *)g_readytorun.head; + rtcb = this_task(); if (rtcb) { /* Return the task ID from the TCB at the head of the ready-to-run diff --git a/sched/task/task_onexit.c b/sched/task/task_onexit.c index a1172abd06..6d3d47fce6 100644 --- a/sched/task/task_onexit.c +++ b/sched/task/task_onexit.c @@ -52,30 +52,6 @@ #ifdef CONFIG_SCHED_ONEXIT -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -116,7 +92,7 @@ int on_exit(CODE void (*func)(int, FAR void *), FAR void *arg) { #if defined(CONFIG_SCHED_ONEXIT_MAX) && CONFIG_SCHED_ONEXIT_MAX > 1 - FAR struct tcb_s *tcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *tcb = this_task(); FAR struct task_group_s *group = tcb->group; int index; int ret = ENOSPC; @@ -151,7 +127,7 @@ int on_exit(CODE void (*func)(int, FAR void *), FAR void *arg) return ret; #else - FAR struct tcb_s *tcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *tcb = this_task(); FAR struct task_group_s *group = tcb->group; int ret = ENOSPC; diff --git a/sched/task/task_prctl.c b/sched/task/task_prctl.c index b89c578709..1908872536 100644 --- a/sched/task/task_prctl.c +++ b/sched/task/task_prctl.c @@ -50,10 +50,6 @@ #include "sched/sched.h" #include "task/task.h" -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -102,7 +98,7 @@ int prctl(int option, ...) if (!pid) { - tcb = (FAR struct tcb_s *)g_readytorun.head; + tcb = this_task(); } else { diff --git a/sched/task/task_restart.c b/sched/task/task_restart.c index e6229adf4f..71c6f77adc 100644 --- a/sched/task/task_restart.c +++ b/sched/task/task_restart.c @@ -50,30 +50,6 @@ #include "signal/signal.h" #include "task/task.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -115,7 +91,7 @@ int task_restart(pid_t pid) /* Check if the task to restart is the calling task */ - rtcb = (FAR struct tcb_s *)g_readytorun.head; + rtcb = this_task(); if ((pid == 0) || (pid == rtcb->pid)) { /* Not implemented */ diff --git a/sched/task/task_setup.c b/sched/task/task_setup.c index feb45b83fd..d7730c6509 100644 --- a/sched/task/task_setup.c +++ b/sched/task/task_setup.c @@ -63,15 +63,7 @@ #define MAX_STACK_ARGS 256 /**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /* This is the name for un-named tasks */ @@ -183,7 +175,7 @@ static int task_assignpid(FAR struct tcb_s *tcb) #ifdef CONFIG_SCHED_HAVE_PARENT static inline void task_saveparent(FAR struct tcb_s *tcb, uint8_t ttype) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *rtcb = this_task(); #if defined(HAVE_GROUP_MEMBERS) || defined(CONFIG_SCHED_CHILD_STATUS) DEBUGASSERT(tcb && tcb->group && rtcb->group); @@ -288,7 +280,7 @@ static inline void task_saveparent(FAR struct tcb_s *tcb, uint8_t ttype) #ifdef CONFIG_PIC static inline void task_dupdspace(FAR struct tcb_s *tcb) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *rtcb = this_task(); if (rtcb->dspace != NULL) { /* Copy the D-Space structure reference and increment the reference diff --git a/sched/task/task_start.c b/sched/task/task_start.c index 6beeccff97..9737d2ddf3 100644 --- a/sched/task/task_start.c +++ b/sched/task/task_start.c @@ -100,7 +100,7 @@ void task_start(void) { - FAR struct task_tcb_s *tcb = (FAR struct task_tcb_s *)g_readytorun.head; + FAR struct task_tcb_s *tcb = (FAR struct task_tcb_s *)this_task(); int exitcode; int argc; diff --git a/sched/task/task_vfork.c b/sched/task/task_vfork.c index 65cdf481cf..b2fef61d36 100644 --- a/sched/task/task_vfork.c +++ b/sched/task/task_vfork.c @@ -240,7 +240,7 @@ static inline int vfork_argsetup(FAR struct tcb_s *parent, FAR struct task_tcb_s *task_vforksetup(start_t retaddr) { - struct tcb_s *parent = (FAR struct tcb_s *)g_readytorun.head; + struct tcb_s *parent = this_task(); struct task_tcb_s *child; uint8_t ttype; int priority; @@ -364,12 +364,12 @@ errout_with_tcb: pid_t task_vforkstart(FAR struct task_tcb_s *child) { - struct tcb_s *parent = (FAR struct tcb_s *)g_readytorun.head; + struct tcb_s *parent = this_task(); pid_t pid; int rc; int ret; - svdbg("Starting Child TCB=%p, parent=%p\n", child, g_readytorun.head); + svdbg("Starting Child TCB=%p, parent=%p\n", child, this_task()); DEBUGASSERT(child); /* Duplicate the original argument list in the forked child TCB */