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

Function pthread_mutex_init

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

* @brief Initializes a mutex with optional attributes. * * This function initializes a mutex object pointed to by `mutex`. The mutex * can optionally be initialized with attributes specified by `attr`. If * `attr` is `NULL`, default attributes are used. * * @param[in,out] mutex Pointer to the mutex to be initialized. * @param[in] attr Pointer to the mutex attributes object. Pass `NULL` to u

Source from the content-addressed store, hash-verified

294 * @see pthread_mutex_destroy, pthread_mutex_lock, pthread_mutex_unlock
295 */
296int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr)
297{
298 rt_err_t result;
299 char name[RT_NAME_MAX];
300 static rt_uint16_t pthread_mutex_number = 0;
301
302 if (!mutex)
303 return EINVAL;
304
305 /* build mutex name */
306 rt_snprintf(name, sizeof(name), "pmtx%02d", pthread_mutex_number ++);
307 if (attr == RT_NULL)
308 mutex->attr = pthread_default_mutexattr;
309 else
310 mutex->attr = *attr;
311
312 /* init mutex lock */
313 result = rt_mutex_init(&(mutex->lock), name, RT_IPC_FLAG_PRIO);
314 if (result != RT_EOK)
315 return EINVAL;
316
317 /* detach the object from system object container */
318 rt_object_detach(&(mutex->lock.parent.parent));
319 mutex->lock.parent.parent.type = RT_Object_Class_Mutex;
320
321 return 0;
322}
323RTM_EXPORT(pthread_mutex_init);
324
325/**

Callers 15

pthread_barrier_initFunction · 0.85
pthread_mutex_lockFunction · 0.85
pthread_mutex_unlockFunction · 0.85
pthread_mutex_trylockFunction · 0.85
pthread_rwlock_initFunction · 0.85
shm_sum_ipcs_lock_initFunction · 0.85
shm_sum_ipc_getFunction · 0.85
snd_pcm_newFunction · 0.85
rt_hw_sdl_startFunction · 0.85
mainthread_schedulerFunction · 0.85

Calls 3

rt_snprintfFunction · 0.85
rt_mutex_initFunction · 0.85
rt_object_detachFunction · 0.85

Tested by 1

test_threadFunction · 0.68