diff options
author | Kent Overstreet <kent.overstreet@gmail.com> | 2018-06-01 17:17:16 -0400 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@gmail.com> | 2018-06-01 17:33:19 -0400 |
commit | bb6f4111fbfe2550eb7b583586e732a473ba62f0 (patch) | |
tree | 72f01b9dbeaba544efb75016309c0da6839913ae /include/linux/percpu-rwsem.h | |
parent | d7bfc55d236363c7f9d2edee7437202497e462b5 (diff) |
Update bcachefs sources to 9abf628c70 bcachefs: Fix a spurious error in fsck
Diffstat (limited to 'include/linux/percpu-rwsem.h')
-rw-r--r-- | include/linux/percpu-rwsem.h | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/include/linux/percpu-rwsem.h b/include/linux/percpu-rwsem.h new file mode 100644 index 00000000..c233e3ce --- /dev/null +++ b/include/linux/percpu-rwsem.h @@ -0,0 +1,72 @@ + +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _LINUX_PERCPU_RWSEM_H +#define _LINUX_PERCPU_RWSEM_H + +#include <pthread.h> +#include <linux/preempt.h> + +struct percpu_rw_semaphore { + pthread_rwlock_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(); +} + +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); +} + +static inline void percpu_up_read_preempt_enable(struct percpu_rw_semaphore *sem) +{ + preempt_enable(); + pthread_rwlock_unlock(&sem->lock); +} + +static inline void percpu_up_read(struct percpu_rw_semaphore *sem) +{ + pthread_rwlock_unlock(&sem->lock); +} + +static inline void percpu_down_write(struct percpu_rw_semaphore *sem) +{ + pthread_rwlock_wrlock(&sem->lock); +} + +static inline void percpu_up_write(struct percpu_rw_semaphore *sem) +{ + pthread_rwlock_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); + return 0; +} + +#define percpu_rwsem_assert_held(sem) do {} while (0) + +#endif |