brintos

brintos / linux-shallow public Read only

0
0
Text · 1.1 KiB · 5109167 Raw
68 lines · c
1// SPDX-License-Identifier: GPL-2.02#include "util.h"3#include "rwsem.h"4 5#if RWS_ERRORCHECK6#include "mutex.h"7#endif8 9int init_rwsem(struct rw_semaphore *sem)10{11#if RWS_ERRORCHECK12	mutex_init(&sem->mtx);13	return 0;14#else15	return pthread_rwlock_init(&sem->lock, NULL);16#endif17}18 19int exit_rwsem(struct rw_semaphore *sem)20{21#if RWS_ERRORCHECK22	mutex_destroy(&sem->mtx);23	return 0;24#else25	return pthread_rwlock_destroy(&sem->lock);26#endif27}28 29int down_read(struct rw_semaphore *sem)30{31#if RWS_ERRORCHECK32	mutex_lock(&sem->mtx);33	return 0;34#else35	return perf_singlethreaded ? 0 : pthread_rwlock_rdlock(&sem->lock);36#endif37}38 39int up_read(struct rw_semaphore *sem)40{41#if RWS_ERRORCHECK42	mutex_unlock(&sem->mtx);43	return 0;44#else45	return perf_singlethreaded ? 0 : pthread_rwlock_unlock(&sem->lock);46#endif47}48 49int down_write(struct rw_semaphore *sem)50{51#if RWS_ERRORCHECK52	mutex_lock(&sem->mtx);53	return 0;54#else55	return perf_singlethreaded ? 0 : pthread_rwlock_wrlock(&sem->lock);56#endif57}58 59int up_write(struct rw_semaphore *sem)60{61#if RWS_ERRORCHECK62	mutex_unlock(&sem->mtx);63	return 0;64#else65	return perf_singlethreaded ? 0 : pthread_rwlock_unlock(&sem->lock);66#endif67}68