GNU Linux-libre 6.9-gnu
[releases.git] / tools / include / linux / rwsem.h
1 /* SPDX-License-Identifier: GPL-2.0+ */
2 #ifndef _TOOLS__RWSEM_H
3 #define _TOOLS__RWSEM_H
4
5 #include <pthread.h>
6
7 struct rw_semaphore {
8         pthread_rwlock_t lock;
9 };
10
11 static inline int init_rwsem(struct rw_semaphore *sem)
12 {
13         return pthread_rwlock_init(&sem->lock, NULL);
14 }
15
16 static inline int exit_rwsem(struct rw_semaphore *sem)
17 {
18         return pthread_rwlock_destroy(&sem->lock);
19 }
20
21 static inline int down_read(struct rw_semaphore *sem)
22 {
23         return pthread_rwlock_rdlock(&sem->lock);
24 }
25
26 static inline int up_read(struct rw_semaphore *sem)
27 {
28         return pthread_rwlock_unlock(&sem->lock);
29 }
30
31 static inline int down_write(struct rw_semaphore *sem)
32 {
33         return pthread_rwlock_wrlock(&sem->lock);
34 }
35
36 static inline int up_write(struct rw_semaphore *sem)
37 {
38         return pthread_rwlock_unlock(&sem->lock);
39 }
40
41 #define down_read_nested(sem, subclass)         down_read(sem)
42 #define down_write_nested(sem, subclass)        down_write(sem)
43
44 #endif /* _TOOLS_RWSEM_H */