git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1532 35acf78f-673a-0410-8e92-d51de3d6d3f4
parent
ca013cf8e4
commit
7bd8164f8f
|
@ -52,56 +52,32 @@ struct Thread {
|
|||
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.*/
|
||||
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. */
|
||||
#endif
|
||||
#if CH_DBG_THREADS_PROFILING
|
||||
volatile systime_t p_time; /**< Consumed time.
|
||||
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. */
|
||||
|
@ -121,41 +97,41 @@ struct Thread {
|
|||
};
|
||||
|
||||
/** Thread state: Ready to run, waiting on the ready list.*/
|
||||
#define PRREADY 0
|
||||
#define THD_STATE_READY 0
|
||||
/** Thread state: Currently running.*/
|
||||
#define PRCURR 1
|
||||
#define THD_STATE_CURRENT 1
|
||||
/** Thread state: Thread created in suspended state.*/
|
||||
#define PRSUSPENDED 2
|
||||
#define THD_STATE_SUSPENDED 2
|
||||
/** Thread state: Waiting on a semaphore.*/
|
||||
#define PRWTSEM 3
|
||||
#define THD_STATE_WTSEM 3
|
||||
/** Thread state: Waiting on a mutex.*/
|
||||
#define PRWTMTX 4
|
||||
/** Thread state: Waiting in @p chThdSleep() or @p chThdSleepUntil(). */
|
||||
#define PRWTCOND 5
|
||||
#define THD_STATE_WTMTX 4
|
||||
/** Thread state: Waiting in @p chCondWait().*/
|
||||
#define PRSLEEP 6
|
||||
#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 PRWAIT 7
|
||||
#define THD_STATE_WTEXIT 7
|
||||
/** Thread state: Waiting in @p chEvtWaitOneTimeout() or
|
||||
@p chEvtWaitAnyTimeout().*/
|
||||
#define PRWTOREVT 8
|
||||
#define THD_STATE_WTOREVT 8
|
||||
/** Thread state: Waiting in @p chEvtWaitAllTimeout().*/
|
||||
#define PRWTANDEVT 9
|
||||
#define THD_STATE_WTANDEVT 9
|
||||
/** Thread state: Waiting in @p chMsgSend().*/
|
||||
#define PRSNDMSG 10
|
||||
#define THD_STATE_SNDMSG 10
|
||||
/** Thread state: Waiting in @p chMsgWait().*/
|
||||
#define PRWTMSG 11
|
||||
#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.
|
||||
|
|
|
@ -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().*/
|
||||
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 */
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
/*
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
||||
/*
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -52,8 +52,13 @@
|
|||
*****************************************************************************
|
||||
|
||||
*** 1.5.0 ***
|
||||
- FIX: Fixed parameter check in sdStart() function (bug 2932922).
|
||||
- FIX: Fixed missing platform.mk file in MSP430 port (bug 2933735).
|
||||
- FIX: Fixed parameter check in sdStart() function (bug 2932922)(backported in
|
||||
1.4.0).
|
||||
- FIX: Fixed missing platform.mk file in MSP430 port (bug 2933735)(backported
|
||||
in 1.4.0).
|
||||
- CHANGE: Removed the unnamed union from the Thread structure some compilers
|
||||
do not support this non standard construct.
|
||||
- CHANGE: Modified the thread-related constant macros to have a THD_ prefix.
|
||||
|
||||
*** 1.3.8 ***
|
||||
- FIX: Fixed dequeuing in lifo_remove() function (bug 2928142).
|
||||
|
|
|
@ -226,8 +226,8 @@ msg_t thread4(void *p) {
|
|||
(void)p;
|
||||
chSysLock();
|
||||
do {
|
||||
chSchGoSleepS(PRSUSPENDED);
|
||||
msg = self->p_rdymsg;
|
||||
chSchGoSleepS(THD_STATE_SUSPENDED);
|
||||
msg = self->p_u.rdymsg;
|
||||
} while (msg == RDY_OK);
|
||||
chSysUnlock();
|
||||
return 0;
|
||||
|
|
26
todo.txt
26
todo.txt
|
@ -4,30 +4,22 @@ Status:
|
|||
X = In progress, some work done.
|
||||
* = Done.
|
||||
|
||||
Before 1.4.0:
|
||||
* Abstract streams interface (for MAC, USB endpoints, files, sockets etc).
|
||||
* Abstract I/O channels rather than just serial ports.
|
||||
* Add tests documentation to the general documentation via doxygen.
|
||||
* Static object initializers.
|
||||
* Add a central memory manager offering a sbrk()-like API.
|
||||
* Make the heap allocator feed memory chunks from the memory manager.
|
||||
* Dedicated syscalls.c support for newlib users.
|
||||
* HAL and common device drivers.
|
||||
* Multiple heaps, disjoint heaps, heaps in heaps.
|
||||
|
||||
After 1.4.x
|
||||
Before 1.6.0:
|
||||
* Remove instances of unnamed structures/unions.
|
||||
- Active threads registry in the kernel.
|
||||
- Debug-related features and tools.
|
||||
- I2C device driver class support.
|
||||
- USB device support.
|
||||
- USB device driver class support.
|
||||
- MAC driver revision in order to support copy-less operations, this will
|
||||
require changes to lwIP or a new TCP/IP stack however.
|
||||
- Objects registry in the kernel.
|
||||
- OSEK-style simple tasks within the idle thread.
|
||||
- Code examples into the documentation.
|
||||
- More code examples into the documentation.
|
||||
- Update C++ wrapper (Heap, Pools, Mailboxes and any new feature).
|
||||
- Threads Pools manager in the library.
|
||||
? OSEK-style simple tasks within the idle thread.
|
||||
|
||||
After 1.6.0
|
||||
? Minimal optional C-runtime library (complete enough for lwIP).
|
||||
? Think to something for threads restart.
|
||||
? Remove any instance of unnamed structures/unions.
|
||||
|
||||
Ideas for 2.x.x:
|
||||
- High resolution timers and tickless kernel.
|
||||
|
|
Loading…
Reference in New Issue