From 7bd8164f8ff6ffd0a9458d44e18097582adae201 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Wed, 20 Jan 2010 14:39:34 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1532 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/include/threads.h | 136 ++++++++++++++++++-------------------------- os/kernel/src/chcond.c | 36 ++++++------ os/kernel/src/chevents.c | 32 ++++++----- os/kernel/src/chmsg.c | 10 ++-- os/kernel/src/chmtx.c | 24 ++++---- os/kernel/src/chschd.c | 26 ++++----- os/kernel/src/chsem.c | 22 +++---- os/kernel/src/chsys.c | 2 +- os/kernel/src/chthreads.c | 32 +++++------ 9 files changed, 149 insertions(+), 171 deletions(-) (limited to 'os/kernel') diff --git a/os/kernel/include/threads.h b/os/kernel/include/threads.h index 1468b0f5a..6c674dea7 100644 --- a/os/kernel/include/threads.h +++ b/os/kernel/include/threads.h @@ -44,118 +44,94 @@ */ struct Thread { Thread *p_next; /**< Next @p Thread in the threads - list/queue.*/ + list/queue. */ /* End of the fields shared with the ThreadsList structure. */ Thread *p_prev; /**< Previous @p Thread in the threads - queue.*/ + queue. */ /* End of the fields shared with the ThreadsQueue structure. */ - tprio_t p_prio; /**< Thread priority.*/ + tprio_t p_prio; /**< Thread priority. */ /* End of the fields shared with the ReadyList structure. */ - tstate_t p_state; /**< Current thread state.*/ - tmode_t p_flags; /**< Various flags.*/ - struct context p_ctx; /**< Processor context.*/ + tstate_t p_state; /**< Current thread state. */ + tmode_t p_flags; /**< Various thread flags. */ + struct context p_ctx; /**< Processor context. */ #if CH_USE_NESTED_LOCKS - cnt_t p_locks; /**< Number of nested locks.*/ + cnt_t p_locks; /**< Number of nested locks. */ #endif #if CH_DBG_THREADS_PROFILING - volatile systime_t p_time; /**< Consumed time. - @note This field can overflow.*/ + volatile systime_t p_time; /**< Thread consumed time in ticks. + @note This field can overflow. */ #endif - /* - * The following fields are merged in unions because they are all - * state-specific fields. This trick saves some extra space for each - * thread in the system. - */ union { - msg_t p_rdymsg; /**< Thread wakeup code.*/ - msg_t p_exitcode; /**< The thread exit code - (@p PREXIT state).*/ - void *p_wtobjp; /**< Generic kernel object pointer used - for opaque access.*/ -#if CH_USE_SEMAPHORES - Semaphore *p_wtsemp; /**< Semaphore where the thread is - waiting on (@p PRWTSEM state).*/ -#endif -#if CH_USE_MUTEXES - Mutex *p_wtmtxp; /**< Mutex where the thread is waiting - on (@p PRWTMTX state).*/ -#endif -#if CH_USE_CONDVARS - CondVar *p_wtcondp; /**< CondVar where the thread is - waiting on (@p PRWTCOND state).*/ -#endif -#if CH_USE_MESSAGES - Thread *p_wtthdp; /**< Destination thread for message - send @p PRSNDMSG state).*/ -#endif + msg_t rdymsg; /**< Thread wakeup code. */ + msg_t exitcode; /**< The thread exit code + (@p THD_STATE_FINAL state). */ + void *wtobjp; /**< Generic kernel object pointer. */ #if CH_USE_EVENTS - eventmask_t p_ewmask; /**< Enabled events mask (@p PRWTOREVT - or @p PRWTANDEVT states).*/ + eventmask_t ewmask; /**< Enabled events mask + (@p THD_STATE_WTOREVT or + @p THD_STATE_WTANDEVT states). */ #endif - }; - /* - * Start of the optional fields. - */ + } p_u; /**< State-specific fields. */ #if CH_USE_WAITEXIT Thread *p_waiting; /**< Thread waiting for termination.*/ #endif #if CH_USE_MESSAGES - ThreadsQueue p_msgqueue; /**< Message queue.*/ - msg_t p_msg; /**< The message.*/ + ThreadsQueue p_msgqueue; /**< Messages queue. */ + msg_t p_msg; /**< Thread message. */ #endif #if CH_USE_EVENTS - eventmask_t p_epending; /**< Pending events mask.*/ + eventmask_t p_epending; /**< Pending events mask. */ #endif #if CH_USE_MUTEXES Mutex *p_mtxlist; /**< List of the mutexes owned by this - thread, @p NULL terminated.*/ + thread, @p NULL terminated. */ tprio_t p_realprio; /**< Thread's own, non-inherited, - priority.*/ + priority. */ #endif #if CH_USE_DYNAMIC && CH_USE_MEMPOOLS void *p_mpool; /**< Memory Pool where the thread - workspace is returned.*/ + workspace is returned. */ #endif /* Extra fields defined in chconf.h */ THREAD_EXT_FIELDS }; /** Thread state: Ready to run, waiting on the ready list.*/ -#define PRREADY 0 -/** Thread state: Currently running. */ -#define PRCURR 1 -/** Thread state: Thread created in suspended state. */ -#define PRSUSPENDED 2 -/** Thread state: Waiting on a semaphore. */ -#define PRWTSEM 3 -/** Thread state: Waiting on a mutex. */ -#define PRWTMTX 4 -/** Thread state: Waiting in @p chThdSleep() or @p chThdSleepUntil(). */ -#define PRWTCOND 5 -/** Thread state: Waiting in @p chCondWait(). */ -#define PRSLEEP 6 -/** Thread state: Waiting in @p chThdWait(). */ -#define PRWAIT 7 +#define THD_STATE_READY 0 +/** Thread state: Currently running.*/ +#define THD_STATE_CURRENT 1 +/** Thread state: Thread created in suspended state.*/ +#define THD_STATE_SUSPENDED 2 +/** Thread state: Waiting on a semaphore.*/ +#define THD_STATE_WTSEM 3 +/** Thread state: Waiting on a mutex.*/ +#define THD_STATE_WTMTX 4 +/** Thread state: Waiting in @p chCondWait().*/ +#define THD_STATE_WTCOND 5 +/** Thread state: Waiting in @p chThdSleep() or @p chThdSleepUntil().*/ +#define THD_STATE_SLEEPING 6 +/** Thread state: Waiting in @p chThdWait().*/ +#define THD_STATE_WTEXIT 7 /** Thread state: Waiting in @p chEvtWaitOneTimeout() or - @p chEvtWaitAnyTimeout(). */ -#define PRWTOREVT 8 -/** Thread state: Waiting in @p chEvtWaitAllTimeout(). */ -#define PRWTANDEVT 9 -/** Thread state: Waiting in @p chMsgSend(). */ -#define PRSNDMSG 10 -/** Thread state: Waiting in @p chMsgWait(). */ -#define PRWTMSG 11 + @p chEvtWaitAnyTimeout().*/ +#define THD_STATE_WTOREVT 8 +/** Thread state: Waiting in @p chEvtWaitAllTimeout().*/ +#define THD_STATE_WTANDEVT 9 +/** Thread state: Waiting in @p chMsgSend().*/ +#define THD_STATE_SNDMSG 10 +/** Thread state: Waiting in @p chMsgWait().*/ +#define THD_STATE_WTMSG 11 /** Thread state: After termination.*/ -#define PREXIT 12 +#define THD_STATE_FINAL 12 /* * Various flags into the thread p_flags field. */ -#define P_MEM_MODE_MASK 3 /* Thread memory mode mask. */ -#define P_MEM_MODE_STATIC 0 /* Thread memory mode: static. */ -#define P_MEM_MODE_HEAP 1 /* Thread memory mode: heap. */ -#define P_MEM_MODE_MEMPOOL 2 /* Thread memory mode: mempool. */ -#define P_TERMINATE 4 /* Termination requested. */ +#define THD_MEM_MODE_MASK 3 /**< Thread memory mode mask. */ +#define THD_MEM_MODE_STATIC 0 /**< Thread memory mode: static.*/ +#define THD_MEM_MODE_HEAP 1 /**< Thread memory mode: heap. */ +#define THD_MEM_MODE_MEMPOOL 2 /**< Thread memory mode: pool. */ +#define THD_TERMINATE 4 /**< Termination requested. */ /* Not an API, don't use into the application code.*/ Thread *init_thread(Thread *tp, tprio_t prio); @@ -205,13 +181,13 @@ extern "C" { #define chThdLS() (void *)(currp + 1) /** - * Verifies if the specified thread is in the @p PREXIT state. + * Verifies if the specified thread is in the @p THD_STATE_FINAL state. * * @param[in] tp the pointer to the thread * @retval TRUE thread terminated. * @retval FALSE thread not terminated. */ -#define chThdTerminated(tp) ((tp)->p_state == PREXIT) +#define chThdTerminated(tp) ((tp)->p_state == THD_STATE_FINAL) /** * Verifies if the current thread has a termination request pending. @@ -219,7 +195,7 @@ extern "C" { * @retval TRUE termination request pended. * @retval FALSE termination request not pended. */ -#define chThdShouldTerminate() (currp->p_flags & P_TERMINATE) +#define chThdShouldTerminate() (currp->p_flags & THD_TERMINATE) /** * Resumes a thread created with @p chThdInit(). @@ -240,7 +216,7 @@ extern "C" { * specification. * . */ -#define chThdSleepS(time) chSchGoSleepTimeoutS(PRSLEEP, time) +#define chThdSleepS(time) chSchGoSleepTimeoutS(THD_STATE_SLEEPING, time) /** * Delays the invoking thread for the specified number of seconds. diff --git a/os/kernel/src/chcond.c b/os/kernel/src/chcond.c index 39b5fd1fc..a7ba23ed5 100644 --- a/os/kernel/src/chcond.c +++ b/os/kernel/src/chcond.c @@ -72,7 +72,7 @@ void chCondSignalI(CondVar *cp) { chDbgCheck(cp != NULL, "chCondSignalI"); if (notempty(&cp->c_queue)) /* any thread ? */ - chSchReadyI(fifo_remove(&cp->c_queue))->p_rdymsg = RDY_OK; + chSchReadyI(fifo_remove(&cp->c_queue))->p_u.rdymsg = RDY_OK; } /** @@ -97,11 +97,11 @@ void chCondBroadcastI(CondVar *cp) { chDbgCheck(cp != NULL, "chCondBroadcastI"); - /* empties the condition variable queue and inserts all the Threads into the + /* Empties the condition variable queue and inserts all the Threads into the * ready list in FIFO order. The wakeup message is set to @p RDY_RESET in - * order to make a chCondBroadcast() detectable from a chCondSignal(). */ + * order to make a chCondBroadcast() detectable from a chCondSignal().*/ while (cp->c_queue.p_next != (void *)&cp->c_queue) - chSchReadyI(fifo_remove(&cp->c_queue))->p_rdymsg = RDY_RESET; + chSchReadyI(fifo_remove(&cp->c_queue))->p_u.rdymsg = RDY_RESET; } /** @@ -146,13 +146,13 @@ msg_t chCondWaitS(CondVar *cp) { "chCondWaitS(), #1", "not owning a mutex"); - mp = chMtxUnlockS(); /* unlocks the condvar mutex */ - prio_insert(currp, &cp->c_queue); /* enters the condvar queue */ - currp->p_wtcondp = cp; /* needed by the tracer */ - chSchGoSleepS(PRWTCOND); /* waits on the condvar */ - msg = currp->p_rdymsg; /* fetches the wakeup message */ - chMtxLockS(mp); /* atomically relocks the mutex */ - return msg; /* returns the wakeup message */ + mp = chMtxUnlockS(); + prio_insert(currp, &cp->c_queue); + currp->p_u.wtobjp = cp; + chSchGoSleepS(THD_STATE_WTCOND); + msg = currp->p_u.rdymsg; + chMtxLockS(mp); + return msg; } #if CH_USE_CONDVARS_TIMEOUT @@ -212,13 +212,13 @@ msg_t chCondWaitTimeoutS(CondVar *cp, systime_t time) { "chCondWaitTimeoutS(), #1", "not owning a mutex"); - mp = chMtxUnlockS(); /* unlocks the condvar mutex */ - prio_insert(currp, &cp->c_queue); /* enters the condvar queue */ - currp->p_wtcondp = cp; /* needed by the tracer */ - chSchGoSleepTimeoutS(PRWTCOND, time); /* waits on the condvar */ - msg = currp->p_rdymsg; /* fetches the wakeup message */ - chMtxLockS(mp); /* atomically relocks the mutex */ - return msg; /* returns the wakeup message */ + mp = chMtxUnlockS(); + prio_insert(currp, &cp->c_queue); + currp->p_u.wtobjp = cp; + chSchGoSleepTimeoutS(THD_STATE_WTCOND, time); + msg = currp->p_u.rdymsg; + chMtxLockS(mp); + return msg; } #endif /* CH_USE_CONDVARS_TIMEOUT */ diff --git a/os/kernel/src/chevents.c b/os/kernel/src/chevents.c index 64636da66..580b0aea9 100644 --- a/os/kernel/src/chevents.c +++ b/os/kernel/src/chevents.c @@ -137,9 +137,11 @@ void chEvtSignalI(Thread *tp, eventmask_t mask) { tp->p_epending |= mask; /* Test on the AND/OR conditions wait states.*/ - if (((tp->p_state == PRWTOREVT) && ((tp->p_epending & tp->p_ewmask) != 0)) || - ((tp->p_state == PRWTANDEVT) && ((tp->p_epending & tp->p_ewmask) == tp->p_ewmask))) - chSchReadyI(tp)->p_rdymsg = RDY_OK; + if (((tp->p_state == THD_STATE_WTOREVT) && + ((tp->p_epending & tp->p_u.ewmask) != 0)) || + ((tp->p_state == THD_STATE_WTANDEVT) && + ((tp->p_epending & tp->p_u.ewmask) == tp->p_u.ewmask))) + chSchReadyI(tp)->p_u.rdymsg = RDY_OK; } /** @@ -220,8 +222,8 @@ eventmask_t chEvtWaitOne(eventmask_t ewmask) { chSysLock(); if ((m = (currp->p_epending & ewmask)) == 0) { - currp->p_ewmask = ewmask; - chSchGoSleepS(PRWTOREVT); + currp->p_u.ewmask = ewmask; + chSchGoSleepS(THD_STATE_WTOREVT); m = currp->p_epending & ewmask; } m &= -m; @@ -246,8 +248,8 @@ eventmask_t chEvtWaitAny(eventmask_t ewmask) { chSysLock(); if ((m = (currp->p_epending & ewmask)) == 0) { - currp->p_ewmask = ewmask; - chSchGoSleepS(PRWTOREVT); + currp->p_u.ewmask = ewmask; + chSchGoSleepS(THD_STATE_WTOREVT); m = currp->p_epending & ewmask; } currp->p_epending &= ~m; @@ -269,8 +271,8 @@ eventmask_t chEvtWaitAll(eventmask_t ewmask) { chSysLock(); if ((currp->p_epending & ewmask) != ewmask) { - currp->p_ewmask = ewmask; - chSchGoSleepS(PRWTANDEVT); + currp->p_u.ewmask = ewmask; + chSchGoSleepS(THD_STATE_WTANDEVT); } currp->p_epending &= ~ewmask; @@ -308,8 +310,8 @@ eventmask_t chEvtWaitOneTimeout(eventmask_t ewmask, systime_t time) { if ((m = (currp->p_epending & ewmask)) == 0) { if (TIME_IMMEDIATE == time) return (eventmask_t)0; - currp->p_ewmask = ewmask; - if (chSchGoSleepTimeoutS(PRWTOREVT, time) < RDY_OK) + currp->p_u.ewmask = ewmask; + if (chSchGoSleepTimeoutS(THD_STATE_WTOREVT, time) < RDY_OK) return (eventmask_t)0; m = currp->p_epending & ewmask; } @@ -344,8 +346,8 @@ eventmask_t chEvtWaitAnyTimeout(eventmask_t ewmask, systime_t time) { if ((m = (currp->p_epending & ewmask)) == 0) { if (TIME_IMMEDIATE == time) return (eventmask_t)0; - currp->p_ewmask = ewmask; - if (chSchGoSleepTimeoutS(PRWTOREVT, time) < RDY_OK) + currp->p_u.ewmask = ewmask; + if (chSchGoSleepTimeoutS(THD_STATE_WTOREVT, time) < RDY_OK) return (eventmask_t)0; m = currp->p_epending & ewmask; } @@ -376,8 +378,8 @@ eventmask_t chEvtWaitAllTimeout(eventmask_t ewmask, systime_t time) { if ((currp->p_epending & ewmask) != ewmask) { if (TIME_IMMEDIATE == time) return (eventmask_t)0; - currp->p_ewmask = ewmask; - if (chSchGoSleepTimeoutS(PRWTANDEVT, time) < RDY_OK) + currp->p_u.ewmask = ewmask; + if (chSchGoSleepTimeoutS(THD_STATE_WTANDEVT, time) < RDY_OK) return (eventmask_t)0; } currp->p_epending &= ~ewmask; diff --git a/os/kernel/src/chmsg.c b/os/kernel/src/chmsg.c index e3c82ec5a..577e82693 100644 --- a/os/kernel/src/chmsg.c +++ b/os/kernel/src/chmsg.c @@ -50,11 +50,11 @@ msg_t chMsgSend(Thread *tp, msg_t msg) { chSysLock(); msg_insert(currp, &tp->p_msgqueue); currp->p_msg = msg; - currp->p_wtthdp = tp; - if (tp->p_state == PRWTMSG) + currp->p_u.wtobjp = tp; + if (tp->p_state == THD_STATE_WTMSG) chSchReadyI(tp); - chSchGoSleepS(PRSNDMSG); - msg = currp->p_rdymsg; + chSchGoSleepS(THD_STATE_SNDMSG); + msg = currp->p_u.rdymsg; chSysUnlock(); return msg; } @@ -73,7 +73,7 @@ msg_t chMsgWait(void) { chSysLock(); if (!chMsgIsPendingI(currp)) - chSchGoSleepS(PRWTMSG); + chSchGoSleepS(THD_STATE_WTMSG); msg = chMsgGetI(currp); chSysUnlock(); return msg; diff --git a/os/kernel/src/chmtx.c b/os/kernel/src/chmtx.c index 21ec5b997..962356db8 100644 --- a/os/kernel/src/chmtx.c +++ b/os/kernel/src/chmtx.c @@ -86,31 +86,31 @@ void chMtxLockS(Mutex *mp) { * The following states need priority queues reordering. */ switch (tp->p_state) { - case PRWTMTX: + case THD_STATE_WTMTX: /* Re-enqueues tp with its new priority on the mutex wait queue.*/ - prio_insert(dequeue(tp), &tp->p_wtmtxp->m_queue); + prio_insert(dequeue(tp), (ThreadsQueue *)&tp->p_u.wtobjp); /* Boost the owner of this mutex if needed.*/ - tp = tp->p_wtmtxp->m_owner; + tp = ((Mutex *)tp->p_u.wtobjp)->m_owner; continue; #if CH_USE_CONDVARS - case PRWTCOND: + case THD_STATE_WTCOND: /* Re-enqueues tp with its new priority on the condvar queue.*/ - prio_insert(dequeue(tp), &tp->p_wtcondp->c_queue); + prio_insert(dequeue(tp), (ThreadsQueue *)&tp->p_u.wtobjp); break; #endif #if CH_USE_SEMAPHORES_PRIORITY - case PRWTSEM: + case THD_STATE_WTSEM: /* Re-enqueues tp with its new priority on the semaphore queue.*/ - prio_insert(dequeue(tp), &tp->p_wtsemp->s_queue); + prio_insert(dequeue(tp), (ThreadsQueue *)&tp->p_u.wtobjp); break; #endif #if CH_USE_MESSAGES_PRIORITY - case PRSNDMSG: + case THD_STATE_SNDMSG: /* Re-enqueues tp with its new priority on the server thread queue.*/ - prio_insert(dequeue(tp), &tp->p_wtthdp->p_msgqueue); + prio_insert(dequeue(tp), ((Thread *)tp->p_u.wtobjp)->p_msgqueue); break; #endif - case PRREADY: + case THD_STATE_READY: /* Re-enqueues tp with its new priority on the ready list.*/ chSchReadyI(dequeue(tp)); } @@ -118,8 +118,8 @@ void chMtxLockS(Mutex *mp) { } /* Sleep on the mutex.*/ prio_insert(currp, &mp->m_queue); - currp->p_wtmtxp = mp; - chSchGoSleepS(PRWTMTX); + currp->p_u.wtobjp = mp; + chSchGoSleepS(THD_STATE_WTMTX); chDbgAssert(mp->m_owner == NULL, "chMtxLockS(), #1", "still owned"); } /* diff --git a/os/kernel/src/chschd.c b/os/kernel/src/chschd.c index 15f7a1a16..f7be9c6a8 100644 --- a/os/kernel/src/chschd.c +++ b/os/kernel/src/chschd.c @@ -60,7 +60,7 @@ Thread *chSchReadyI(Thread *tp) { #endif Thread *cp; - tp->p_state = PRREADY; + tp->p_state = THD_STATE_READY; cp = (Thread *)&rlist.r_queue; do { cp = cp->p_next; @@ -82,7 +82,7 @@ void chSchGoSleepS(tstate_t newstate) { Thread *otp; (otp = currp)->p_state = newstate; - (currp = fifo_remove(&rlist.r_queue))->p_state = PRCURR; + (currp = fifo_remove(&rlist.r_queue))->p_state = THD_STATE_CURRENT; #if CH_TIME_QUANTUM > 0 rlist.r_preempt = CH_TIME_QUANTUM; #endif @@ -99,21 +99,21 @@ static void wakeup(void *p) { #if CH_USE_SEMAPHORES || CH_USE_MUTEXES || CH_USE_CONDVARS switch (tp->p_state) { #if CH_USE_SEMAPHORES - case PRWTSEM: - chSemFastSignalI(tp->p_wtsemp); + case THD_STATE_WTSEM: + chSemFastSignalI((Semaphore *)tp->p_u.wtobjp); /* Falls into, intentional. */ #endif #if CH_USE_MUTEXES - case PRWTMTX: + case THD_STATE_WTMTX: #endif #if CH_USE_CONDVARS - case PRWTCOND: + case THD_STATE_WTCOND: #endif /* States requiring dequeuing.*/ dequeue(tp); } #endif - chSchReadyI(tp)->p_rdymsg = RDY_TIMEOUT; + chSchReadyI(tp)->p_u.rdymsg = RDY_TIMEOUT; } /** @@ -149,7 +149,7 @@ msg_t chSchGoSleepTimeoutS(tstate_t newstate, systime_t time) { } else chSchGoSleepS(newstate); - return currp->p_rdymsg; + return currp->p_u.rdymsg; } /** @@ -166,7 +166,7 @@ msg_t chSchGoSleepTimeoutS(tstate_t newstate, systime_t time) { */ void chSchWakeupS(Thread *ntp, msg_t msg) { - ntp->p_rdymsg = msg; + ntp->p_u.rdymsg = msg; /* If the waken thread has a not-greater priority than the current * one then it is just inserted in the ready list else it made * running immediately and the invoking thread goes in the ready @@ -179,7 +179,7 @@ void chSchWakeupS(Thread *ntp, msg_t msg) { #if CH_TIME_QUANTUM > 0 rlist.r_preempt = CH_TIME_QUANTUM; #endif - (currp = ntp)->p_state = PRCURR; + (currp = ntp)->p_state = THD_STATE_CURRENT; chDbgTrace(otp, ntp); chSysSwitchI(otp, ntp); } @@ -195,7 +195,7 @@ void chSchDoRescheduleI(void) { Thread *otp = currp; /* Pick the first thread from the ready queue and makes it current.*/ - (currp = fifo_remove(&rlist.r_queue))->p_state = PRCURR; + (currp = fifo_remove(&rlist.r_queue))->p_state = THD_STATE_CURRENT; chSchReadyI(otp); #if CH_TIME_QUANTUM > 0 rlist.r_preempt = CH_TIME_QUANTUM; @@ -258,7 +258,7 @@ void chSchDoYieldS(void) { * ready list there is at least one thread with priority equal or higher * than the current one. */ - otp->p_state = PRREADY; + otp->p_state = THD_STATE_READY; do { cp = cp->p_prev; } while (cp->p_prio < otp->p_prio); @@ -267,7 +267,7 @@ void chSchDoYieldS(void) { otp->p_next->p_prev = cp->p_next = otp; /* Pick the first thread from the ready queue and makes it current.*/ - (currp = fifo_remove(&rlist.r_queue))->p_state = PRCURR; + (currp = fifo_remove(&rlist.r_queue))->p_state = THD_STATE_CURRENT; #if CH_TIME_QUANTUM > 0 rlist.r_preempt = CH_TIME_QUANTUM; #endif diff --git a/os/kernel/src/chsem.c b/os/kernel/src/chsem.c index dba765da9..c78d52f74 100644 --- a/os/kernel/src/chsem.c +++ b/os/kernel/src/chsem.c @@ -86,7 +86,7 @@ void chSemResetI(Semaphore *sp, cnt_t n) { cnt = sp->s_cnt; sp->s_cnt = n; while (cnt++ < 0) - chSchReadyI(lifo_remove(&sp->s_queue))->p_rdymsg = RDY_RESET; + chSchReadyI(lifo_remove(&sp->s_queue))->p_u.rdymsg = RDY_RESET; } /** @@ -120,9 +120,9 @@ msg_t chSemWaitS(Semaphore *sp) { if (--sp->s_cnt < 0) { sem_insert(currp, &sp->s_queue); - currp->p_wtsemp = sp; - chSchGoSleepS(PRWTSEM); - return currp->p_rdymsg; + currp->p_u.wtobjp = sp; + chSchGoSleepS(THD_STATE_WTSEM); + return currp->p_u.rdymsg; } return RDY_OK; } @@ -174,8 +174,8 @@ msg_t chSemWaitTimeoutS(Semaphore *sp, systime_t time) { return RDY_TIMEOUT; } sem_insert(currp, &sp->s_queue); - currp->p_wtsemp = sp; - return chSchGoSleepTimeoutS(PRWTSEM, time); + currp->p_u.wtobjp = sp; + return chSchGoSleepTimeoutS(THD_STATE_WTSEM, time); } return RDY_OK; } @@ -213,7 +213,7 @@ void chSemSignalI(Semaphore *sp) { /* NOTE: It is done this way in order to allow a tail call on chSchReadyI().*/ Thread *tp = fifo_remove(&sp->s_queue); - tp->p_rdymsg = RDY_OK; + tp->p_u.rdymsg = RDY_OK; chSchReadyI(tp); } } @@ -236,12 +236,12 @@ msg_t chSemSignalWait(Semaphore *sps, Semaphore *spw) { chSysLock(); if (sps->s_cnt++ < 0) - chSchReadyI(fifo_remove(&sps->s_queue))->p_rdymsg = RDY_OK; + chSchReadyI(fifo_remove(&sps->s_queue))->p_u.rdymsg = RDY_OK; if (--spw->s_cnt < 0) { sem_insert(currp, &spw->s_queue); - currp->p_wtsemp = spw; - chSchGoSleepS(PRWTSEM); - msg = currp->p_rdymsg; + currp->p_u.wtobjp = spw; + chSchGoSleepS(THD_STATE_WTSEM); + msg = currp->p_u.rdymsg; } else { chSchRescheduleS(); diff --git a/os/kernel/src/chsys.c b/os/kernel/src/chsys.c index 74ee794a3..2863f253c 100644 --- a/os/kernel/src/chsys.c +++ b/os/kernel/src/chsys.c @@ -75,7 +75,7 @@ void chSysInit(void) { /* * Now this instructions flow becomes the main thread. */ - (currp = init_thread(&mainthread, NORMALPRIO))->p_state = PRCURR; + (currp = init_thread(&mainthread, NORMALPRIO))->p_state = THD_STATE_CURRENT; chSysEnable(); /* diff --git a/os/kernel/src/chthreads.c b/os/kernel/src/chthreads.c index 6755b0b48..e372a6e5c 100644 --- a/os/kernel/src/chthreads.c +++ b/os/kernel/src/chthreads.c @@ -31,9 +31,9 @@ */ Thread *init_thread(Thread *tp, tprio_t prio) { - tp->p_flags = P_MEM_MODE_STATIC; + tp->p_flags = THD_MEM_MODE_STATIC; tp->p_prio = prio; - tp->p_state = PRSUSPENDED; + tp->p_state = THD_STATE_SUSPENDED; #if CH_USE_NESTED_LOCKS tp->p_locks = 0; #endif @@ -69,7 +69,7 @@ static void memfill(uint8_t *startp, uint8_t *endp, uint8_t v) { /** * @brief Initializes a new thread. * @details The new thread is initialized but not inserted in the ready list, - * the initial state is @p PRSUSPENDED. + * the initial state is @p THD_STATE_SUSPENDED. * * @param[out] wsp pointer to a working area dedicated to the thread stack * @param[in] size size of the working area @@ -150,7 +150,7 @@ Thread *chThdCreateFromHeap(MemoryHeap *heapp, size_t size, if (wsp == NULL) return NULL; tp = chThdInit(wsp, size, prio, pf, arg); - tp->p_flags = P_MEM_MODE_HEAP; + tp->p_flags = THD_MEM_MODE_HEAP; return chThdResume(tp); } #endif /* CH_USE_DYNAMIC && CH_USE_WAITEXIT && CH_USE_HEAP */ @@ -187,7 +187,7 @@ Thread *chThdCreateFromMemoryPool(MemoryPool *mp, tprio_t prio, if (wsp == NULL) return NULL; tp = chThdInit(wsp, mp->mp_object_size, prio, pf, arg); - tp->p_flags = P_MEM_MODE_MEMPOOL; + tp->p_flags = THD_MEM_MODE_MEMPOOL; tp->p_mpool = mp; return chThdResume(tp); } @@ -235,9 +235,9 @@ tprio_t chThdSetPriority(tprio_t newprio) { Thread *chThdResume(Thread *tp) { chSysLock(); - chDbgAssert(tp->p_state == PRSUSPENDED, + chDbgAssert(tp->p_state == THD_STATE_SUSPENDED, "chThdResume(), #1", - "thread not in PRSUSPENDED state"); + "thread not in THD_STATE_SUSPENDED state"); chSchWakeupS(tp, RDY_OK); chSysUnlock(); return tp; @@ -254,7 +254,7 @@ Thread *chThdResume(Thread *tp) { void chThdTerminate(Thread *tp) { chSysLock(); - tp->p_flags |= P_TERMINATE; + tp->p_flags |= THD_TERMINATE; chSysUnlock(); } @@ -315,13 +315,13 @@ void chThdExit(msg_t msg) { Thread *tp = currp; chSysLock(); - tp->p_exitcode = msg; + tp->p_u.exitcode = msg; THREAD_EXT_EXIT(tp); #if CH_USE_WAITEXIT if (tp->p_waiting != NULL) chSchReadyI(tp->p_waiting); #endif - chSchGoSleepS(PREXIT); + chSchGoSleepS(THD_STATE_FINAL); } #if CH_USE_WAITEXIT @@ -362,28 +362,28 @@ msg_t chThdWait(Thread *tp) { chDbgAssert(tp != currp, "chThdWait(), #1", "waiting self"); chDbgAssert(tp->p_waiting == NULL, "chThdWait(), #2", "some other thread waiting"); - if (tp->p_state != PREXIT) { + if (tp->p_state != THD_STATE_FINAL) { tp->p_waiting = currp; - chSchGoSleepS(PRWAIT); + chSchGoSleepS(THD_STATE_WTEXIT); } - msg = tp->p_exitcode; + msg = tp->p_u.exitcode; #if !CH_USE_DYNAMIC chSysUnlock(); return msg; #else /* CH_USE_DYNAMIC */ /* Returning memory.*/ - tmode_t mode = tp->p_flags & P_MEM_MODE_MASK; + tmode_t mode = tp->p_flags & THD_MEM_MODE_MASK; chSysUnlock(); switch (mode) { #if CH_USE_HEAP - case P_MEM_MODE_HEAP: + case THD_MEM_MODE_HEAP: chHeapFree(tp); break; #endif #if CH_USE_MEMPOOLS - case P_MEM_MODE_MEMPOOL: + case THD_MEM_MODE_MEMPOOL: chPoolFree(tp->p_mpool, tp); break; #endif -- cgit v1.2.3