18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci#include "util.h"
38c2ecf20Sopenharmony_ci#include "rwsem.h"
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ciint init_rwsem(struct rw_semaphore *sem)
68c2ecf20Sopenharmony_ci{
78c2ecf20Sopenharmony_ci	return pthread_rwlock_init(&sem->lock, NULL);
88c2ecf20Sopenharmony_ci}
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ciint exit_rwsem(struct rw_semaphore *sem)
118c2ecf20Sopenharmony_ci{
128c2ecf20Sopenharmony_ci	return pthread_rwlock_destroy(&sem->lock);
138c2ecf20Sopenharmony_ci}
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ciint down_read(struct rw_semaphore *sem)
168c2ecf20Sopenharmony_ci{
178c2ecf20Sopenharmony_ci	return perf_singlethreaded ? 0 : pthread_rwlock_rdlock(&sem->lock);
188c2ecf20Sopenharmony_ci}
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ciint up_read(struct rw_semaphore *sem)
218c2ecf20Sopenharmony_ci{
228c2ecf20Sopenharmony_ci	return perf_singlethreaded ? 0 : pthread_rwlock_unlock(&sem->lock);
238c2ecf20Sopenharmony_ci}
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ciint down_write(struct rw_semaphore *sem)
268c2ecf20Sopenharmony_ci{
278c2ecf20Sopenharmony_ci	return perf_singlethreaded ? 0 : pthread_rwlock_wrlock(&sem->lock);
288c2ecf20Sopenharmony_ci}
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ciint up_write(struct rw_semaphore *sem)
318c2ecf20Sopenharmony_ci{
328c2ecf20Sopenharmony_ci	return perf_singlethreaded ? 0 : pthread_rwlock_unlock(&sem->lock);
338c2ecf20Sopenharmony_ci}
34