mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2025-02-28 04:27:07 +08:00
[pthreads] Fix the phread_mutex_trylock issue for not recursive mutex.
This commit is contained in:
parent
4730a45ab3
commit
712c0673fb
@ -232,6 +232,7 @@ RTM_EXPORT(pthread_mutex_unlock);
|
|||||||
int pthread_mutex_trylock(pthread_mutex_t *mutex)
|
int pthread_mutex_trylock(pthread_mutex_t *mutex)
|
||||||
{
|
{
|
||||||
rt_err_t result;
|
rt_err_t result;
|
||||||
|
int mtype;
|
||||||
|
|
||||||
if (!mutex)
|
if (!mutex)
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
@ -241,11 +242,20 @@ int pthread_mutex_trylock(pthread_mutex_t *mutex)
|
|||||||
pthread_mutex_init(mutex, RT_NULL);
|
pthread_mutex_init(mutex, RT_NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mtype = mutex->attr & MUTEXATTR_TYPE_MASK;
|
||||||
|
rt_enter_critical();
|
||||||
|
if (mutex->lock.owner == rt_thread_self() &&
|
||||||
|
mtype != PTHREAD_MUTEX_RECURSIVE)
|
||||||
|
{
|
||||||
|
rt_exit_critical();
|
||||||
|
|
||||||
|
return EDEADLK;
|
||||||
|
}
|
||||||
|
rt_exit_critical();
|
||||||
|
|
||||||
result = rt_mutex_take(&(mutex->lock), 0);
|
result = rt_mutex_take(&(mutex->lock), 0);
|
||||||
if (result == RT_EOK)
|
if (result == RT_EOK) return 0;
|
||||||
return 0;
|
|
||||||
|
|
||||||
return EBUSY;
|
return EBUSY;
|
||||||
}
|
}
|
||||||
RTM_EXPORT(pthread_mutex_trylock);
|
RTM_EXPORT(pthread_mutex_trylock);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user