* @brief Decrements the reference count of a lightweight process (LWP) * * @param[in,out] lwp The lightweight process whose reference count to decrement * * @return int The reference count before decrementing * * @note This function atomically decrements the LWP's reference count. * When the count reaches 1 (meaning this was the last reference): * - For debug builds, sends a me
| 978 | * - Calls lwp_free() to release all LWP resources |
| 979 | */ |
| 980 | int lwp_ref_dec(struct rt_lwp *lwp) |
| 981 | { |
| 982 | int ref; |
| 983 | |
| 984 | ref = rt_atomic_add(&lwp->ref, -1); |
| 985 | LOG_D("%s(lwp=%p,lwp->cmd=%s): before ref=%d", __func__, lwp, lwp->cmd, ref); |
| 986 | |
| 987 | if (ref == 1) |
| 988 | { |
| 989 | struct rt_channel_msg msg; |
| 990 | |
| 991 | if (lwp->debug) |
| 992 | { |
| 993 | memset(&msg, 0, sizeof msg); |
| 994 | rt_raw_channel_send(gdb_server_channel(), &msg); |
| 995 | } |
| 996 | |
| 997 | #ifndef ARCH_MM_MMU |
| 998 | #ifdef RT_LWP_USING_SHM |
| 999 | lwp_shm_lwp_free(lwp); |
| 1000 | #endif /* RT_LWP_USING_SHM */ |
| 1001 | #endif /* not defined ARCH_MM_MMU */ |
| 1002 | lwp_free(lwp); |
| 1003 | } |
| 1004 | else |
| 1005 | { |
| 1006 | /* reference must be a positive integer */ |
| 1007 | RT_ASSERT(ref > 1); |
| 1008 | } |
| 1009 | |
| 1010 | return ref; |
| 1011 | } |
| 1012 | |
| 1013 | /** |
| 1014 | * @brief Retrieves a lightweight process (LWP) by its PID while holding the lock |