4
0
mirror of https://github.com/RT-Thread/rt-thread.git synced 2025-02-18 18:39:11 +08:00

[kernel] release mutex when thread delete (#8345)

This commit is contained in:
Yuqiang Wang 2023-12-07 22:32:53 +08:00 committed by GitHub
parent 073761fdbe
commit 8997db911f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -144,6 +144,22 @@ static void _thread_timeout(void *parameter)
rt_schedule();
}
/* release the mutex held by a thread when thread is reclaimed */
#ifdef RT_USING_MUTEX
static void _free_owned_mutex(rt_thread_t thread)
{
rt_list_t *node;
rt_list_t *tmp_list;
struct rt_mutex *mutex;
rt_list_for_each_safe(node, tmp_list, &(thread->taken_object_list))
{
mutex = rt_list_entry(node, struct rt_mutex, taken_list);
rt_mutex_release(mutex);
}
}
#endif
static rt_err_t _thread_init(struct rt_thread *thread,
const char *name,
void (*entry)(void *parameter),
@ -444,6 +460,7 @@ rt_err_t rt_thread_detach(rt_thread_t thread)
thread->stat = RT_THREAD_CLOSE;
#ifdef RT_USING_MUTEX
_free_owned_mutex(thread);
if ((thread->pending_object) &&
(rt_object_get_type(thread->pending_object) == RT_Object_Class_Mutex))
{
@ -518,18 +535,6 @@ rt_thread_t rt_thread_create(const char *name,
}
RTM_EXPORT(rt_thread_create);
void _free_owned_mutex(rt_thread_t thread)
{
rt_list_t *node;
rt_list_t *tmp_list;
struct rt_mutex *mutex;
rt_list_for_each_safe(node, tmp_list, &(thread->taken_object_list))
{
mutex = rt_list_entry(node, struct rt_mutex, taken_list);
rt_mutex_release(mutex);
}
}
/**
* @brief This function will delete a thread. The thread object will be removed from
* thread queue and deleted from system object management in the idle thread.