]> git.sesse.net Git - bcachefs-tools-debian/blob - c_src/include/linux/percpu-rwsem.h
153251c076856821bc25b2ab85914b672b1fe938
[bcachefs-tools-debian] / c_src / include / linux / percpu-rwsem.h
1
2 /* SPDX-License-Identifier: GPL-2.0 */
3 #ifndef _LINUX_PERCPU_RWSEM_H
4 #define _LINUX_PERCPU_RWSEM_H
5
6 #include <pthread.h>
7 #include <linux/preempt.h>
8
9 struct percpu_rw_semaphore {
10         pthread_mutex_t         lock;
11 };
12
13 static inline void percpu_down_read_preempt_disable(struct percpu_rw_semaphore *sem)
14 {
15         pthread_mutex_lock(&sem->lock);
16 }
17
18 static inline void percpu_down_read(struct percpu_rw_semaphore *sem)
19 {
20         pthread_mutex_lock(&sem->lock);
21 }
22
23 static inline int percpu_down_read_trylock(struct percpu_rw_semaphore *sem)
24 {
25         return !pthread_mutex_trylock(&sem->lock);
26 }
27
28 static inline void percpu_up_read_preempt_enable(struct percpu_rw_semaphore *sem)
29 {
30         pthread_mutex_unlock(&sem->lock);
31 }
32
33 static inline void percpu_up_read(struct percpu_rw_semaphore *sem)
34 {
35         pthread_mutex_unlock(&sem->lock);
36 }
37
38 static inline void percpu_down_write(struct percpu_rw_semaphore *sem)
39 {
40         pthread_mutex_lock(&sem->lock);
41 }
42
43 static inline void percpu_up_write(struct percpu_rw_semaphore *sem)
44 {
45         pthread_mutex_unlock(&sem->lock);
46 }
47
48 static inline void percpu_free_rwsem(struct percpu_rw_semaphore *sem) {}
49
50 static inline int percpu_init_rwsem(struct percpu_rw_semaphore *sem)
51 {
52         pthread_mutex_init(&sem->lock, NULL);
53         return 0;
54 }
55
56 #define percpu_rwsem_assert_held(sem)           do {} while (0)
57
58 #endif