at master 71 lines 1.3 kB view raw
1// SPDX-License-Identifier: GPL-2.0 2#include "util.h" 3#include "rwsem.h" 4 5#if RWS_ERRORCHECK 6#include "mutex.h" 7#endif 8 9int init_rwsem(struct rw_semaphore *sem) 10{ 11#if RWS_ERRORCHECK 12 mutex_init(&sem->mtx); 13 return 0; 14#else 15 return pthread_rwlock_init(&sem->lock, NULL); 16#endif 17} 18 19int exit_rwsem(struct rw_semaphore *sem) 20{ 21#if RWS_ERRORCHECK 22 mutex_destroy(&sem->mtx); 23 return 0; 24#else 25 return pthread_rwlock_destroy(&sem->lock); 26#endif 27} 28 29int down_read(struct rw_semaphore *sem) 30 NO_THREAD_SAFETY_ANALYSIS 31{ 32#if RWS_ERRORCHECK 33 mutex_lock(&sem->mtx); 34 return 0; 35#else 36 return perf_singlethreaded ? 0 : pthread_rwlock_rdlock(&sem->lock); 37#endif 38} 39 40int up_read(struct rw_semaphore *sem) 41 NO_THREAD_SAFETY_ANALYSIS 42{ 43#if RWS_ERRORCHECK 44 mutex_unlock(&sem->mtx); 45 return 0; 46#else 47 return perf_singlethreaded ? 0 : pthread_rwlock_unlock(&sem->lock); 48#endif 49} 50 51int down_write(struct rw_semaphore *sem) 52 NO_THREAD_SAFETY_ANALYSIS 53{ 54#if RWS_ERRORCHECK 55 mutex_lock(&sem->mtx); 56 return 0; 57#else 58 return perf_singlethreaded ? 0 : pthread_rwlock_wrlock(&sem->lock); 59#endif 60} 61 62int up_write(struct rw_semaphore *sem) 63 NO_THREAD_SAFETY_ANALYSIS 64{ 65#if RWS_ERRORCHECK 66 mutex_unlock(&sem->mtx); 67 return 0; 68#else 69 return perf_singlethreaded ? 0 : pthread_rwlock_unlock(&sem->lock); 70#endif 71}