Lines Matching refs:rwl

31 static uint32_t read_lock_acquire(struct posix_rwlock *rwl, int32_t timeout);
32 static uint32_t write_lock_acquire(struct posix_rwlock *rwl, int32_t timeout);
49 static inline size_t posix_rwlock_to_offset(struct posix_rwlock *rwl) in posix_rwlock_to_offset() argument
51 return rwl - posix_rwlock_pool; in posix_rwlock_to_offset()
88 struct posix_rwlock *rwl; in to_posix_rwlock() local
104 rwl = &posix_rwlock_pool[bit]; in to_posix_rwlock()
106 return rwl; in to_posix_rwlock()
117 struct posix_rwlock *rwl; in pthread_rwlock_init() local
122 rwl = to_posix_rwlock(rwlock); in pthread_rwlock_init()
123 if (rwl == NULL) { in pthread_rwlock_init()
127 sys_sem_init(&rwl->rd_sem, CONCURRENT_READER_LIMIT, CONCURRENT_READER_LIMIT); in pthread_rwlock_init()
128 sys_sem_init(&rwl->wr_sem, 1, 1); in pthread_rwlock_init()
129 sys_sem_init(&rwl->reader_active, 1, 1); in pthread_rwlock_init()
130 rwl->wr_owner = NULL; in pthread_rwlock_init()
132 LOG_DBG("Initialized rwlock %p", rwl); in pthread_rwlock_init()
147 struct posix_rwlock *rwl; in pthread_rwlock_destroy() local
150 rwl = get_posix_rwlock(*rwlock); in pthread_rwlock_destroy()
151 if (rwl == NULL) { in pthread_rwlock_destroy()
156 if (rwl->wr_owner != NULL) { in pthread_rwlock_destroy()
162 bit = posix_rwlock_to_offset(rwl); in pthread_rwlock_destroy()
180 struct posix_rwlock *rwl; in pthread_rwlock_rdlock() local
182 rwl = get_posix_rwlock(*rwlock); in pthread_rwlock_rdlock()
183 if (rwl == NULL) { in pthread_rwlock_rdlock()
187 return read_lock_acquire(rwl, SYS_FOREVER_MS); in pthread_rwlock_rdlock()
203 struct posix_rwlock *rwl; in pthread_rwlock_timedrdlock() local
211 rwl = get_posix_rwlock(*rwlock); in pthread_rwlock_timedrdlock()
212 if (rwl == NULL) { in pthread_rwlock_timedrdlock()
216 if (read_lock_acquire(rwl, timeout) != 0U) { in pthread_rwlock_timedrdlock()
233 struct posix_rwlock *rwl; in pthread_rwlock_tryrdlock() local
235 rwl = get_posix_rwlock(*rwlock); in pthread_rwlock_tryrdlock()
236 if (rwl == NULL) { in pthread_rwlock_tryrdlock()
240 return read_lock_acquire(rwl, 0); in pthread_rwlock_tryrdlock()
253 struct posix_rwlock *rwl; in pthread_rwlock_wrlock() local
255 rwl = get_posix_rwlock(*rwlock); in pthread_rwlock_wrlock()
256 if (rwl == NULL) { in pthread_rwlock_wrlock()
260 return write_lock_acquire(rwl, SYS_FOREVER_MS); in pthread_rwlock_wrlock()
276 struct posix_rwlock *rwl; in pthread_rwlock_timedwrlock() local
284 rwl = get_posix_rwlock(*rwlock); in pthread_rwlock_timedwrlock()
285 if (rwl == NULL) { in pthread_rwlock_timedwrlock()
289 if (write_lock_acquire(rwl, timeout) != 0U) { in pthread_rwlock_timedwrlock()
306 struct posix_rwlock *rwl; in pthread_rwlock_trywrlock() local
308 rwl = get_posix_rwlock(*rwlock); in pthread_rwlock_trywrlock()
309 if (rwl == NULL) { in pthread_rwlock_trywrlock()
313 return write_lock_acquire(rwl, 0); in pthread_rwlock_trywrlock()
324 struct posix_rwlock *rwl; in pthread_rwlock_unlock() local
326 rwl = get_posix_rwlock(*rwlock); in pthread_rwlock_unlock()
327 if (rwl == NULL) { in pthread_rwlock_unlock()
331 if (k_current_get() == rwl->wr_owner) { in pthread_rwlock_unlock()
333 rwl->wr_owner = NULL; in pthread_rwlock_unlock()
334 (void)sys_sem_give(&rwl->reader_active); in pthread_rwlock_unlock()
335 (void)sys_sem_give(&rwl->wr_sem); in pthread_rwlock_unlock()
338 (void)sys_sem_give(&rwl->rd_sem); in pthread_rwlock_unlock()
340 if (sys_sem_count_get(&rwl->rd_sem) == CONCURRENT_READER_LIMIT) { in pthread_rwlock_unlock()
342 (void)sys_sem_give(&rwl->reader_active); in pthread_rwlock_unlock()
348 static uint32_t read_lock_acquire(struct posix_rwlock *rwl, int32_t timeout) in read_lock_acquire() argument
352 if (sys_sem_take(&rwl->wr_sem, SYS_TIMEOUT_MS(timeout)) == 0) { in read_lock_acquire()
353 (void)sys_sem_take(&rwl->reader_active, K_NO_WAIT); in read_lock_acquire()
354 (void)sys_sem_take(&rwl->rd_sem, K_NO_WAIT); in read_lock_acquire()
355 (void)sys_sem_give(&rwl->wr_sem); in read_lock_acquire()
363 static uint32_t write_lock_acquire(struct posix_rwlock *rwl, int32_t timeout) in write_lock_acquire() argument
372 if (sys_sem_take(&rwl->wr_sem, k_timeout) == 0) { in write_lock_acquire()
383 if (sys_sem_take(&rwl->reader_active, k_timeout) == 0) { in write_lock_acquire()
384 rwl->wr_owner = k_current_get(); in write_lock_acquire()
386 (void)sys_sem_give(&rwl->wr_sem); in write_lock_acquire()