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

Function pthread_rwlock_init

components/libc/posix/pthreads/pthread_rwlock.c:78–94  ·  view source on GitHub ↗

* @brief Initializes a read-write lock. * * This function initializes the read-write lock object pointed to by `rwlock` with the * attributes specified by `attr`. If `attr` is `NULL`, the default attributes are used. * A read-write lock allows multiple threads to read or a single thread to write, but not both simultaneously. * * @param rwlock A pointer to the read-write lock object to be ini

Source from the content-addressed store, hash-verified

76 * @see pthread_rwlock_destroy, pthread_rwlock_rdlock, pthread_rwlock_wrlock, pthread_rwlock_unlock
77 */
78int pthread_rwlock_init(pthread_rwlock_t *rwlock,
79 const pthread_rwlockattr_t *attr)
80{
81 if (!rwlock)
82 return EINVAL;
83
84 rwlock->attr = PTHREAD_PROCESS_PRIVATE;
85 pthread_mutex_init(&(rwlock->rw_mutex), NULL);
86 pthread_cond_init(&(rwlock->rw_condreaders), NULL);
87 pthread_cond_init(&(rwlock->rw_condwriters), NULL);
88
89 rwlock->rw_nwaitwriters = 0;
90 rwlock->rw_nwaitreaders = 0;
91 rwlock->rw_refcount = 0;
92
93 return 0;
94}
95RTM_EXPORT(pthread_rwlock_init);
96
97/**

Callers 7

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 2

pthread_mutex_initFunction · 0.85
pthread_cond_initFunction · 0.85

Tested by

no test coverage detected