1fb71c86cSArnaldo Carvalho de Melo// SPDX-License-Identifier: GPL-2.0
20a7c74eaSArnaldo Carvalho de Melo#include "util.h"
30a7c74eaSArnaldo Carvalho de Melo#include "rwsem.h"
40a7c74eaSArnaldo Carvalho de Melo
50a7c74eaSArnaldo Carvalho de Meloint init_rwsem(struct rw_semaphore *sem)
60a7c74eaSArnaldo Carvalho de Melo{
70a7c74eaSArnaldo Carvalho de Melo	return pthread_rwlock_init(&sem->lock, NULL);
80a7c74eaSArnaldo Carvalho de Melo}
90a7c74eaSArnaldo Carvalho de Melo
100a7c74eaSArnaldo Carvalho de Meloint exit_rwsem(struct rw_semaphore *sem)
110a7c74eaSArnaldo Carvalho de Melo{
120a7c74eaSArnaldo Carvalho de Melo	return pthread_rwlock_destroy(&sem->lock);
130a7c74eaSArnaldo Carvalho de Melo}
140a7c74eaSArnaldo Carvalho de Melo
150a7c74eaSArnaldo Carvalho de Meloint down_read(struct rw_semaphore *sem)
160a7c74eaSArnaldo Carvalho de Melo{
170a7c74eaSArnaldo Carvalho de Melo	return perf_singlethreaded ? 0 : pthread_rwlock_rdlock(&sem->lock);
180a7c74eaSArnaldo Carvalho de Melo}
190a7c74eaSArnaldo Carvalho de Melo
200a7c74eaSArnaldo Carvalho de Meloint up_read(struct rw_semaphore *sem)
210a7c74eaSArnaldo Carvalho de Melo{
220a7c74eaSArnaldo Carvalho de Melo	return perf_singlethreaded ? 0 : pthread_rwlock_unlock(&sem->lock);
230a7c74eaSArnaldo Carvalho de Melo}
240a7c74eaSArnaldo Carvalho de Melo
250a7c74eaSArnaldo Carvalho de Meloint down_write(struct rw_semaphore *sem)
260a7c74eaSArnaldo Carvalho de Melo{
270a7c74eaSArnaldo Carvalho de Melo	return perf_singlethreaded ? 0 : pthread_rwlock_wrlock(&sem->lock);
280a7c74eaSArnaldo Carvalho de Melo}
290a7c74eaSArnaldo Carvalho de Melo
300a7c74eaSArnaldo Carvalho de Meloint up_write(struct rw_semaphore *sem)
310a7c74eaSArnaldo Carvalho de Melo{
320a7c74eaSArnaldo Carvalho de Melo	return perf_singlethreaded ? 0 : pthread_rwlock_unlock(&sem->lock);
330a7c74eaSArnaldo Carvalho de Melo}
34