<ahref="chthreads_8c.html">Go to the documentation of this file.</a><divclass="fragment"><preclass="fragment"><aname="l00001"></a>00001 <spanclass="comment">/*</span>
<aname="l00065"></a>00065 <spanclass="preprocessor">#include "<aclass="code"href="ch_8h.html"title="ChibiOS/RT main include file.">ch.h</a>"</span>
<aname="l00074"></a><aclass="code"href="group__threads.html#ga4f6ae58bb3cedfc03aacde6d49e49d35">00074</a><aclass="code"href="struct_thread.html"title="Structure representing a thread.">Thread</a> *<aclass="code"href="group__threads.html#ga4f6ae58bb3cedfc03aacde6d49e49d35"title="Initializes a thread structure.">init_thread</a>(<aclass="code"href="struct_thread.html"title="Structure representing a thread.">Thread</a> *tp, <aclass="code"href="group__types.html#ga5f2488ba73e5969cbc0f7033735374ee"title="Priority, use the fastest unsigned type.">tprio_t</a> prio) {
<aname="l00081"></a>00081 tp-><aclass="code"href="struct_thread.html#a3ae80b4b3de4c7a23c542ca251e1f017"title="List of the mutexes owned by this thread.">p_mtxlist</a> = NULL;
<aname="l00090"></a>00090 <spanclass="preprocessor"></span> tp-><aclass="code"href="struct_thread.html#a723aab9bf515e789c3d9ea81f9dbd6a0"title="Thread consumed time in ticks.">p_time</a> = 0;
<aname="l00093"></a>00093 <spanclass="preprocessor"></span> tp-><aclass="code"href="struct_thread.html#af86d1da435197d113bc42fe8139a21c5"title="References to this thread.">p_refs</a> = 1;
<aname="l00102"></a>00102 <spanclass="preprocessor"></span><aclass="code"href="group__registry.html#ga365d4805b1329b068d9211b680f43388"title="Adds a thread to the registry list.">REG_INSERT</a>(tp);
<aname="l00137"></a><aclass="code"href="group__threads.html#gac6de13d4044b32d3ae9e2066b5d4c030">00137</a><aclass="code"href="struct_thread.html"title="Structure representing a thread.">Thread</a> *<aclass="code"href="group__threads.html#gac6de13d4044b32d3ae9e2066b5d4c030"title="Creates a new thread into a static memory area.">chThdCreateI</a>(<spanclass="keywordtype">void</span> *wsp, <spanclass="keywordtype">size_t</span> size,
<aname="l00138"></a>00138 <aclass="code"href="group__types.html#ga5f2488ba73e5969cbc0f7033735374ee"title="Priority, use the fastest unsigned type.">tprio_t</a> prio, <aclass="code"href="group__threads.html#gabfe59aa7d2ed1b8e57a2ce17bcbc1189"title="Thread function.">tfunc_t</a> pf, <spanclass="keywordtype">void</span> *arg) {
<aname="l00139"></a>00139 <spanclass="comment">/* Thread structure is layed out in the lower part of the thread workspace */</span>
<aname="l00140"></a>00140 <aclass="code"href="struct_thread.html"title="Structure representing a thread.">Thread</a> *tp = wsp;
<aname="l00141"></a>00141
<aname="l00142"></a>00142 <aclass="code"href="group__debug.html#ga6bb6c0f97caab3a66332c8bfbf7a3844"title="Function parameter check.">chDbgCheck</a>((wsp != NULL) && (size >= <aclass="code"href="group__core.html#gaf7a83c1c8bde96b77299c36dc598d33d"title="Computes the thread working area global size.">THD_WA_SIZE</a>(0)) &&
<aname="l00143"></a>00143 (prio <= <aclass="code"href="group__scheduler.html#ga0621c307e30868052b802fbc821297e8"title="Highest user priority.">HIGHPRIO</a>) && (pf != NULL),
<aname="l00145"></a>00145 <aclass="code"href="group__core.html#gaf5777aa68e4c4786b577953c7237a95d"title="Platform dependent part of the chThdInit() API.">SETUP_CONTEXT</a>(wsp, size, pf, arg);
<aname="l00146"></a>00146 <spanclass="keywordflow">return</span><aclass="code"href="group__threads.html#ga4f6ae58bb3cedfc03aacde6d49e49d35"title="Initializes a thread structure.">init_thread</a>(tp, prio);
<aname="l00163"></a><aclass="code"href="group__threads.html#ga048e588238dd336c6059133b3d0c3435">00163</a><aclass="code"href="struct_thread.html"title="Structure representing a thread.">Thread</a> *<aclass="code"href="group__threads.html#ga048e588238dd336c6059133b3d0c3435"title="Creates a new thread into a static memory area.">chThdCreateStatic</a>(<spanclass="keywordtype">void</span> *wsp, <spanclass="keywordtype">size_t</span> size,
<aname="l00164"></a>00164 <aclass="code"href="group__types.html#ga5f2488ba73e5969cbc0f7033735374ee"title="Priority, use the fastest unsigned type.">tprio_t</a> prio, <aclass="code"href="group__threads.html#gabfe59aa7d2ed1b8e57a2ce17bcbc1189"title="Thread function.">tfunc_t</a> pf, <spanclass="keywordtype">void</span> *arg) {
<aname="l00165"></a>00165 <aclass="code"href="struct_thread.html"title="Structure representing a thread.">Thread</a> *tp;
<aname="l00168"></a>00168 <spanclass="preprocessor"></span> memfill((<aclass="code"href="group___s_t_m8___c_o_r_e.html#gaba7bc1797add20fe3efdf37ced1182c5">uint8_t</a> *)wsp, (<aclass="code"href="group___s_t_m8___c_o_r_e.html#gaba7bc1797add20fe3efdf37ced1182c5">uint8_t</a> *)wsp + <spanclass="keyword">sizeof</span>(<aclass="code"href="struct_thread.html"title="Structure representing a thread.">Thread</a>), <aclass="code"href="group__debug.html#gad8d58eb160d991692ecc3bd4e04e0cbd"title="Fill value for thread area in debug mode.">THREAD_FILL_VALUE</a>);
<aname="l00169"></a>00169 memfill((<aclass="code"href="group___s_t_m8___c_o_r_e.html#gaba7bc1797add20fe3efdf37ced1182c5">uint8_t</a> *)wsp + <spanclass="keyword">sizeof</span>(<aclass="code"href="struct_thread.html"title="Structure representing a thread.">Thread</a>),
<aname="l00170"></a>00170 (<aclass="code"href="group___s_t_m8___c_o_r_e.html#gaba7bc1797add20fe3efdf37ced1182c5">uint8_t</a> *)wsp + size, <aclass="code"href="group__debug.html#ga1379fe3590594def45a6a6c7a4faa41b"title="Fill value for thread stack area in debug mode.">STACK_FILL_VALUE</a>);
<aname="l00172"></a>00172 <spanclass="preprocessor"></span><aclass="code"href="group__system.html#ga9f6573c0763d1e4e97c63c62edad6e42"title="Enters the kernel lock mode.">chSysLock</a>();
<aname="l00173"></a>00173 <aclass="code"href="group__scheduler.html#gae47a8819a21ef2d521124e76bfb37c95"title="Wakes up a thread.">chSchWakeupS</a>(tp = <aclass="code"href="group__threads.html#gac6de13d4044b32d3ae9e2066b5d4c030"title="Creates a new thread into a static memory area.">chThdCreateI</a>(wsp, size, prio, pf, arg), <aclass="code"href="group__scheduler.html#gae1c86078318e11c2fa57ee3c2ec69f61"title="Default thread wakeup low level message.">RDY_OK</a>);
<aname="l00174"></a>00174 <aclass="code"href="group__system.html#ga5a257fa58a09815eb64a45e2dfbdc22e"title="Leaves the kernel lock mode.">chSysUnlock</a>();
<aname="l00200"></a><aclass="code"href="group__threads.html#ga50b84e3e82a4e09c1066e1d422e4c780">00200</a><aclass="code"href="struct_thread.html"title="Structure representing a thread.">Thread</a> *<aclass="code"href="group__threads.html#ga50b84e3e82a4e09c1066e1d422e4c780"title="Creates a new thread allocating the memory from the heap.">chThdCreateFromHeap</a>(<aclass="code"href="structmemory__heap.html"title="Structure describing a memory heap.">MemoryHeap</a> *heapp, <spanclass="keywordtype">size_t</span> size,
<aname="l00201"></a>00201 <aclass="code"href="group__types.html#ga5f2488ba73e5969cbc0f7033735374ee"title="Priority, use the fastest unsigned type.">tprio_t</a> prio, <aclass="code"href="group__threads.html#gabfe59aa7d2ed1b8e57a2ce17bcbc1189"title="Thread function.">tfunc_t</a> pf, <spanclass="keywordtype">void</span> *arg) {
<aname="l00203"></a>00203 <aclass="code"href="struct_thread.html"title="Structure representing a thread.">Thread</a> *tp;
<aname="l00204"></a>00204
<aname="l00205"></a>00205 wsp = <aclass="code"href="group__heaps.html#ga3d364eec0bef8b1986f63b3288ebbd5f"title="Allocates a block of memory from the heap by using the first-fit algorithm.">chHeapAlloc</a>(heapp, size);
<aname="l00210"></a>00210 <spanclass="preprocessor"></span> memfill((<aclass="code"href="group___s_t_m8___c_o_r_e.html#gaba7bc1797add20fe3efdf37ced1182c5">uint8_t</a> *)wsp, (<aclass="code"href="group___s_t_m8___c_o_r_e.html#gaba7bc1797add20fe3efdf37ced1182c5">uint8_t</a> *)wsp + <spanclass="keyword">sizeof</span>(<aclass="code"href="struct_thread.html"title="Structure representing a thread.">Thread</a>), <aclass="code"href="group__debug.html#gad8d58eb160d991692ecc3bd4e04e0cbd"title="Fill value for thread area in debug mode.">THREAD_FILL_VALUE</a>);
<aname="l00211"></a>00211 memfill((<aclass="code"href="group___s_t_m8___c_o_r_e.html#gaba7bc1797add20fe3efdf37ced1182c5">uint8_t</a> *)wsp + <spanclass="keyword">sizeof</span>(<aclass="code"href="struct_thread.html"title="Structure representing a thread.">Thread</a>),
<aname="l00212"></a>00212 (<aclass="code"href="group___s_t_m8___c_o_r_e.html#gaba7bc1797add20fe3efdf37ced1182c5">uint8_t</a> *)wsp + size, <aclass="code"href="group__debug.html#ga1379fe3590594def45a6a6c7a4faa41b"title="Fill value for thread stack area in debug mode.">STACK_FILL_VALUE</a>);
<aname="l00215"></a>00215 <aclass="code"href="group__system.html#ga9f6573c0763d1e4e97c63c62edad6e42"title="Enters the kernel lock mode.">chSysLock</a>();
<aname="l00216"></a>00216 tp = <aclass="code"href="group__threads.html#gac6de13d4044b32d3ae9e2066b5d4c030"title="Creates a new thread into a static memory area.">chThdCreateI</a>(wsp, size, prio, pf, arg);
<aname="l00245"></a><aclass="code"href="group__threads.html#gad3ccc1a6f054c543258ed2fe97ed2f58">00245</a><aclass="code"href="struct_thread.html"title="Structure representing a thread.">Thread</a> *<aclass="code"href="group__threads.html#gad3ccc1a6f054c543258ed2fe97ed2f58"title="Creates a new thread allocating the memory from the specified memory pool.">chThdCreateFromMemoryPool</a>(<aclass="code"href="struct_memory_pool.html"title="Memory pool descriptor.">MemoryPool</a> *mp, <aclass="code"href="group__types.html#ga5f2488ba73e5969cbc0f7033735374ee"title="Priority, use the fastest unsigned type.">tprio_t</a> prio,
<aname="l00252"></a>00252 wsp = <aclass="code"href="group__pools.html#gab86190d70893fe708c75570af6720bd5"title="Allocates an object from a memory pool.">chPoolAlloc</a>(mp);
<aname="l00257"></a>00257 <spanclass="preprocessor"></span> memfill((<aclass="code"href="group___s_t_m8___c_o_r_e.html#gaba7bc1797add20fe3efdf37ced1182c5">uint8_t</a> *)wsp, (<aclass="code"href="group___s_t_m8___c_o_r_e.html#gaba7bc1797add20fe3efdf37ced1182c5">uint8_t</a> *)wsp + <spanclass="keyword">sizeof</span>(<aclass="code"href="struct_thread.html"title="Structure representing a thread.">Thread</a>), <aclass="code"href="group__debug.html#gad8d58eb160d991692ecc3bd4e04e0cbd"title="Fill value for thread area in debug mode.">THREAD_FILL_VALUE</a>);
<aname="l00258"></a>00258 memfill((<aclass="code"href="group___s_t_m8___c_o_r_e.html#gaba7bc1797add20fe3efdf37ced1182c5">uint8_t</a> *)wsp + <spanclass="keyword">sizeof</span>(<aclass="code"href="struct_thread.html"title="Structure representing a thread.">Thread</a>),
<aname="l00259"></a>00259 (<aclass="code"href="group___s_t_m8___c_o_r_e.html#gaba7bc1797add20fe3efdf37ced1182c5">uint8_t</a> *)wsp + mp-><aclass="code"href="struct_memory_pool.html#a962ca1e05036d54213b3a0eeaebb0ec6"title="Memory pool objects size.">mp_object_size</a>, <aclass="code"href="group__debug.html#ga1379fe3590594def45a6a6c7a4faa41b"title="Fill value for thread stack area in debug mode.">STACK_FILL_VALUE</a>);
<aname="l00262"></a>00262 <aclass="code"href="group__system.html#ga9f6573c0763d1e4e97c63c62edad6e42"title="Enters the kernel lock mode.">chSysLock</a>();
<aname="l00263"></a>00263 tp = <aclass="code"href="group__threads.html#gac6de13d4044b32d3ae9e2066b5d4c030"title="Creates a new thread into a static memory area.">chThdCreateI</a>(wsp, mp-><aclass="code"href="struct_memory_pool.html#a962ca1e05036d54213b3a0eeaebb0ec6"title="Memory pool objects size.">mp_object_size</a>, prio, pf, arg);
<aname="l00265"></a>00265 tp-><aclass="code"href="struct_thread.html#ae0e65912a0c02df5477a3a524cd41d97"title="Memory Pool where the thread workspace is returned.">p_mpool</a> = mp;
<aname="l00266"></a>00266 <aclass="code"href="group__scheduler.html#gae47a8819a21ef2d521124e76bfb37c95"title="Wakes up a thread.">chSchWakeupS</a>(tp, <aclass="code"href="group__scheduler.html#gae1c86078318e11c2fa57ee3c2ec69f61"title="Default thread wakeup low level message.">RDY_OK</a>);
<aname="l00267"></a>00267 <aclass="code"href="group__system.html#ga5a257fa58a09815eb64a45e2dfbdc22e"title="Leaves the kernel lock mode.">chSysUnlock</a>();
<aname="l00282"></a><aclass="code"href="group__threads.html#ga5a5d9388c64e4c1a3aec129d2831eefe">00282</a><aclass="code"href="group__types.html#ga5f2488ba73e5969cbc0f7033735374ee"title="Priority, use the fastest unsigned type.">tprio_t</a><aclass="code"href="group__threads.html#ga5a5d9388c64e4c1a3aec129d2831eefe"title="Changes the running thread priority level then reschedules if necessary.">chThdSetPriority</a>(<aclass="code"href="group__types.html#ga5f2488ba73e5969cbc0f7033735374ee"title="Priority, use the fastest unsigned type.">tprio_t</a> newprio) {
<aname="l00283"></a>00283 <aclass="code"href="group__types.html#ga5f2488ba73e5969cbc0f7033735374ee"title="Priority, use the fastest unsigned type.">tprio_t</a> oldprio;
<aname="l00298"></a>00298 <spanclass="preprocessor"></span><aclass="code"href="group__scheduler.html#ga4e38b4bee3d2330f6a0f1cdb7660af20"title="Performs a reschedule if a higher priority thread is runnable.">chSchRescheduleS</a>();
<aname="l00299"></a>00299 <aclass="code"href="group__system.html#ga5a257fa58a09815eb64a45e2dfbdc22e"title="Leaves the kernel lock mode.">chSysUnlock</a>();
<aname="l00310"></a><aclass="code"href="group__threads.html#ga2c1ce2be73cd177af7e577b282232a7d">00310</a><aclass="code"href="struct_thread.html"title="Structure representing a thread.">Thread</a> *<aclass="code"href="group__threads.html#ga2c1ce2be73cd177af7e577b282232a7d"title="Resumes a suspended thread.">chThdResume</a>(<aclass="code"href="struct_thread.html"title="Structure representing a thread.">Thread</a> *tp) {
<aname="l00311"></a>00311
<aname="l00312"></a>00312 <aclass="code"href="group__system.html#ga9f6573c0763d1e4e97c63c62edad6e42"title="Enters the kernel lock mode.">chSysLock</a>();
<aname="l00313"></a>00313 <aclass="code"href="group__debug.html#ga43d50c69eb730d0f024eb832d61f30c9"title="Condition assertion.">chDbgAssert</a>(tp-><aclass="code"href="struct_thread.html#a3c3e9d6abccb62c3a5fab6ef043a391f"title="Current thread state.">p_state</a> == <aclass="code"href="group__threads.html#gace00089d9d68ba83bb866396332c15d8"title="Thread state: Thread created in suspended state.">THD_STATE_SUSPENDED</a>,
<aname="l00329"></a><aclass="code"href="group__threads.html#ga7ea7371fa41598ebd523622587ce3f22">00329</a><spanclass="keywordtype">void</span><aclass="code"href="group__threads.html#ga7ea7371fa41598ebd523622587ce3f22"title="Requests a thread termination.">chThdTerminate</a>(<aclass="code"href="struct_thread.html"title="Structure representing a thread.">Thread</a> *tp) {
<aname="l00330"></a>00330
<aname="l00331"></a>00331 <aclass="code"href="group__system.html#ga9f6573c0763d1e4e97c63c62edad6e42"title="Enters the kernel lock mode.">chSysLock</a>();
<aname="l00348"></a><aclass="code"href="group__threads.html#ga8b10a49e2ec522a5ddecabdc453afcab">00348</a><spanclass="keywordtype">void</span><aclass="code"href="group__threads.html#ga8b10a49e2ec522a5ddecabdc453afcab"title="Suspends the invoking thread for the specified time.">chThdSleep</a>(<aclass="code"href="group__types.html#gae3e32a98d431a02106616da3071832dd"title="System Time, recommended fastest unsigned.">systime_t</a> time) {
<aname="l00349"></a>00349
<aname="l00350"></a>00350 <aclass="code"href="group__debug.html#ga6bb6c0f97caab3a66332c8bfbf7a3844"title="Function parameter check.">chDbgCheck</a>(time != <aclass="code"href="group__scheduler.html#gae1568cf3090c973c3bc47f86ae2f5afb"title="Infinite time specification for all the syscalls with a timeout specification.">TIME_INFINITE</a>, <spanclass="stringliteral">"chThdSleep"</span>);
<aname="l00351"></a>00351
<aname="l00352"></a>00352 <aclass="code"href="group__system.html#ga9f6573c0763d1e4e97c63c62edad6e42"title="Enters the kernel lock mode.">chSysLock</a>();
<aname="l00353"></a>00353 <aclass="code"href="group__threads.html#ga851dc0c4ac72885bf09feebdef4673ac"title="Suspends the invoking thread for the specified time.">chThdSleepS</a>(time);
<aname="l00354"></a>00354 <aclass="code"href="group__system.html#ga5a257fa58a09815eb64a45e2dfbdc22e"title="Leaves the kernel lock mode.">chSysUnlock</a>();
<aname="l00363"></a><aclass="code"href="group__threads.html#ga9e6e2f8d46d415e8f0862daf0be1d984">00363</a><spanclass="keywordtype">void</span><aclass="code"href="group__threads.html#ga9e6e2f8d46d415e8f0862daf0be1d984"title="Suspends the invoking thread until the system time arrives to the specified value.">chThdSleepUntil</a>(<aclass="code"href="group__types.html#gae3e32a98d431a02106616da3071832dd"title="System Time, recommended fastest unsigned.">systime_t</a> time) {
<aname="l00366"></a>00366 <spanclass="keywordflow">if</span> ((time -= <aclass="code"href="group__time.html#ga137c8f67c450f34416a786d169be90e2"title="Current system time.">chTimeNow</a>()) > 0)
<aname="l00367"></a>00367 <aclass="code"href="group__threads.html#ga851dc0c4ac72885bf09feebdef4673ac"title="Suspends the invoking thread for the specified time.">chThdSleepS</a>(time);
<aname="l00368"></a>00368 <aclass="code"href="group__system.html#ga5a257fa58a09815eb64a45e2dfbdc22e"title="Leaves the kernel lock mode.">chSysUnlock</a>();
<aname="l00376"></a><aclass="code"href="group__threads.html#gacb0a8f22a8358487eaebab3c84b1c4a1">00376</a><spanclass="keywordtype">void</span><aclass="code"href="group__threads.html#gacb0a8f22a8358487eaebab3c84b1c4a1"title="Yields the time slot.">chThdYield</a>(<spanclass="keywordtype">void</span>) {
<aname="l00378"></a>00378 <aclass="code"href="group__system.html#ga9f6573c0763d1e4e97c63c62edad6e42"title="Enters the kernel lock mode.">chSysLock</a>();
<aname="l00379"></a>00379 <aclass="code"href="group__scheduler.html#ga8fd763c1a004a010fc13575578edefbd"title="Yields the time slot.">chSchDoYieldS</a>();
<aname="l00380"></a>00380 <aclass="code"href="group__system.html#ga5a257fa58a09815eb64a45e2dfbdc22e"title="Leaves the kernel lock mode.">chSysUnlock</a>();
<aname="l00389"></a><aclass="code"href="group__threads.html#ga24ab3a3a4d70214ee360867a1c3c75ac">00389</a><spanclass="keywordtype">void</span><aclass="code"href="group__threads.html#ga24ab3a3a4d70214ee360867a1c3c75ac"title="Terminates the current thread by specifying an exit status code.">chThdExit</a>(<aclass="code"href="group__types.html#ga35bcb0c321cd7bc45bf1a11fa17ebdd3"title="Message, use signed pointer equivalent.">msg_t</a> msg) {
<aname="l00390"></a>00390 <aclass="code"href="struct_thread.html"title="Structure representing a thread.">Thread</a> *tp = currp;
<aname="l00391"></a>00391
<aname="l00392"></a>00392 <aclass="code"href="group__system.html#ga9f6573c0763d1e4e97c63c62edad6e42"title="Enters the kernel lock mode.">chSysLock</a>();
<aname="l00398"></a>00398 <spanclass="preprocessor"></span><spanclass="keywordflow">while</span> (<aclass="code"href="group__internals.html#ga8f6bea56a53acc44758fe61c98d68a4e"title="Evaluates to TRUE if the specified threads queue or list is not empty.">notempty</a>(&tp-><aclass="code"href="struct_thread.html#ad1088bc1f9970cc102dc28000134e9ab"title="Termination waiting list.">p_waiting</a>))
<aname="l00399"></a>00399 <aclass="code"href="group__scheduler.html#ga535d58cfb3436c8d4e4586c31c062298"title="Inserts a thread in the Ready List.">chSchReadyI</a>(<aclass="code"href="group__internals.html#gad9aa523aebdaeefa3cc4a311bc210e8a"title="Pops a Thread from the top of a stack list and returns it.">list_remove</a>(&tp-><aclass="code"href="struct_thread.html#ad1088bc1f9970cc102dc28000134e9ab"title="Termination waiting list.">p_waiting</a>));
<aname="l00402"></a>00402 <spanclass="preprocessor"></span><spanclass="comment">/* Static threads are immediately removed from the registry because</span>
<aname="l00403"></a>00403 <spanclass="comment"> there is no memory to recover.*/</span>
<aname="l00405"></a>00405 <aclass="code"href="group__registry.html#ga472c6eb9a86e5963f452aa78719c92da"title="Removes a thread from the registry list.">REG_REMOVE</a>(tp);
<aname="l00407"></a>00407 <spanclass="preprocessor"></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__threads.html#ga10583a3a3fb4c62693bb08796f8d13ae"title="Thread state: After termination.">THD_STATE_FINAL</a>);
<aname="l00418"></a><aclass="code"href="group__threads.html#gabefc5734beaf29ae0bcd52cd41744930">00418</a><aclass="code"href="struct_thread.html"title="Structure representing a thread.">Thread</a> *<aclass="code"href="group__threads.html#gabefc5734beaf29ae0bcd52cd41744930"title="Adds a reference to a thread object.">chThdAddRef</a>(<aclass="code"href="struct_thread.html"title="Structure representing a thread.">Thread</a> *tp) {
<aname="l00419"></a>00419
<aname="l00420"></a>00420 <aclass="code"href="group__system.html#ga9f6573c0763d1e4e97c63c62edad6e42"title="Enters the kernel lock mode.">chSysLock</a>();
<aname="l00421"></a>00421 <aclass="code"href="group__debug.html#ga43d50c69eb730d0f024eb832d61f30c9"title="Condition assertion.">chDbgAssert</a>(tp-><aclass="code"href="struct_thread.html#af86d1da435197d113bc42fe8139a21c5"title="References to this thread.">p_refs</a>< 255, <spanclass="stringliteral">"chThdAddRef(), #1"</span>, <spanclass="stringliteral">"too many references"</span>);
<aname="l00422"></a>00422 tp-><aclass="code"href="struct_thread.html#af86d1da435197d113bc42fe8139a21c5"title="References to this thread.">p_refs</a>++;
<aname="l00423"></a>00423 <aclass="code"href="group__system.html#ga5a257fa58a09815eb64a45e2dfbdc22e"title="Leaves the kernel lock mode.">chSysUnlock</a>();
<aname="l00436"></a><aclass="code"href="group__threads.html#gaa22f80040cf192015be4607f31a0ac80">00436</a><spanclass="keywordtype">void</span><aclass="code"href="group__threads.html#gaa22f80040cf192015be4607f31a0ac80"title="Releases a reference to a thread object.">chThdRelease</a>(<aclass="code"href="struct_thread.html"title="Structure representing a thread.">Thread</a> *tp) {
<aname="l00437"></a>00437 <aclass="code"href="group__types.html#ga205898ea166481281fec650f2a7e85a3"title="Thread references counter, uint8_t is ok.">trefs_t</a> refs;
<aname="l00438"></a>00438
<aname="l00439"></a>00439 <aclass="code"href="group__system.html#ga9f6573c0763d1e4e97c63c62edad6e42"title="Enters the kernel lock mode.">chSysLock</a>();
<aname="l00440"></a>00440 <aclass="code"href="group__debug.html#ga43d50c69eb730d0f024eb832d61f30c9"title="Condition assertion.">chDbgAssert</a>(tp-><aclass="code"href="struct_thread.html#af86d1da435197d113bc42fe8139a21c5"title="References to this thread.">p_refs</a>> 0, <spanclass="stringliteral">"chThdRelease(), #1"</span>, <spanclass="stringliteral">"not referenced"</span>);
<aname="l00441"></a>00441 refs = --tp-><aclass="code"href="struct_thread.html#af86d1da435197d113bc42fe8139a21c5"title="References to this thread.">p_refs</a>;
<aname="l00442"></a>00442 <aclass="code"href="group__system.html#ga5a257fa58a09815eb64a45e2dfbdc22e"title="Leaves the kernel lock mode.">chSysUnlock</a>();
<aname="l00443"></a>00443
<aname="l00444"></a>00444 <spanclass="comment">/* If the references counter reaches zero and the thread is in its</span>
<aname="l00445"></a>00445 <spanclass="comment"> terminated state then the memory can be returned to the proper</span>
<aname="l00446"></a>00446 <spanclass="comment"> allocator. Of course static threads are not affected.*/</span>
<aname="l00452"></a>00452 <spanclass="preprocessor"></span><aclass="code"href="group__registry.html#ga472c6eb9a86e5963f452aa78719c92da"title="Removes a thread from the registry list.">REG_REMOVE</a>(tp);
<aname="l00460"></a>00460 <spanclass="preprocessor"></span><aclass="code"href="group__registry.html#ga472c6eb9a86e5963f452aa78719c92da"title="Removes a thread from the registry list.">REG_REMOVE</a>(tp);
<aname="l00462"></a>00462 <spanclass="preprocessor"></span><aclass="code"href="group__pools.html#ga978f8d038e8e981bf9e5a104b81c6cb6"title="Releases (or adds) an object into (to) a memory pool.">chPoolFree</a>(tp-><aclass="code"href="struct_thread.html#ae0e65912a0c02df5477a3a524cd41d97"title="Memory Pool where the thread workspace is returned.">p_mpool</a>, tp);
<aname="l00499"></a><aclass="code"href="group__threads.html#ga94a5727ecdbe0f738dfc8e1ede1c3409">00499</a><aclass="code"href="group__types.html#ga35bcb0c321cd7bc45bf1a11fa17ebdd3"title="Message, use signed pointer equivalent.">msg_t</a><aclass="code"href="group__threads.html#ga94a5727ecdbe0f738dfc8e1ede1c3409"title="Blocks the execution of the invoking thread until the specified thread terminates then the exit code ...">chThdWait</a>(<aclass="code"href="struct_thread.html"title="Structure representing a thread.">Thread</a> *tp) {
<aname="l00500"></a>00500 <aclass="code"href="group__types.html#ga35bcb0c321cd7bc45bf1a11fa17ebdd3"title="Message, use signed pointer equivalent.">msg_t</a> msg;
<aname="l00510"></a>00510 <aclass="code"href="group__internals.html#ga5818ce2d363d36402baece614b06e41b"title="Pushes a Thread on top of a stack list.">list_insert</a>(<aclass="code"href="group__scheduler.html#ga1a5fddde56420e8accd0c09c1abb32a7"title="Current thread pointer access macro.">currp</a>, &tp-><aclass="code"href="struct_thread.html#ad1088bc1f9970cc102dc28000134e9ab"title="Termination waiting list.">p_waiting</a>);
<aname="l00511"></a>00511 <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#gaf726245829b74db3a77a5f4bcc17bf67"title="Thread state: Waiting in chThdWait().">THD_STATE_WTEXIT</a>);
<aname="l00516"></a>00516 <spanclass="preprocessor"></span><aclass="code"href="group__threads.html#gaa22f80040cf192015be4607f31a0ac80"title="Releases a reference to a thread object.">chThdRelease</a>(tp);
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>