diff options
author | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2009-09-06 16:50:07 +0000 |
---|---|---|
committer | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2009-09-06 16:50:07 +0000 |
commit | 1f2dd43b3ebca18d849527e1be6f93d473298677 (patch) | |
tree | 6a12590044e84cae3e0b0b93bc823d63f888a1ef /os/kernel | |
parent | 6535195a339ef68e4550a9d2b831e6b640a34401 (diff) | |
download | ChibiOS-1f2dd43b3ebca18d849527e1be6f93d473298677.tar.gz ChibiOS-1f2dd43b3ebca18d849527e1be6f93d473298677.tar.bz2 ChibiOS-1f2dd43b3ebca18d849527e1be6f93d473298677.zip |
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1155 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'os/kernel')
-rw-r--r-- | os/kernel/src/chmtx.c | 37 | ||||
-rw-r--r-- | os/kernel/src/chschd.c | 10 |
2 files changed, 26 insertions, 21 deletions
diff --git a/os/kernel/src/chmtx.c b/os/kernel/src/chmtx.c index cc3c91e3e..9e568c782 100644 --- a/os/kernel/src/chmtx.c +++ b/os/kernel/src/chmtx.c @@ -69,7 +69,7 @@ void chMtxLockS(Mutex *mp) { chDbgCheck(mp != NULL, "chMtxLockS"); - /* the mutex is already locked? */ + /* Ia the mutex already locked? */ if (mp->m_owner != NULL) { /* * Priority inheritance protocol; explores the thread-mutex dependencies @@ -77,50 +77,47 @@ void chMtxLockS(Mutex *mp) { * of the running thread requesting the mutex. */ Thread *tp = mp->m_owner; - /* { tp is the thread currently owning the mutex } */ - /* the running thread has higher priority than tp? */ + /* {tp is the thread currently owning the mutex} */ + /* Has the running thread higher priority than tp? */ while (tp->p_prio < currp->p_prio) { - /* make priority of thread tp match the running thread's priority */ + /* Make priority of thread tp match the running thread's priority.*/ tp->p_prio = currp->p_prio; /* * The following states need priority queues reordering. */ switch (tp->p_state) { - /* thread tp is waiting on a mutex? */ case PRWTMTX: - /* Requeues tp with its new priority on the mutex wait queue. */ + /* Re-enqueues tp with its new priority on the mutex wait queue.*/ prio_insert(dequeue(tp), &tp->p_wtmtxp->m_queue); - /* boost the owner of this mutex if needed */ + /* Boost the owner of this mutex if needed.*/ tp = tp->p_wtmtxp->m_owner; continue; #if CH_USE_CONDVARS case PRWTCOND: - /* Requeues tp with its new priority on the condvar queue. */ + /* Re-enqueues tp with its new priority on the condvar queue.*/ prio_insert(dequeue(tp), &tp->p_wtcondp->c_queue); break; #endif #if CH_USE_SEMAPHORES_PRIORITY case PRWTSEM: - /* Requeues tp with its new priority on the semaphore queue. */ + /* Re-enqueues tp with its new priority on the semaphore queue.*/ prio_insert(dequeue(tp), &tp->p_wtsemp->s_queue); break; #endif #if CH_USE_MESSAGES_PRIORITY case PRSNDMSG: - /* Requeues tp with its new priority on the server thread queue. */ + /* Re-enqueues tp with its new priority on the server thread queue.*/ prio_insert(dequeue(tp), &tp->p_wtthdp->p_msgqueue); break; #endif - /* thread tp is ready? */ case PRREADY: - /* Requeue tp with its new priority on the ready list. */ + /* Re-enqueues tp with its new priority on the ready list.*/ chSchReadyI(dequeue(tp)); } break; } - /* sleep on the mutex */ + /* Sleep on the mutex.*/ prio_insert(currp, &mp->m_queue); - /* thread remembers the mutex where it is waiting on */ currp->p_wtmtxp = mp; chSchGoSleepS(PRWTMTX); chDbgAssert(mp->m_owner == NULL, "chMtxLockS(), #1", "still owned"); @@ -201,24 +198,24 @@ Mutex *chMtxUnlock(void) { * If a thread is waiting on the mutex then the hard part begins. */ if (chMtxQueueNotEmptyS(ump)) { - /* get the highest priority thread waiting for the unlocked mutex */ + /* Get the highest priority thread waiting for the unlocked mutex.*/ Thread *tp = fifo_remove(&ump->m_queue); /* * Recalculates the optimal thread priority by scanning the owned mutexes list. */ tprio_t newprio = currp->p_realprio; - /* iterate mp over all the (other) mutexes the current thread still owns */ + /* Iterate mp over all the (other) mutexes the current thread still owns.*/ mp = currp->p_mtxlist; while (mp != NULL) { - /* mutex mp has a higher priority thread pending? */ + /* Has the mutex mp a higher priority thread pending? */ if (chMtxQueueNotEmptyS(mp) && (mp->m_queue.p_next->p_prio > newprio)) - /* boost current thread's priority to waiting thread */ + /* Boost the recalculated thread's priority to waiting thread.*/ newprio = mp->m_queue.p_next->p_prio; mp = mp->m_next; } - /* (possibly) boost the priority of the current thread */ + /* Possibly restores the priority of the current thread.*/ currp->p_prio = newprio; - /* awaken the highest priority thread waiting for the unlocked mutex */ + /* Awaken the highest priority thread waiting for the unlocked mutex.*/ chSchWakeupS(tp, RDY_OK); } chSysUnlock(); diff --git a/os/kernel/src/chschd.c b/os/kernel/src/chschd.c index 7ab32f068..093a1a0c0 100644 --- a/os/kernel/src/chschd.c +++ b/os/kernel/src/chschd.c @@ -162,6 +162,7 @@ msg_t chSchGoSleepTimeoutS(tstate_t newstate, systime_t time) { * @param[in] msg message to the awakened thread * @note It is equivalent to a @p chSchReadyI() followed by a * @p chSchRescheduleS() but much more efficient. + * @note The function assumes that the current thread has the highest priority */ void chSchWakeupS(Thread *ntp, msg_t msg) { @@ -175,10 +176,17 @@ void chSchWakeupS(Thread *ntp, msg_t msg) { else { Thread *otp = currp; chSchReadyI(otp); - (currp = ntp)->p_state = PRCURR; #if CH_USE_ROUNDROBIN rlist.r_preempt = CH_TIME_QUANTUM; #endif +#if 0 + /* Shortcut for when the round robin scheduling is not enabled.*/ + otp->p_state = PRREADY; + /* Direct insertion on top of the ready list, no scanning.*/ + otp->p_next = rlist.r_queue.p_next->p_next; + otp->p_next->p_prev = rlist.r_queue.p_next = otp; +#endif + (currp = ntp)->p_state = PRCURR; chDbgTrace(otp, ntp); chSysSwitchI(otp, ntp); } |