/* SPDX-License-Identifier: GPL-2.0-or-later */ /* * Queue read/write lock * * These use generic atomic and locking routines, but depend on a fair spinlock * implementation in order to be fair themselves. The implementation in * asm-generic/spinlock.h meets these requirements. * * (C) Copyright 2013-2014 Hewlett-Packard Development Company, L.P. * * Authors: Waiman Long <[email protected]> */ #ifndef __ASM_GENERIC_QRWLOCK_H #define __ASM_GENERIC_QRWLOCK_H #include <linux/atomic.h> #include <asm/barrier.h> #include <asm/processor.h> #include <asm-generic/qrwlock_types.h> /* Must be included from asm/spinlock.h after defining arch_spin_is_locked. */ /* * Writer states & reader shift and bias. */ #define _QW_WAITING … #define _QW_LOCKED … #define _QW_WMASK … #define _QR_SHIFT … #define _QR_BIAS … /* * External function declarations */ extern void queued_read_lock_slowpath(struct qrwlock *lock); extern void queued_write_lock_slowpath(struct qrwlock *lock); /** * queued_read_trylock - try to acquire read lock of a queued rwlock * @lock : Pointer to queued rwlock structure * Return: 1 if lock acquired, 0 if failed */ static inline int queued_read_trylock(struct qrwlock *lock) { … } /** * queued_write_trylock - try to acquire write lock of a queued rwlock * @lock : Pointer to queued rwlock structure * Return: 1 if lock acquired, 0 if failed */ static inline int queued_write_trylock(struct qrwlock *lock) { … } /** * queued_read_lock - acquire read lock of a queued rwlock * @lock: Pointer to queued rwlock structure */ static inline void queued_read_lock(struct qrwlock *lock) { … } /** * queued_write_lock - acquire write lock of a queued rwlock * @lock : Pointer to queued rwlock structure */ static inline void queued_write_lock(struct qrwlock *lock) { … } /** * queued_read_unlock - release read lock of a queued rwlock * @lock : Pointer to queued rwlock structure */ static inline void queued_read_unlock(struct qrwlock *lock) { … } /** * queued_write_unlock - release write lock of a queued rwlock * @lock : Pointer to queued rwlock structure */ static inline void queued_write_unlock(struct qrwlock *lock) { … } /** * queued_rwlock_is_contended - check if the lock is contended * @lock : Pointer to queued rwlock structure * Return: 1 if lock contended, 0 otherwise */ static inline int queued_rwlock_is_contended(struct qrwlock *lock) { … } /* * Remapping rwlock architecture specific functions to the corresponding * queued rwlock functions. */ #define arch_read_lock(l) … #define arch_write_lock(l) … #define arch_read_trylock(l) … #define arch_write_trylock(l) … #define arch_read_unlock(l) … #define arch_write_unlock(l) … #define arch_rwlock_is_contended(l) … #endif /* __ASM_GENERIC_QRWLOCK_H */