Made the scheduler code more readable.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@849 35acf78f-673a-0410-8e92-d51de3d6d3f4
This commit is contained in:
parent
6ec06f6ff4
commit
dbf48157fb
|
@ -168,9 +168,7 @@ void PendSVVector(void) {
|
||||||
/* set the round-robin time quantum */
|
/* set the round-robin time quantum */
|
||||||
rlist.r_preempt = CH_TIME_QUANTUM;
|
rlist.r_preempt = CH_TIME_QUANTUM;
|
||||||
#endif
|
#endif
|
||||||
#if CH_DBG_ENABLE_TRACE
|
|
||||||
chDbgTrace(otp, currp);
|
chDbgTrace(otp, currp);
|
||||||
#endif
|
|
||||||
sp_thd = currp->p_ctx.r13;
|
sp_thd = currp->p_ctx.r13;
|
||||||
|
|
||||||
POP_CONTEXT(sp_thd);
|
POP_CONTEXT(sp_thd);
|
||||||
|
|
24
src/chschd.c
24
src/chschd.c
|
@ -86,9 +86,7 @@ void chSchGoSleepS(tstate_t newstate) {
|
||||||
#if CH_USE_ROUNDROBIN
|
#if CH_USE_ROUNDROBIN
|
||||||
rlist.r_preempt = CH_TIME_QUANTUM;
|
rlist.r_preempt = CH_TIME_QUANTUM;
|
||||||
#endif
|
#endif
|
||||||
#if CH_DBG_ENABLE_TRACE
|
|
||||||
chDbgTrace(otp, currp);
|
chDbgTrace(otp, currp);
|
||||||
#endif
|
|
||||||
chSysSwitchI(otp, currp);
|
chSysSwitchI(otp, currp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -163,25 +161,22 @@ msg_t chSchGoSleepTimeoutS(tstate_t newstate, systime_t time) {
|
||||||
* @p chSchRescheduleS() but much more efficient.
|
* @p chSchRescheduleS() but much more efficient.
|
||||||
*/
|
*/
|
||||||
void chSchWakeupS(Thread *ntp, msg_t msg) {
|
void chSchWakeupS(Thread *ntp, msg_t msg) {
|
||||||
|
|
||||||
ntp->p_rdymsg = msg;
|
ntp->p_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
|
||||||
|
* list instead.*/
|
||||||
if (ntp->p_prio <= currp->p_prio)
|
if (ntp->p_prio <= currp->p_prio)
|
||||||
/* the woken thread has equal or lower priority than the running thread */
|
|
||||||
chSchReadyI(ntp);
|
chSchReadyI(ntp);
|
||||||
else {
|
else {
|
||||||
/* the woken thread has higher priority than the running thread and thus
|
|
||||||
* preempts the currently running thread. */
|
|
||||||
Thread *otp = currp;
|
Thread *otp = currp;
|
||||||
chSchReadyI(otp);
|
chSchReadyI(otp);
|
||||||
/* change the to-be-run thread to running state */
|
|
||||||
(currp = ntp)->p_state = PRCURR;
|
(currp = ntp)->p_state = PRCURR;
|
||||||
#if CH_USE_ROUNDROBIN
|
#if CH_USE_ROUNDROBIN
|
||||||
rlist.r_preempt = CH_TIME_QUANTUM;
|
rlist.r_preempt = CH_TIME_QUANTUM;
|
||||||
#endif
|
#endif
|
||||||
#if CH_DBG_ENABLE_TRACE
|
|
||||||
/* trace the context switch */
|
|
||||||
chDbgTrace(otp, ntp);
|
chDbgTrace(otp, ntp);
|
||||||
#endif
|
|
||||||
/* switch the thread context */
|
|
||||||
chSysSwitchI(otp, ntp);
|
chSysSwitchI(otp, ntp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -201,9 +196,7 @@ void chSchDoRescheduleI(void) {
|
||||||
#if CH_USE_ROUNDROBIN
|
#if CH_USE_ROUNDROBIN
|
||||||
rlist.r_preempt = CH_TIME_QUANTUM;
|
rlist.r_preempt = CH_TIME_QUANTUM;
|
||||||
#endif
|
#endif
|
||||||
#if CH_DBG_ENABLE_TRACE
|
|
||||||
chDbgTrace(otp, currp);
|
chDbgTrace(otp, currp);
|
||||||
#endif
|
|
||||||
chSysSwitchI(otp, currp);
|
chSysSwitchI(otp, currp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -221,6 +214,8 @@ void chSchRescheduleS(void) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Evaluates if a reschedulation is required.
|
* @brief Evaluates if a reschedulation is required.
|
||||||
|
* @details The decision is taken by comparing the relative priorities and
|
||||||
|
* depending on the state of the round robin timeout counter.
|
||||||
*
|
*
|
||||||
* @retval TRUE if there is a thread that should go in running state.
|
* @retval TRUE if there is a thread that should go in running state.
|
||||||
* @retval FALSE if a reschedulation is not required.
|
* @retval FALSE if a reschedulation is not required.
|
||||||
|
@ -232,10 +227,11 @@ bool_t chSchRescRequiredI(void) {
|
||||||
/* If the running thread has not reached its time quantum, reschedule only
|
/* If the running thread has not reached its time quantum, reschedule only
|
||||||
* if the first thread on the ready queue has a higher priority.
|
* if the first thread on the ready queue has a higher priority.
|
||||||
* Otherwise, if the running thread has used up its time quantum, reschedule
|
* Otherwise, if the running thread has used up its time quantum, reschedule
|
||||||
* if the first thread on the ready queue has equal or higher priority.
|
* if the first thread on the ready queue has equal or higher priority.*/
|
||||||
*/
|
|
||||||
return rlist.r_preempt ? p1 > p2 : p1 >= p2;
|
return rlist.r_preempt ? p1 > p2 : p1 >= p2;
|
||||||
#else
|
#else
|
||||||
|
/* If the round robin feature is not enabled then performs a simpler
|
||||||
|
* comparison.*/
|
||||||
return p1 > p2;
|
return p1 > p2;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -118,6 +118,12 @@ typedef struct {
|
||||||
#define chDbgPanic(msg) {}
|
#define chDbgPanic(msg) {}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if !CH_DBG_ENABLE_TRACE
|
||||||
|
/* When the trace feature is disabled this function is replaced by an empty
|
||||||
|
* macro.*/
|
||||||
|
#define chDbgTrace(otp, ntp) {}
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue