/* 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 <waiman.long@hp.com>
*/ #ifndef __ASM_GENERIC_QRWLOCK_H #define __ASM_GENERIC_QRWLOCK_H
/** * 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
*/ staticinlineint queued_write_trylock(struct qrwlock *lock)
{ int cnts;
cnts = atomic_read(&lock->cnts); if (unlikely(cnts)) return 0;
return likely(atomic_try_cmpxchg_acquire(&lock->cnts, &cnts,
_QW_LOCKED));
} /** * queued_read_lock - acquire read lock of a queued rwlock * @lock: Pointer to queued rwlock structure
*/ staticinlinevoid queued_read_lock(struct qrwlock *lock)
{ int cnts;
cnts = atomic_add_return_acquire(_QR_BIAS, &lock->cnts); if (likely(!(cnts & _QW_WMASK))) return;
/* The slowpath will decrement the reader count, if necessary. */
queued_read_lock_slowpath(lock);
}
/** * queued_write_lock - acquire write lock of a queued rwlock * @lock : Pointer to queued rwlock structure
*/ staticinlinevoid queued_write_lock(struct qrwlock *lock)
{ int cnts = 0; /* Optimize for the unfair lock case where the fair flag is 0. */ if (likely(atomic_try_cmpxchg_acquire(&lock->cnts, &cnts, _QW_LOCKED))) return;
queued_write_lock_slowpath(lock);
}
/** * queued_read_unlock - release read lock of a queued rwlock * @lock : Pointer to queued rwlock structure
*/ staticinlinevoid queued_read_unlock(struct qrwlock *lock)
{ /* * Atomically decrement the reader count
*/
(void)atomic_sub_return_release(_QR_BIAS, &lock->cnts);
}
/** * queued_write_unlock - release write lock of a queued rwlock * @lock : Pointer to queued rwlock structure
*/ staticinlinevoid queued_write_unlock(struct qrwlock *lock)
{
smp_store_release(&lock->wlocked, 0);
}
/** * queued_rwlock_is_contended - check if the lock is contended * @lock : Pointer to queued rwlock structure * Return: 1 if lock contended, 0 otherwise
*/ staticinlineint queued_rwlock_is_contended(struct qrwlock *lock)
{ return arch_spin_is_locked(&lock->wait_lock);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.