osq_lock.h 626 B

123456789101112131415161718192021222324252627
  1. #ifndef __LINUX_OSQ_LOCK_H
  2. #define __LINUX_OSQ_LOCK_H
  3. /*
  4. * An MCS like lock especially tailored for optimistic spinning for sleeping
  5. * lock implementations (mutex, rwsem, etc).
  6. */
  7. #define OSQ_UNLOCKED_VAL (0)
  8. struct optimistic_spin_queue {
  9. /*
  10. * Stores an encoded value of the CPU # of the tail node in the queue.
  11. * If the queue is empty, then it's set to OSQ_UNLOCKED_VAL.
  12. */
  13. atomic_t tail;
  14. };
  15. /* Init macro and function. */
  16. #define OSQ_LOCK_UNLOCKED { ATOMIC_INIT(OSQ_UNLOCKED_VAL) }
  17. static inline void osq_lock_init(struct optimistic_spin_queue *lock)
  18. {
  19. atomic_set(&lock->tail, OSQ_UNLOCKED_VAL);
  20. }
  21. #endif