Merge tag 'trace-printf-v6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/trace...
[drm/drm-misc.git] / tools / perf / util / rwsem.c
blob5109167f27f78c3def6f21586f5cedfa872f7385
1 // SPDX-License-Identifier: GPL-2.0
2 #include "util.h"
3 #include "rwsem.h"
5 #if RWS_ERRORCHECK
6 #include "mutex.h"
7 #endif
9 int init_rwsem(struct rw_semaphore *sem)
11 #if RWS_ERRORCHECK
12 mutex_init(&sem->mtx);
13 return 0;
14 #else
15 return pthread_rwlock_init(&sem->lock, NULL);
16 #endif
19 int exit_rwsem(struct rw_semaphore *sem)
21 #if RWS_ERRORCHECK
22 mutex_destroy(&sem->mtx);
23 return 0;
24 #else
25 return pthread_rwlock_destroy(&sem->lock);
26 #endif
29 int down_read(struct rw_semaphore *sem)
31 #if RWS_ERRORCHECK
32 mutex_lock(&sem->mtx);
33 return 0;
34 #else
35 return perf_singlethreaded ? 0 : pthread_rwlock_rdlock(&sem->lock);
36 #endif
39 int up_read(struct rw_semaphore *sem)
41 #if RWS_ERRORCHECK
42 mutex_unlock(&sem->mtx);
43 return 0;
44 #else
45 return perf_singlethreaded ? 0 : pthread_rwlock_unlock(&sem->lock);
46 #endif
49 int down_write(struct rw_semaphore *sem)
51 #if RWS_ERRORCHECK
52 mutex_lock(&sem->mtx);
53 return 0;
54 #else
55 return perf_singlethreaded ? 0 : pthread_rwlock_wrlock(&sem->lock);
56 #endif
59 int up_write(struct rw_semaphore *sem)
61 #if RWS_ERRORCHECK
62 mutex_unlock(&sem->mtx);
63 return 0;
64 #else
65 return perf_singlethreaded ? 0 : pthread_rwlock_unlock(&sem->lock);
66 #endif