MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / rt_thread_close

Function rt_thread_close

src/thread.c:437–469  ·  view source on GitHub ↗

* @brief This function will close a thread. The thread object will be removed from * thread queue and detached/deleted from the system object management. * It's different from rt_thread_delete or rt_thread_detach that this will not enqueue * the closing thread to cleanup queue. * * @param thread is the thread to be closed. * * @return Return the operation sta

Source from the content-addressed store, hash-verified

435 * If the return value is any other values, it means this operation failed.
436 */
437rt_err_t rt_thread_close(rt_thread_t thread)
438{
439 rt_sched_lock_level_t slvl;
440 rt_uint8_t thread_status;
441
442 /* forbid scheduling on current core if closing current thread */
443 RT_ASSERT(thread != rt_thread_self() || rt_critical_level());
444
445 /* before checking status of scheduler */
446 rt_sched_lock(&slvl);
447
448 /* check if thread is already closed */
449 thread_status = rt_sched_thread_get_stat(thread);
450 if (thread_status != RT_THREAD_CLOSE)
451 {
452 if (thread_status != RT_THREAD_INIT)
453 {
454 /* remove from schedule */
455 rt_sched_remove_thread(thread);
456 }
457
458 /* release thread timer */
459 rt_timer_detach(&(thread->thread_timer));
460
461 /* change stat */
462 rt_sched_thread_close(thread);
463 }
464
465 /* scheduler works are done */
466 rt_sched_unlock(slvl);
467
468 return RT_EOK;
469}
470RTM_EXPORT(rt_thread_close);
471
472static rt_err_t _thread_detach(rt_thread_t thread);

Callers 3

_thread_exitFunction · 0.85
_thread_detachFunction · 0.85

Calls 8

rt_thread_selfFunction · 0.85
rt_sched_thread_get_statFunction · 0.85
rt_timer_detachFunction · 0.85
rt_sched_thread_closeFunction · 0.85
rt_critical_levelFunction · 0.70
rt_sched_lockFunction · 0.70
rt_sched_remove_threadFunction · 0.70
rt_sched_unlockFunction · 0.70

Tested by

no test coverage detected