lockref.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #ifndef __LINUX_LOCKREF_H
  2. #define __LINUX_LOCKREF_H
  3. /*
  4. * Locked reference counts.
  5. *
  6. * These are different from just plain atomic refcounts in that they
  7. * are atomic with respect to the spinlock that goes with them. In
  8. * particular, there can be implementations that don't actually get
  9. * the spinlock for the common decrement/increment operations, but they
  10. * still have to check that the operation is done semantically as if
  11. * the spinlock had been taken (using a cmpxchg operation that covers
  12. * both the lock and the count word, or using memory transactions, for
  13. * example).
  14. */
  15. #include <linux/spinlock.h>
  16. struct lockref {
  17. union {
  18. #ifdef CONFIG_CMPXCHG_LOCKREF
  19. aligned_u64 lock_count;
  20. #endif
  21. struct {
  22. spinlock_t lock;
  23. unsigned int count;
  24. };
  25. };
  26. };
  27. extern void lockref_get(struct lockref *);
  28. extern int lockref_get_not_zero(struct lockref *);
  29. extern int lockref_get_or_lock(struct lockref *);
  30. extern int lockref_put_or_lock(struct lockref *);
  31. extern void lockref_mark_dead(struct lockref *);
  32. extern int lockref_get_not_dead(struct lockref *);
  33. #endif /* __LINUX_LOCKREF_H */