summaryrefslogtreecommitdiff
path: root/include/linux/percpu-rwsem.h
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2019-03-08 14:41:57 -0500
committerKent Overstreet <kent.overstreet@gmail.com>2019-03-08 14:41:57 -0500
commit0aaa8494121f61f76c93505df6a481a488ab799a (patch)
tree3a38799686e0207c17c20504148d2e366a9935f3 /include/linux/percpu-rwsem.h
parent166e32606ef3508517ed2ea2f6087e5f332981c1 (diff)
use a mutex for percpu rwsemaphores
bcachefs is using a percpu rwsem to protect percpu data structures, and in userspace we don't have real percpu data structures - so we need to guard all access to them with a mutex.
Diffstat (limited to 'include/linux/percpu-rwsem.h')
-rw-r--r--include/linux/percpu-rwsem.h35
1 files changed, 8 insertions, 27 deletions
diff --git a/include/linux/percpu-rwsem.h b/include/linux/percpu-rwsem.h
index c233e3ce..f286f304 100644
--- a/include/linux/percpu-rwsem.h
+++ b/include/linux/percpu-rwsem.h
@@ -7,63 +7,44 @@
#include <linux/preempt.h>
struct percpu_rw_semaphore {
- pthread_rwlock_t lock;
+ pthread_mutex_t lock;
};
-#define DEFINE_STATIC_PERCPU_RWSEM(name) \
-static DEFINE_PER_CPU(unsigned int, __percpu_rwsem_rc_##name); \
-static struct percpu_rw_semaphore name = { \
- .rss = __RCU_SYNC_INITIALIZER(name.rss, RCU_SCHED_SYNC), \
- .read_count = &__percpu_rwsem_rc_##name, \
- .rw_sem = __RWSEM_INITIALIZER(name.rw_sem), \
- .writer = __RCUWAIT_INITIALIZER(name.writer), \
-}
-
-extern int __percpu_down_read(struct percpu_rw_semaphore *, int);
-extern void __percpu_up_read(struct percpu_rw_semaphore *);
-
static inline void percpu_down_read_preempt_disable(struct percpu_rw_semaphore *sem)
{
- pthread_rwlock_rdlock(&sem->lock);
- preempt_disable();
+ pthread_mutex_lock(&sem->lock);
}
static inline void percpu_down_read(struct percpu_rw_semaphore *sem)
{
- pthread_rwlock_rdlock(&sem->lock);
-}
-
-static inline int percpu_down_read_trylock(struct percpu_rw_semaphore *sem)
-{
- return !pthread_rwlock_tryrdlock(&sem->lock);
+ pthread_mutex_lock(&sem->lock);
}
static inline void percpu_up_read_preempt_enable(struct percpu_rw_semaphore *sem)
{
- preempt_enable();
- pthread_rwlock_unlock(&sem->lock);
+ pthread_mutex_unlock(&sem->lock);
}
static inline void percpu_up_read(struct percpu_rw_semaphore *sem)
{
- pthread_rwlock_unlock(&sem->lock);
+ pthread_mutex_unlock(&sem->lock);
}
static inline void percpu_down_write(struct percpu_rw_semaphore *sem)
{
- pthread_rwlock_wrlock(&sem->lock);
+ pthread_mutex_lock(&sem->lock);
}
static inline void percpu_up_write(struct percpu_rw_semaphore *sem)
{
- pthread_rwlock_unlock(&sem->lock);
+ pthread_mutex_unlock(&sem->lock);
}
static inline void percpu_free_rwsem(struct percpu_rw_semaphore *sem) {}
static inline int percpu_init_rwsem(struct percpu_rw_semaphore *sem)
{
- pthread_rwlock_init(&sem->lock, NULL);
+ pthread_mutex_init(&sem->lock, NULL);
return 0;
}