mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-12-28 16:56:26 +00:00
7c22309821
struct optimistic_spin_node is private to the implementation. Move it into the C file to ensure nothing is accessing it. Signed-off-by: David Laight <david.laight@aculab.com> Acked-by: Waiman Long <longman@redhat.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
37 lines
912 B
C
37 lines
912 B
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
#ifndef __LINUX_OSQ_LOCK_H
|
|
#define __LINUX_OSQ_LOCK_H
|
|
|
|
/*
|
|
* An MCS like lock especially tailored for optimistic spinning for sleeping
|
|
* lock implementations (mutex, rwsem, etc).
|
|
*/
|
|
|
|
struct optimistic_spin_queue {
|
|
/*
|
|
* Stores an encoded value of the CPU # of the tail node in the queue.
|
|
* If the queue is empty, then it's set to OSQ_UNLOCKED_VAL.
|
|
*/
|
|
atomic_t tail;
|
|
};
|
|
|
|
#define OSQ_UNLOCKED_VAL (0)
|
|
|
|
/* Init macro and function. */
|
|
#define OSQ_LOCK_UNLOCKED { ATOMIC_INIT(OSQ_UNLOCKED_VAL) }
|
|
|
|
static inline void osq_lock_init(struct optimistic_spin_queue *lock)
|
|
{
|
|
atomic_set(&lock->tail, OSQ_UNLOCKED_VAL);
|
|
}
|
|
|
|
extern bool osq_lock(struct optimistic_spin_queue *lock);
|
|
extern void osq_unlock(struct optimistic_spin_queue *lock);
|
|
|
|
static inline bool osq_is_locked(struct optimistic_spin_queue *lock)
|
|
{
|
|
return atomic_read(&lock->tail) != OSQ_UNLOCKED_VAL;
|
|
}
|
|
|
|
#endif
|