Staging
v0.5.1
https://github.com/torvalds/linux
Raw File
Tip revision: 19583ca584d6f574384e17fe7613dfaeadcdc4a6 authored by Linus Torvalds on 03 August 2014, 22:25:02 UTC
Linux 3.16
Tip revision: 19583ca
osq_lock.h
#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).
 */

#define OSQ_UNLOCKED_VAL (0)

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;
};

/* 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);
}

#endif
back to top