xref: /openbmc/linux/tools/perf/util/rwsem.c (revision be709d48)
1 #include "util.h"
2 #include "rwsem.h"
3 
4 int init_rwsem(struct rw_semaphore *sem)
5 {
6 	return pthread_rwlock_init(&sem->lock, NULL);
7 }
8 
9 int exit_rwsem(struct rw_semaphore *sem)
10 {
11 	return pthread_rwlock_destroy(&sem->lock);
12 }
13 
14 int down_read(struct rw_semaphore *sem)
15 {
16 	return perf_singlethreaded ? 0 : pthread_rwlock_rdlock(&sem->lock);
17 }
18 
19 int up_read(struct rw_semaphore *sem)
20 {
21 	return perf_singlethreaded ? 0 : pthread_rwlock_unlock(&sem->lock);
22 }
23 
24 int down_write(struct rw_semaphore *sem)
25 {
26 	return perf_singlethreaded ? 0 : pthread_rwlock_wrlock(&sem->lock);
27 }
28 
29 int up_write(struct rw_semaphore *sem)
30 {
31 	return perf_singlethreaded ? 0 : pthread_rwlock_unlock(&sem->lock);
32 }
33