<ahref="chschd_8c.html">Go to the documentation of this file.</a><divclass="fragment"><preclass="fragment"><aname="l00001"></a>00001 <spanclass="comment">/*</span>
<aname="l00040"></a>00040 <spanclass="preprocessor">#include "<aclass="code"href="ch_8h.html"title="ChibiOS/RT main include file.">ch.h</a>"</span>
<aname="l00046"></a><aclass="code"href="group___s_t_m8___c_o_r_e.html#ga3a6de9d40a3d21712aecc7837fa7c23b">00046</a><spanclass="preprocessor"></span><aclass="code"href="struct_ready_list.html"title="Ready list header.">ReadyList</a><aclass="code"href="group__scheduler.html#ga752cd9dbf0dc458b8b532182836ca38d"title="Ready list header.">rlist</a>;
<aname="l00056"></a>00056 rlist.<aclass="code"href="struct_ready_list.html#aee33d97bf6d798dfd2528db725452bcc"title="This field must be initialized to zero.">r_prio</a> = NOPRIO;
<aname="l00075"></a>00075 <spanclass="preprocessor"></span><spanclass="comment">/* NOTE: it is inlined in this module only.*/</span>
<aname="l00076"></a>00076 <aclass="code"href="group__types.html#ga2eb6f9e0395b47b8d5e3eeae4fe0c116"title="Inline function modifier.">INLINE</a><aclass="code"href="struct_thread.html"title="Structure representing a thread.">Thread</a> *<aclass="code"href="group__scheduler.html#ga535d58cfb3436c8d4e4586c31c062298"title="Inserts a thread in the Ready List.">chSchReadyI</a>(<aclass="code"href="struct_thread.html"title="Structure representing a thread.">Thread</a> *tp) {
<aname="l00078"></a><aclass="code"href="group__scheduler.html#ga535d58cfb3436c8d4e4586c31c062298">00078</a><spanclass="preprocessor"></span><aclass="code"href="struct_thread.html"title="Structure representing a thread.">Thread</a> *<aclass="code"href="group__scheduler.html#ga535d58cfb3436c8d4e4586c31c062298"title="Inserts a thread in the Ready List.">chSchReadyI</a>(<aclass="code"href="struct_thread.html"title="Structure representing a thread.">Thread</a> *tp) {
<aname="l00085"></a>00085 cp = cp-><aclass="code"href="struct_thread.html#a49d3270919a6e423a47de20bc57beaa1"title="Next in the list/queue.">p_next</a>;
<aname="l00088"></a>00088 tp-><aclass="code"href="struct_thread.html#a49d3270919a6e423a47de20bc57beaa1"title="Next in the list/queue.">p_next</a> = cp;
<aname="l00089"></a>00089 tp-><aclass="code"href="struct_thread.html#a7661cf39bbb29453ce0c48a94708fb69"title="Previous in the queue.">p_prev</a> = cp-><aclass="code"href="struct_thread.html#a7661cf39bbb29453ce0c48a94708fb69"title="Previous in the queue.">p_prev</a>;
<aname="l00090"></a>00090 tp-><aclass="code"href="struct_thread.html#a7661cf39bbb29453ce0c48a94708fb69"title="Previous in the queue.">p_prev</a>-><aclass="code"href="struct_thread.html#a49d3270919a6e423a47de20bc57beaa1"title="Next in the list/queue.">p_next</a> = cp-><aclass="code"href="struct_thread.html#a7661cf39bbb29453ce0c48a94708fb69"title="Previous in the queue.">p_prev</a> = tp;
<aname="l00103"></a><aclass="code"href="group__scheduler.html#ga97c1c514b755a1e71caf2f19c1ccf986">00103</a><spanclass="preprocessor"></span><spanclass="keywordtype">void</span><aclass="code"href="group__scheduler.html#ga97c1c514b755a1e71caf2f19c1ccf986"title="Puts the current thread to sleep into the specified state.">chSchGoSleepS</a>(<aclass="code"href="group__types.html#ga52d7ed152360a74632afa37bbeeca7ca"title="Thread state, uint8_t is ok.">tstate_t</a> newstate) {
<aname="l00104"></a>00104 <aclass="code"href="struct_thread.html"title="Structure representing a thread.">Thread</a> *otp;
<aname="l00110"></a>00110 <spanclass="preprocessor"></span><aclass="code"href="group__scheduler.html#ga226bd98a30b2db31dbb1ecc572c18da2"title="Current thread pointer change macro.">setcurrp</a>(<aclass="code"href="group__internals.html#ga042479f09357fc59befebf4dfe0e9f4a"title="Removes the first-out Thread from a queue and returns it.">fifo_remove</a>(&rlist.<aclass="code"href="struct_ready_list.html#a7577e36ac8500b0364cd3d4157e260d1"title="Threads queue.">r_queue</a>));
<aname="l00112"></a>00112 <aclass="code"href="group__debug.html#gac7f8f0653faf2e3a93108ff5333821b7"title="Inserts in the circular debug trace buffer a context switch record.">chDbgTrace</a>(otp);
<aname="l00113"></a>00113 <aclass="code"href="group__system.html#ga63044a9140cf65d2272f06e05431e161"title="Performs a context switch.">chSysSwitchI</a>(<aclass="code"href="group__scheduler.html#ga1a5fddde56420e8accd0c09c1abb32a7"title="Current thread pointer access macro.">currp</a>, otp);
<aname="l00125"></a>00125 <spanclass="keywordflow">case</span><aclass="code"href="group__threads.html#ga1f7b83c73a5b850a3f33bddbdb024fb3"title="Thread state: Ready to run, waiting on the ready list.">THD_STATE_READY</a>:
<aname="l00126"></a>00126 <spanclass="comment">/* Handling the special case where the thread has been made ready by</span>
<aname="l00127"></a>00127 <spanclass="comment"> another thread with higher priority.*/</span>
<aname="l00131"></a>00131 <spanclass="preprocessor"></span><spanclass="keywordflow">case</span><aclass="code"href="group__threads.html#gad0b81cae859c0a6bc6a0d2036aa8e272"title="Thread state: Waiting on a semaphore.">THD_STATE_WTSEM</a>:
<aname="l00132"></a>00132 <aclass="code"href="group__semaphores.html#gacb89a28bd1fff2704207423f350215ba"title="Increases the semaphore counter.">chSemFastSignalI</a>((<aclass="code"href="struct_semaphore.html"title="Semaphore structure.">Semaphore</a> *)tp-><aclass="code"href="struct_thread.html#a72cd0424b6098ca241fac1f74d21b56a"title="State-specific fields.">p_u</a>.<aclass="code"href="struct_thread.html#a4f016b01444741e6f9b420436b748862"title="Pointer to a generic &quot;wait&quot; object.">wtobjp</a>);
<aname="l00138"></a>00138 <spanclass="preprocessor"></span><spanclass="comment">/* States requiring dequeuing.*/</span>
<aname="l00139"></a>00139 <aclass="code"href="group__internals.html#gafff11bcd31d7dc3d1a0a6c66f3fc6ec9"title="Removes a Thread from a queue and returns it.">dequeue</a>(tp);
<aname="l00143"></a>00143 <aclass="code"href="group__scheduler.html#ga535d58cfb3436c8d4e4586c31c062298"title="Inserts a thread in the Ready List.">chSchReadyI</a>(tp);
<aname="l00167"></a><aclass="code"href="group__scheduler.html#ga306e564f678c1a39139639490c77e78b">00167</a><aclass="code"href="group__types.html#ga35bcb0c321cd7bc45bf1a11fa17ebdd3"title="Message, use signed pointer equivalent.">msg_t</a><aclass="code"href="group__scheduler.html#ga306e564f678c1a39139639490c77e78b"title="Puts the current thread to sleep into the specified state with timeout specification.">chSchGoSleepTimeoutS</a>(<aclass="code"href="group__types.html#ga52d7ed152360a74632afa37bbeeca7ca"title="Thread state, uint8_t is ok.">tstate_t</a> newstate, <aclass="code"href="group__types.html#gae3e32a98d431a02106616da3071832dd"title="System Time, recommended fastest unsigned.">systime_t</a> time) {
<aname="l00168"></a>00168
<aname="l00169"></a>00169 <spanclass="keywordflow">if</span> (<aclass="code"href="group__scheduler.html#gae1568cf3090c973c3bc47f86ae2f5afb"title="Infinite time specification for all the syscalls with a timeout specification.">TIME_INFINITE</a> != time) {
<aname="l00172"></a>00172 <aclass="code"href="group__time.html#ga1c44c3a0bc64b2954d95cd98b2e7124e"title="Enables a virtual timer.">chVTSetI</a>(&vt, time, wakeup, <aclass="code"href="group__scheduler.html#ga1a5fddde56420e8accd0c09c1abb32a7"title="Current thread pointer access macro.">currp</a>);
<aname="l00173"></a>00173 <aclass="code"href="group__scheduler.html#ga97c1c514b755a1e71caf2f19c1ccf986"title="Puts the current thread to sleep into the specified state.">chSchGoSleepS</a>(newstate);
<aname="l00174"></a>00174 <spanclass="keywordflow">if</span> (<aclass="code"href="group__time.html#gae54e6dd40bc7b9cdeb409393ec9e134a"title="Returns TRUE if the speciified timer is armed.">chVTIsArmedI</a>(&vt))
<aname="l00175"></a>00175 <aclass="code"href="group__time.html#ga680d851a74e594cc965101e79891840f"title="Disables a Virtual Timer.">chVTResetI</a>(&vt);
<aname="l00178"></a>00178 <aclass="code"href="group__scheduler.html#ga97c1c514b755a1e71caf2f19c1ccf986"title="Puts the current thread to sleep into the specified state.">chSchGoSleepS</a>(newstate);
<aname="l00197"></a><aclass="code"href="group__scheduler.html#gae47a8819a21ef2d521124e76bfb37c95">00197</a><spanclass="preprocessor"></span><spanclass="keywordtype">void</span><aclass="code"href="group__scheduler.html#gae47a8819a21ef2d521124e76bfb37c95"title="Wakes up a thread.">chSchWakeupS</a>(<aclass="code"href="struct_thread.html"title="Structure representing a thread.">Thread</a> *ntp, <aclass="code"href="group__types.html#ga35bcb0c321cd7bc45bf1a11fa17ebdd3"title="Message, use signed pointer equivalent.">msg_t</a> msg) {
<aname="l00205"></a>00205 <aclass="code"href="group__scheduler.html#ga535d58cfb3436c8d4e4586c31c062298"title="Inserts a thread in the Ready List.">chSchReadyI</a>(ntp);
<aname="l00207"></a>00207 <aclass="code"href="struct_thread.html"title="Structure representing a thread.">Thread</a> *otp = <aclass="code"href="group__scheduler.html#ga535d58cfb3436c8d4e4586c31c062298"title="Inserts a thread in the Ready List.">chSchReadyI</a>(<aclass="code"href="group__scheduler.html#ga1a5fddde56420e8accd0c09c1abb32a7"title="Current thread pointer access macro.">currp</a>);
<aname="l00213"></a>00213 <aclass="code"href="group__debug.html#gac7f8f0653faf2e3a93108ff5333821b7"title="Inserts in the circular debug trace buffer a context switch record.">chDbgTrace</a>(otp);
<aname="l00214"></a>00214 <aclass="code"href="group__system.html#ga63044a9140cf65d2272f06e05431e161"title="Performs a context switch.">chSysSwitchI</a>(ntp, otp);
<aname="l00225"></a><aclass="code"href="group__scheduler.html#ga0257cf203e72a766a52059750cb97e6e">00225</a><spanclass="preprocessor"></span><spanclass="keywordtype">void</span><aclass="code"href="group__scheduler.html#ga0257cf203e72a766a52059750cb97e6e"title="Switches to the first thread on the runnable queue.">chSchDoRescheduleI</a>(<spanclass="keywordtype">void</span>) {
<aname="l00226"></a>00226 <aclass="code"href="struct_thread.html"title="Structure representing a thread.">Thread</a> *otp;
<aname="l00232"></a>00232 <spanclass="comment">/* Picks the first thread from the ready queue and makes it current.*/</span>
<aname="l00233"></a>00233 <aclass="code"href="group__scheduler.html#ga226bd98a30b2db31dbb1ecc572c18da2"title="Current thread pointer change macro.">setcurrp</a>(<aclass="code"href="group__internals.html#ga042479f09357fc59befebf4dfe0e9f4a"title="Removes the first-out Thread from a queue and returns it.">fifo_remove</a>(&rlist.<aclass="code"href="struct_ready_list.html#a7577e36ac8500b0364cd3d4157e260d1"title="Threads queue.">r_queue</a>));
<aname="l00235"></a>00235 <aclass="code"href="group__scheduler.html#ga535d58cfb3436c8d4e4586c31c062298"title="Inserts a thread in the Ready List.">chSchReadyI</a>(otp);
<aname="l00236"></a>00236 <aclass="code"href="group__debug.html#gac7f8f0653faf2e3a93108ff5333821b7"title="Inserts in the circular debug trace buffer a context switch record.">chDbgTrace</a>(otp);
<aname="l00237"></a>00237 <aclass="code"href="group__system.html#ga63044a9140cf65d2272f06e05431e161"title="Performs a context switch.">chSysSwitchI</a>(<aclass="code"href="group__scheduler.html#ga1a5fddde56420e8accd0c09c1abb32a7"title="Current thread pointer access macro.">currp</a>, otp);
<aname="l00247"></a><aclass="code"href="group__scheduler.html#ga4e38b4bee3d2330f6a0f1cdb7660af20">00247</a><spanclass="preprocessor"></span><spanclass="keywordtype">void</span><aclass="code"href="group__scheduler.html#ga4e38b4bee3d2330f6a0f1cdb7660af20"title="Performs a reschedule if a higher priority thread is runnable.">chSchRescheduleS</a>(<spanclass="keywordtype">void</span>) {
<aname="l00248"></a>00248
<aname="l00249"></a>00249 <spanclass="keywordflow">if</span> (<aclass="code"href="group__scheduler.html#ga146230c1fe7e6dab4bc6649f2a71444c"title="Determines if the current thread must reschedule.">chSchIsRescRequiredI</a>())
<aname="l00250"></a>00250 <aclass="code"href="group__scheduler.html#ga0257cf203e72a766a52059750cb97e6e"title="Switches to the first thread on the runnable queue.">chSchDoRescheduleI</a>();
<aname="l00265"></a><aclass="code"href="group__scheduler.html#ga5fa012ef9d1e920983fe2aea2695a52a">00265</a><spanclass="preprocessor"></span><aclass="code"href="group__types.html#ga7556af1cb61728b53228fa3af1c851de"title="Boolean, recommended the fastest signed.">bool_t</a><aclass="code"href="group__scheduler.html#ga5fa012ef9d1e920983fe2aea2695a52a"title="Evaluates if a reschedule is required.">chSchIsRescRequiredExI</a>(<spanclass="keywordtype">void</span>) {
<aname="l00266"></a>00266 <aclass="code"href="group__types.html#ga5f2488ba73e5969cbc0f7033735374ee"title="Priority, use the fastest unsigned type.">tprio_t</a> p1 = <aclass="code"href="group__scheduler.html#gaa3e744fe83212f48d7373b764b9abb2d"title="Returns the priority of the first thread on the given ready list.">firstprio</a>(&rlist.<aclass="code"href="struct_ready_list.html#a7577e36ac8500b0364cd3d4157e260d1"title="Threads queue.">r_queue</a>);
<aname="l00267"></a>00267 <aclass="code"href="group__types.html#ga5f2488ba73e5969cbc0f7033735374ee"title="Priority, use the fastest unsigned type.">tprio_t</a> p2 = <aclass="code"href="group__scheduler.html#ga1a5fddde56420e8accd0c09c1abb32a7"title="Current thread pointer access macro.">currp</a>->p_prio;
<aname="l00269"></a>00269 <spanclass="preprocessor"></span><spanclass="comment">/* If the running thread has not reached its time quantum, reschedule only</span>
<aname="l00270"></a>00270 <spanclass="comment"> if the first thread on the ready queue has a higher priority.</span>
<aname="l00271"></a>00271 <spanclass="comment"> Otherwise, if the running thread has used up its time quantum, reschedule</span>
<aname="l00272"></a>00272 <spanclass="comment"> if the first thread on the ready queue has equal or higher priority.*/</span>
<aname="l00275"></a>00275 <spanclass="preprocessor"></span><spanclass="comment">/* If the round robin preemption feature is not enabled then performs a</span>
Generated on Sun Oct 24 2010 09:40:37 for ChibiOS/RT by <ahref="http://www.doxygen.org/index.html"><imgsrc="doxygen.png"alt="doxygen"align="middle"border="0"></a> 1.7.1</small></address>