* @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
| 76 | * @see pthread_rwlock_destroy, pthread_rwlock_rdlock, pthread_rwlock_wrlock, pthread_rwlock_unlock |
| 77 | */ |
| 78 | int 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 | } |
| 95 | RTM_EXPORT(pthread_rwlock_init); |
| 96 | |
| 97 | /** |
no test coverage detected