Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pthread_mutex:add deadlock assert #13456

Merged
merged 1 commit into from
Sep 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 38 additions & 3 deletions sched/pthread/pthread_mutex.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,41 @@ static void pthread_mutex_add(FAR struct pthread_mutex_s *mutex)
leave_critical_section(flags);
}

/****************************************************************************
* Name: pthread_mutex_check
*
* Description:
* Verify that the mutex is not in the list of mutexes held by
* this pthread.
*
* Input Parameters:
* mutex - The mutex to be locked
*
* Returned Value:
* None
*
****************************************************************************/

#ifdef CONFIG_DEBUG_ASSERTIONS
static void pthread_mutex_check(FAR struct pthread_mutex_s *mutex)
{
FAR struct tcb_s *tcb = this_task();
irqstate_t flags = enter_critical_section();
FAR struct pthread_mutex_s *cur;

DEBUGASSERT(mutex != NULL);
for (cur = tcb->mhead; cur != NULL; cur = cur->flink)
{
/* The mutex should not be in the list of mutexes held by this task */

DEBUGASSERT(cur != mutex);
anjiahao1 marked this conversation as resolved.
Show resolved Hide resolved
}

leave_critical_section(flags);
}

#endif

/****************************************************************************
* Name: pthread_mutex_remove
*
Expand Down Expand Up @@ -145,9 +180,6 @@ int pthread_mutex_take(FAR struct pthread_mutex_s *mutex,
{
int ret = EINVAL;

/* Verify input parameters */

DEBUGASSERT(mutex != NULL);
if (mutex != NULL)
{
/* Make sure that no unexpected context switches occur */
Expand Down Expand Up @@ -197,6 +229,9 @@ int pthread_mutex_take(FAR struct pthread_mutex_s *mutex,

else if (!mutex_is_recursive(&mutex->mutex))
{
#ifdef CONFIG_DEBUG_ASSERTIONS
pthread_mutex_check(mutex);
#endif
pthread_mutex_add(mutex);
}
}
Expand Down
Loading