Lines Matching refs:rwlock
17 static uint32_t read_lock_acquire(pthread_rwlock_t *rwlock, int32_t timeout);
18 static uint32_t write_lock_acquire(pthread_rwlock_t *rwlock, int32_t timeout);
25 int pthread_rwlock_init(pthread_rwlock_t *rwlock, in pthread_rwlock_init() argument
28 k_sem_init(&rwlock->rd_sem, CONCURRENT_READER_LIMIT, in pthread_rwlock_init()
30 k_sem_init(&rwlock->wr_sem, 1, 1); in pthread_rwlock_init()
31 k_sem_init(&rwlock->reader_active, 1, 1); in pthread_rwlock_init()
32 rwlock->wr_owner = NULL; in pthread_rwlock_init()
33 rwlock->status = INITIALIZED; in pthread_rwlock_init()
42 int pthread_rwlock_destroy(pthread_rwlock_t *rwlock) in pthread_rwlock_destroy() argument
44 if (rwlock->status == NOT_INITIALIZED) { in pthread_rwlock_destroy()
48 if (rwlock->wr_owner != NULL) { in pthread_rwlock_destroy()
52 if (rwlock->status == INITIALIZED) { in pthread_rwlock_destroy()
53 rwlock->status = NOT_INITIALIZED; in pthread_rwlock_destroy()
68 int pthread_rwlock_rdlock(pthread_rwlock_t *rwlock) in pthread_rwlock_rdlock() argument
70 if (rwlock->status == NOT_INITIALIZED) { in pthread_rwlock_rdlock()
74 return read_lock_acquire(rwlock, SYS_FOREVER_MS); in pthread_rwlock_rdlock()
85 int pthread_rwlock_timedrdlock(pthread_rwlock_t *rwlock, in pthread_rwlock_timedrdlock() argument
91 if (rwlock->status == NOT_INITIALIZED || abstime->tv_nsec < 0 || in pthread_rwlock_timedrdlock()
98 if (read_lock_acquire(rwlock, timeout) != 0U) { in pthread_rwlock_timedrdlock()
113 int pthread_rwlock_tryrdlock(pthread_rwlock_t *rwlock) in pthread_rwlock_tryrdlock() argument
115 if (rwlock->status == NOT_INITIALIZED) { in pthread_rwlock_tryrdlock()
119 return read_lock_acquire(rwlock, 0); in pthread_rwlock_tryrdlock()
130 int pthread_rwlock_wrlock(pthread_rwlock_t *rwlock) in pthread_rwlock_wrlock() argument
132 if (rwlock->status == NOT_INITIALIZED) { in pthread_rwlock_wrlock()
136 return write_lock_acquire(rwlock, SYS_FOREVER_MS); in pthread_rwlock_wrlock()
147 int pthread_rwlock_timedwrlock(pthread_rwlock_t *rwlock, in pthread_rwlock_timedwrlock() argument
153 if (rwlock->status == NOT_INITIALIZED || abstime->tv_nsec < 0 || in pthread_rwlock_timedwrlock()
160 if (write_lock_acquire(rwlock, timeout) != 0U) { in pthread_rwlock_timedwrlock()
175 int pthread_rwlock_trywrlock(pthread_rwlock_t *rwlock) in pthread_rwlock_trywrlock() argument
177 if (rwlock->status == NOT_INITIALIZED) { in pthread_rwlock_trywrlock()
181 return write_lock_acquire(rwlock, 0); in pthread_rwlock_trywrlock()
190 int pthread_rwlock_unlock(pthread_rwlock_t *rwlock) in pthread_rwlock_unlock() argument
192 if (rwlock->status == NOT_INITIALIZED) { in pthread_rwlock_unlock()
196 if (k_current_get() == rwlock->wr_owner) { in pthread_rwlock_unlock()
198 rwlock->wr_owner = NULL; in pthread_rwlock_unlock()
199 k_sem_give(&rwlock->reader_active); in pthread_rwlock_unlock()
200 k_sem_give(&rwlock->wr_sem); in pthread_rwlock_unlock()
203 if (k_sem_count_get(&rwlock->rd_sem) == in pthread_rwlock_unlock()
206 k_sem_give(&rwlock->reader_active); in pthread_rwlock_unlock()
209 k_sem_give(&rwlock->rd_sem); in pthread_rwlock_unlock()
215 static uint32_t read_lock_acquire(pthread_rwlock_t *rwlock, int32_t timeout) in read_lock_acquire() argument
219 if (k_sem_take(&rwlock->wr_sem, SYS_TIMEOUT_MS(timeout)) == 0) { in read_lock_acquire()
220 k_sem_take(&rwlock->reader_active, K_NO_WAIT); in read_lock_acquire()
221 k_sem_take(&rwlock->rd_sem, K_NO_WAIT); in read_lock_acquire()
222 k_sem_give(&rwlock->wr_sem); in read_lock_acquire()
230 static uint32_t write_lock_acquire(pthread_rwlock_t *rwlock, int32_t timeout) in write_lock_acquire() argument
239 if (k_sem_take(&rwlock->wr_sem, k_timeout) == 0) { in write_lock_acquire()
250 if (k_sem_take(&rwlock->reader_active, k_timeout) == 0) { in write_lock_acquire()
251 rwlock->wr_owner = k_current_get(); in write_lock_acquire()
253 k_sem_give(&rwlock->wr_sem); in write_lock_acquire()