MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / pthread_mutex_unlock

Function pthread_mutex_unlock

components/libc/posix/pthreads/pthread_mutex.c:454–485  ·  view source on GitHub ↗

* @brief Unlocks a mutex. * * This function unlocks the mutex object pointed to by `mutex`. If other threads * are blocked waiting for the mutex, one of them will acquire the lock once it is * released. The calling thread must hold the lock on the mutex before calling * this function. * * @param[in,out] mutex Pointer to the mutex to be unlocked. * * @return * - 0 on success. * - Non-zer

Source from the content-addressed store, hash-verified

452 * @see pthread_mutex_lock, pthread_mutex_trylock, pthread_mutex_init
453 */
454int pthread_mutex_unlock(pthread_mutex_t *mutex)
455{
456 rt_err_t result;
457
458 if (!mutex)
459 return EINVAL;
460 if (mutex->attr == -1)
461 {
462 /* init mutex */
463 pthread_mutex_init(mutex, RT_NULL);
464 }
465
466 if (mutex->lock.owner != rt_thread_self())
467 {
468 int mtype;
469 mtype = mutex->attr & MUTEXATTR_TYPE_MASK;
470
471 /* error check, return EPERM */
472 if (mtype == PTHREAD_MUTEX_ERRORCHECK)
473 return EPERM;
474
475 /* no thread waiting on this mutex */
476 if (mutex->lock.owner == RT_NULL)
477 return 0;
478 }
479
480 result = rt_mutex_release(&(mutex->lock));
481 if (result == RT_EOK)
482 return 0;
483
484 return EINVAL;
485}
486RTM_EXPORT(pthread_mutex_unlock);
487
488/**

Callers 15

emutls_get_indexFunction · 0.85
pthread_barrier_destroyFunction · 0.85
pthread_barrier_waitFunction · 0.85
_pthread_cond_timedwaitFunction · 0.85
pthread_rwlock_destroyFunction · 0.85
pthread_rwlock_rdlockFunction · 0.85
pthread_rwlock_tryrdlockFunction · 0.85
pthread_rwlock_trywrlockFunction · 0.85
pthread_rwlock_unlockFunction · 0.85
pthread_rwlock_wrlockFunction · 0.85

Calls 3

pthread_mutex_initFunction · 0.85
rt_thread_selfFunction · 0.85
rt_mutex_releaseFunction · 0.85

Tested by 1

test_threadFunction · 0.68