* @brief Handles thread exit for a lightweight process * * @param[in,out] thread The thread that is exiting * @param[in] status The exit status to set for the thread * * @note For MMU architectures, this function checks if the exiting thread is the * header thread (main thread). If so, it treats it as a process exit. */
| 911 | * header thread (main thread). If so, it treats it as a process exit. |
| 912 | */ |
| 913 | void lwp_thread_exit(rt_thread_t thread, int status) |
| 914 | { |
| 915 | rt_thread_t header_thr; |
| 916 | struct rt_lwp *lwp; |
| 917 | |
| 918 | LOG_D("%s", __func__); |
| 919 | |
| 920 | RT_ASSERT(thread == rt_thread_self()); |
| 921 | lwp = (struct rt_lwp *)thread->lwp; |
| 922 | RT_ASSERT(lwp != RT_NULL); |
| 923 | |
| 924 | #ifdef ARCH_MM_MMU |
| 925 | _clear_child_tid(thread); |
| 926 | |
| 927 | LWP_LOCK(lwp); |
| 928 | header_thr = rt_list_entry(lwp->t_grp.prev, struct rt_thread, sibling); |
| 929 | if (header_thr == thread && thread->sibling.prev == &lwp->t_grp) |
| 930 | { |
| 931 | /** |
| 932 | * if thread exit, treated as process exit normally. |
| 933 | * This is reasonable since trap event is exited through lwp_exit() |
| 934 | */ |
| 935 | lwp->lwp_status = LWP_CREATE_STAT_EXIT(status); |
| 936 | LWP_UNLOCK(lwp); |
| 937 | |
| 938 | lwp_terminate(lwp); |
| 939 | } |
| 940 | else |
| 941 | { |
| 942 | LWP_UNLOCK(lwp); |
| 943 | } |
| 944 | #endif /* ARCH_MM_MMU */ |
| 945 | |
| 946 | _thread_exit(lwp, thread); |
| 947 | } |
| 948 | |
| 949 | /** |
| 950 | * @brief Increments the reference count of a lightweight process |
no test coverage detected