aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2009-03-14 13:11:10 +0000
committergdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2009-03-14 13:11:10 +0000
commitdbf48157fb9841ec6ccfcfab01f70eefe8f498ce (patch)
treec3e04d48e9541d52a4a61c4f71e4e51efd4c3b95
parent6ec06f6ff43f3de71632415dbc27006b17c00af1 (diff)
downloadChibiOS-dbf48157fb9841ec6ccfcfab01f70eefe8f498ce.tar.gz
ChibiOS-dbf48157fb9841ec6ccfcfab01f70eefe8f498ce.tar.bz2
ChibiOS-dbf48157fb9841ec6ccfcfab01f70eefe8f498ce.zip
Made the scheduler code more readable.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@849 35acf78f-673a-0410-8e92-d51de3d6d3f4
-rw-r--r--ports/ARMCM3/chcore.c2
-rw-r--r--src/chschd.c24
-rw-r--r--src/include/debug.h6
3 files changed, 16 insertions, 16 deletions
diff --git a/ports/ARMCM3/chcore.c b/ports/ARMCM3/chcore.c
index 0159ee71f..80bd13490 100644
--- a/ports/ARMCM3/chcore.c
+++ b/ports/ARMCM3/chcore.c
@@ -168,9 +168,7 @@ void PendSVVector(void) {
/* set the round-robin time quantum */
rlist.r_preempt = CH_TIME_QUANTUM;
#endif
-#if CH_DBG_ENABLE_TRACE
chDbgTrace(otp, currp);
-#endif
sp_thd = currp->p_ctx.r13;
POP_CONTEXT(sp_thd);
diff --git a/src/chschd.c b/src/chschd.c
index 82718342f..441070dcb 100644
--- a/src/chschd.c
+++ b/src/chschd.c
@@ -86,9 +86,7 @@ void chSchGoSleepS(tstate_t newstate) {
#if CH_USE_ROUNDROBIN
rlist.r_preempt = CH_TIME_QUANTUM;
#endif
-#if CH_DBG_ENABLE_TRACE
chDbgTrace(otp, currp);
-#endif
chSysSwitchI(otp, currp);
}
@@ -163,25 +161,22 @@ msg_t chSchGoSleepTimeoutS(tstate_t newstate, systime_t time) {
* @p chSchRescheduleS() but much more efficient.
*/
void chSchWakeupS(Thread *ntp, msg_t 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)
- /* the woken thread has equal or lower priority than the running thread */
chSchReadyI(ntp);
else {
- /* the woken thread has higher priority than the running thread and thus
- * preempts the currently running thread. */
Thread *otp = currp;
chSchReadyI(otp);
- /* change the to-be-run thread to running state */
(currp = ntp)->p_state = PRCURR;
#if CH_USE_ROUNDROBIN
rlist.r_preempt = CH_TIME_QUANTUM;
#endif
-#if CH_DBG_ENABLE_TRACE
- /* trace the context switch */
chDbgTrace(otp, ntp);
-#endif
- /* switch the thread context */
chSysSwitchI(otp, ntp);
}
}
@@ -201,9 +196,7 @@ void chSchDoRescheduleI(void) {
#if CH_USE_ROUNDROBIN
rlist.r_preempt = CH_TIME_QUANTUM;
#endif
-#if CH_DBG_ENABLE_TRACE
chDbgTrace(otp, currp);
-#endif
chSysSwitchI(otp, currp);
}
@@ -221,6 +214,8 @@ void chSchRescheduleS(void) {
/**
* @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 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 first thread on the ready queue has a higher priority.
* 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;
#else
+ /* If the round robin feature is not enabled then performs a simpler
+ * comparison.*/
return p1 > p2;
#endif
}
diff --git a/src/include/debug.h b/src/include/debug.h
index 82e784040..3c51f0837 100644
--- a/src/include/debug.h
+++ b/src/include/debug.h
@@ -118,6 +118,12 @@ typedef struct {
#define chDbgPanic(msg) {}
#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
extern "C" {
#endif