<ahref="chsem_8c.html">Go to the documentation of this file.</a><divclass="fragment"><preclass="fragment"><aname="l00001"></a>00001 <spanclass="comment">/*</span>
<aname="l00066"></a>00066 <spanclass="preprocessor">#include "<aclass="code"href="ch_8h.html"title="ChibiOS/RT main include file.">ch.h</a>"</span>
<aname="l00087"></a>00087 <aclass="code"href="group__internals.html#ga6d19d0f3ff1fa599b6d9783dec180451"title="Threads queue initialization.">queue_init</a>(&sp-><aclass="code"href="struct_semaphore.html#a26051a38c22dc11a7a2bf37496d8e906"title="Queue of the threads sleeping on this semaphore.">s_queue</a>);
<aname="l00101"></a><aclass="code"href="group__semaphores.html#ga58e266e609cfd3dbc67f299b3ae9debb">00101</a><spanclass="keywordtype">void</span><aclass="code"href="group__semaphores.html#ga58e266e609cfd3dbc67f299b3ae9debb"title="Performs a reset operation on the semaphore.">chSemReset</a>(<aclass="code"href="struct_semaphore.html"title="Semaphore structure.">Semaphore</a> *sp, <aclass="code"href="group__types.html#ga090b3bab5602157ebf706a44041dc05e"title="Counter, recommended fastest signed.">cnt_t</a> n) {
<aname="l00102"></a>00102
<aname="l00103"></a>00103 <aclass="code"href="group__system.html#ga9f6573c0763d1e4e97c63c62edad6e42"title="Enters the kernel lock mode.">chSysLock</a>();
<aname="l00104"></a>00104 <aclass="code"href="group__semaphores.html#gae7972b6b22b80ac09bac5a186277ab81"title="Performs a reset operation on the semaphore.">chSemResetI</a>(sp, n);
<aname="l00105"></a>00105 <aclass="code"href="group__scheduler.html#ga4e38b4bee3d2330f6a0f1cdb7660af20"title="Performs a reschedule if a higher priority thread is runnable.">chSchRescheduleS</a>();
<aname="l00106"></a>00106 <aclass="code"href="group__system.html#ga5a257fa58a09815eb64a45e2dfbdc22e"title="Leaves the kernel lock mode.">chSysUnlock</a>();
<aname="l00120"></a><aclass="code"href="group__semaphores.html#gae7972b6b22b80ac09bac5a186277ab81">00120</a><spanclass="keywordtype">void</span><aclass="code"href="group__semaphores.html#gae7972b6b22b80ac09bac5a186277ab81"title="Performs a reset operation on the semaphore.">chSemResetI</a>(<aclass="code"href="struct_semaphore.html"title="Semaphore structure.">Semaphore</a> *sp, <aclass="code"href="group__types.html#ga090b3bab5602157ebf706a44041dc05e"title="Counter, recommended fastest signed.">cnt_t</a> n) {
<aname="l00128"></a>00128 <aclass="code"href="group__scheduler.html#ga535d58cfb3436c8d4e4586c31c062298"title="Inserts a thread in the Ready List.">chSchReadyI</a>(<aclass="code"href="group__internals.html#gacacfe77140cab62948e63d898bf4dfba"title="Removes the last-out Thread from a queue and returns it.">lifo_remove</a>(&sp-><aclass="code"href="struct_semaphore.html#a26051a38c22dc11a7a2bf37496d8e906"title="Queue of the threads sleeping on this semaphore.">s_queue</a>))-><aclass="code"href="struct_thread.html#a72cd0424b6098ca241fac1f74d21b56a"title="State-specific fields.">p_u</a>.<aclass="code"href="struct_thread.html#ad5792c30fbd60df0de223b0f398fc6d7"title="Thread wakeup code.">rdymsg</a> = RDY_RESET;
<aname="l00138"></a><aclass="code"href="group__semaphores.html#gabc8f7e509870e9b0527a6a68fad71425">00138</a><aclass="code"href="group__types.html#ga35bcb0c321cd7bc45bf1a11fa17ebdd3"title="Message, use signed pointer equivalent.">msg_t</a><aclass="code"href="group__semaphores.html#gabc8f7e509870e9b0527a6a68fad71425"title="Performs a wait operation on a semaphore.">chSemWait</a>(<aclass="code"href="struct_semaphore.html"title="Semaphore structure.">Semaphore</a> *sp) {
<aname="l00139"></a>00139 <aclass="code"href="group__types.html#ga35bcb0c321cd7bc45bf1a11fa17ebdd3"title="Message, use signed pointer equivalent.">msg_t</a> msg;
<aname="l00140"></a>00140
<aname="l00141"></a>00141 <aclass="code"href="group__system.html#ga9f6573c0763d1e4e97c63c62edad6e42"title="Enters the kernel lock mode.">chSysLock</a>();
<aname="l00142"></a>00142 msg = <aclass="code"href="group__semaphores.html#gaa2c0367078533e291d2e889e251d8b67"title="Performs a wait operation on a semaphore.">chSemWaitS</a>(sp);
<aname="l00143"></a>00143 <aclass="code"href="group__system.html#ga5a257fa58a09815eb64a45e2dfbdc22e"title="Leaves the kernel lock mode.">chSysUnlock</a>();
<aname="l00154"></a><aclass="code"href="group__semaphores.html#gaa2c0367078533e291d2e889e251d8b67">00154</a><aclass="code"href="group__types.html#ga35bcb0c321cd7bc45bf1a11fa17ebdd3"title="Message, use signed pointer equivalent.">msg_t</a><aclass="code"href="group__semaphores.html#gaa2c0367078533e291d2e889e251d8b67"title="Performs a wait operation on a semaphore.">chSemWaitS</a>(<aclass="code"href="struct_semaphore.html"title="Semaphore structure.">Semaphore</a> *sp) {
<aname="l00160"></a>00160 sem_insert(<aclass="code"href="group__scheduler.html#ga1a5fddde56420e8accd0c09c1abb32a7"title="Current thread pointer access macro.">currp</a>, &sp-><aclass="code"href="struct_semaphore.html#a26051a38c22dc11a7a2bf37496d8e906"title="Queue of the threads sleeping on this semaphore.">s_queue</a>);
<aname="l00161"></a>00161 <aclass="code"href="group__scheduler.html#ga97c1c514b755a1e71caf2f19c1ccf986"title="Puts the current thread to sleep into the specified state.">chSchGoSleepS</a>(<aclass="code"href="group__threads.html#gad0b81cae859c0a6bc6a0d2036aa8e272"title="Thread state: Waiting on a semaphore.">THD_STATE_WTSEM</a>);
<aname="l00181"></a><aclass="code"href="group__semaphores.html#ga0bc227311e5be3e3b6e3aee6a68169da">00181</a><aclass="code"href="group__types.html#ga35bcb0c321cd7bc45bf1a11fa17ebdd3"title="Message, use signed pointer equivalent.">msg_t</a><aclass="code"href="group__semaphores.html#ga0bc227311e5be3e3b6e3aee6a68169da"title="Performs a wait operation on a semaphore with timeout specification.">chSemWaitTimeout</a>(<aclass="code"href="struct_semaphore.html"title="Semaphore structure.">Semaphore</a> *sp, <aclass="code"href="group__types.html#gae3e32a98d431a02106616da3071832dd"title="System Time, recommended fastest unsigned.">systime_t</a> time) {
<aname="l00182"></a>00182 <aclass="code"href="group__types.html#ga35bcb0c321cd7bc45bf1a11fa17ebdd3"title="Message, use signed pointer equivalent.">msg_t</a> msg;
<aname="l00183"></a>00183
<aname="l00184"></a>00184 <aclass="code"href="group__system.html#ga9f6573c0763d1e4e97c63c62edad6e42"title="Enters the kernel lock mode.">chSysLock</a>();
<aname="l00185"></a>00185 msg = <aclass="code"href="group__semaphores.html#ga924ec5d191bb8debe8727ae4dd5d6d03"title="Performs a wait operation on a semaphore with timeout specification.">chSemWaitTimeoutS</a>(sp, time);
<aname="l00186"></a>00186 <aclass="code"href="group__system.html#ga5a257fa58a09815eb64a45e2dfbdc22e"title="Leaves the kernel lock mode.">chSysUnlock</a>();
<aname="l00204"></a><aclass="code"href="group__semaphores.html#ga924ec5d191bb8debe8727ae4dd5d6d03">00204</a><aclass="code"href="group__types.html#ga35bcb0c321cd7bc45bf1a11fa17ebdd3"title="Message, use signed pointer equivalent.">msg_t</a><aclass="code"href="group__semaphores.html#ga924ec5d191bb8debe8727ae4dd5d6d03"title="Performs a wait operation on a semaphore with timeout specification.">chSemWaitTimeoutS</a>(<aclass="code"href="struct_semaphore.html"title="Semaphore structure.">Semaphore</a> *sp, <aclass="code"href="group__types.html#gae3e32a98d431a02106616da3071832dd"title="System Time, recommended fastest unsigned.">systime_t</a> time) {
<aname="l00209"></a>00209 <spanclass="keywordflow">if</span> (<aclass="code"href="group__scheduler.html#gad1ac15e9e5fc17810a94a779257f3d29"title="Zero time specification for some syscalls with a timeout specification.">TIME_IMMEDIATE</a> == time) {
<aname="l00214"></a>00214 sem_insert(<aclass="code"href="group__scheduler.html#ga1a5fddde56420e8accd0c09c1abb32a7"title="Current thread pointer access macro.">currp</a>, &sp-><aclass="code"href="struct_semaphore.html#a26051a38c22dc11a7a2bf37496d8e906"title="Queue of the threads sleeping on this semaphore.">s_queue</a>);
<aname="l00215"></a>00215 <spanclass="keywordflow">return</span><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__threads.html#gad0b81cae859c0a6bc6a0d2036aa8e272"title="Thread state: Waiting on a semaphore.">THD_STATE_WTSEM</a>, time);
<aname="l00225"></a><aclass="code"href="group__semaphores.html#ga7ec0cbda23e49e2370e0b91f20baf05e">00225</a><spanclass="keywordtype">void</span><aclass="code"href="group__semaphores.html#ga7ec0cbda23e49e2370e0b91f20baf05e"title="Performs a signal operation on a semaphore.">chSemSignal</a>(<aclass="code"href="struct_semaphore.html"title="Semaphore structure.">Semaphore</a> *sp) {
<aname="l00231"></a>00231 <aclass="code"href="group__scheduler.html#gae47a8819a21ef2d521124e76bfb37c95"title="Wakes up a thread.">chSchWakeupS</a>(<aclass="code"href="group__internals.html#ga042479f09357fc59befebf4dfe0e9f4a"title="Removes the first-out Thread from a queue and returns it.">fifo_remove</a>(&sp-><aclass="code"href="struct_semaphore.html#a26051a38c22dc11a7a2bf37496d8e906"title="Queue of the threads sleeping on this semaphore.">s_queue</a>), <aclass="code"href="group__scheduler.html#gae1c86078318e11c2fa57ee3c2ec69f61"title="Default thread wakeup low level message.">RDY_OK</a>);
<aname="l00232"></a>00232 <aclass="code"href="group__system.html#ga5a257fa58a09815eb64a45e2dfbdc22e"title="Leaves the kernel lock mode.">chSysUnlock</a>();
<aname="l00241"></a><aclass="code"href="group__semaphores.html#gaca0b70cf495a9cb7569e1cf5b07e2b3d">00241</a><spanclass="keywordtype">void</span><aclass="code"href="group__semaphores.html#gaca0b70cf495a9cb7569e1cf5b07e2b3d"title="Performs a signal operation on a semaphore.">chSemSignalI</a>(<aclass="code"href="struct_semaphore.html"title="Semaphore structure.">Semaphore</a> *sp) {
<aname="l00248"></a>00248 <aclass="code"href="struct_thread.html"title="Structure representing a thread.">Thread</a> *tp = <aclass="code"href="group__internals.html#ga042479f09357fc59befebf4dfe0e9f4a"title="Removes the first-out Thread from a queue and returns it.">fifo_remove</a>(&sp-><aclass="code"href="struct_semaphore.html#a26051a38c22dc11a7a2bf37496d8e906"title="Queue of the threads sleeping on this semaphore.">s_queue</a>);
<aname="l00250"></a>00250 <aclass="code"href="group__scheduler.html#ga535d58cfb3436c8d4e4586c31c062298"title="Inserts a thread in the Ready List.">chSchReadyI</a>(tp);
<aname="l00265"></a><aclass="code"href="group__semaphores.html#ga0dc7b4339506de346d67b4560b271e44">00265</a><aclass="code"href="group__types.html#ga35bcb0c321cd7bc45bf1a11fa17ebdd3"title="Message, use signed pointer equivalent.">msg_t</a><aclass="code"href="group__semaphores.html#ga0dc7b4339506de346d67b4560b271e44"title="Performs atomic signal and wait operations on two semaphores.">chSemSignalWait</a>(<aclass="code"href="struct_semaphore.html"title="Semaphore structure.">Semaphore</a> *sps, <aclass="code"href="struct_semaphore.html"title="Semaphore structure.">Semaphore</a> *spw) {
<aname="l00266"></a>00266 <aclass="code"href="group__types.html#ga35bcb0c321cd7bc45bf1a11fa17ebdd3"title="Message, use signed pointer equivalent.">msg_t</a> msg;
<aname="l00272"></a>00272 <aclass="code"href="group__scheduler.html#ga535d58cfb3436c8d4e4586c31c062298"title="Inserts a thread in the Ready List.">chSchReadyI</a>(<aclass="code"href="group__internals.html#ga042479f09357fc59befebf4dfe0e9f4a"title="Removes the first-out Thread from a queue and returns it.">fifo_remove</a>(&sps-><aclass="code"href="struct_semaphore.html#a26051a38c22dc11a7a2bf37496d8e906"title="Queue of the threads sleeping on this semaphore.">s_queue</a>))-><aclass="code"href="struct_thread.html#a72cd0424b6098ca241fac1f74d21b56a"title="State-specific fields.">p_u</a>.<aclass="code"href="struct_thread.html#ad5792c30fbd60df0de223b0f398fc6d7"title="Thread wakeup code.">rdymsg</a> = RDY_OK;
<aname="l00275"></a>00275 sem_insert(ctp, &spw-><aclass="code"href="struct_semaphore.html#a26051a38c22dc11a7a2bf37496d8e906"title="Queue of the threads sleeping on this semaphore.">s_queue</a>);
<aname="l00276"></a>00276 ctp-><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> = spw;
<aname="l00277"></a>00277 <aclass="code"href="group__scheduler.html#ga97c1c514b755a1e71caf2f19c1ccf986"title="Puts the current thread to sleep into the specified state.">chSchGoSleepS</a>(<aclass="code"href="group__threads.html#gad0b81cae859c0a6bc6a0d2036aa8e272"title="Thread state: Waiting on a semaphore.">THD_STATE_WTSEM</a>);
<aname="l00281"></a>00281 <aclass="code"href="group__scheduler.html#ga4e38b4bee3d2330f6a0f1cdb7660af20"title="Performs a reschedule if a higher priority thread is runnable.">chSchRescheduleS</a>();
Generated on Sun Nov 28 2010 14:09:48 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>