]> git.sesse.net Git - bcachefs-tools-debian/blob - include/linux/percpu-rwsem.h
use a mutex for percpu rwsemaphores
[bcachefs-tools-debian] / 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 void percpu_up_read_preempt_enable(struct percpu_rw_semaphore *sem)
24 {
25         pthread_mutex_unlock(&sem->lock);
26 }
27
28 static inline void percpu_up_read(struct percpu_rw_semaphore *sem)
29 {
30         pthread_mutex_unlock(&sem->lock);
31 }
32
33 static inline void percpu_down_write(struct percpu_rw_semaphore *sem)
34 {
35         pthread_mutex_lock(&sem->lock);
36 }
37
38 static inline void percpu_up_write(struct percpu_rw_semaphore *sem)
39 {
40         pthread_mutex_unlock(&sem->lock);
41 }
42
43 static inline void percpu_free_rwsem(struct percpu_rw_semaphore *sem) {}
44
45 static inline int percpu_init_rwsem(struct percpu_rw_semaphore *sem)
46 {
47         pthread_mutex_init(&sem->lock, NULL);
48         return 0;
49 }
50
51 #define percpu_rwsem_assert_held(sem)           do {} while (0)
52
53 #endif