diff options
| author | Bernard Xiong <[email protected]> | 2016-11-03 15:38:51 +0800 |
|---|---|---|
| committer | Bernard Xiong <[email protected]> | 2016-11-03 15:38:51 +0800 |
| commit | 712c0673fbe9a5fa6b23f07ff58ea7dbdc6d4347 (patch) | |
| tree | 696aa2cf74f8c57f86c0c0443672b922294668eb | |
| parent | 4730a45ab32991ad03c43304fd488bcf96769af1 (diff) | |
[pthreads] Fix the phread_mutex_trylock issue for not recursive mutex.
| -rw-r--r-- | components/libc/pthreads/pthread_mutex.c | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/components/libc/pthreads/pthread_mutex.c b/components/libc/pthreads/pthread_mutex.c index 40fd870e81..3a3fbe61e5 100644 --- a/components/libc/pthreads/pthread_mutex.c +++ b/components/libc/pthreads/pthread_mutex.c @@ -232,6 +232,7 @@ RTM_EXPORT(pthread_mutex_unlock); int pthread_mutex_trylock(pthread_mutex_t *mutex) { rt_err_t result; + int mtype; if (!mutex) return EINVAL; @@ -241,11 +242,20 @@ int pthread_mutex_trylock(pthread_mutex_t *mutex) 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); - if (result == RT_EOK) - return 0; + if (result == RT_EOK) return 0; return EBUSY; } RTM_EXPORT(pthread_mutex_trylock); - |
