* @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
| 435 | * If the return value is any other values, it means this operation failed. |
| 436 | */ |
| 437 | rt_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 | } |
| 470 | RTM_EXPORT(rt_thread_close); |
| 471 | |
| 472 | static rt_err_t _thread_detach(rt_thread_t thread); |
no test coverage detected