0001
0002 #ifndef __LINUX_LOCKREF_H
0003 #define __LINUX_LOCKREF_H
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018 #include <linux/spinlock.h>
0019 #include <generated/bounds.h>
0020
0021 #define USE_CMPXCHG_LOCKREF \
0022 (IS_ENABLED(CONFIG_ARCH_USE_CMPXCHG_LOCKREF) && \
0023 IS_ENABLED(CONFIG_SMP) && SPINLOCK_SIZE <= 4)
0024
0025 struct lockref {
0026 union {
0027 #if USE_CMPXCHG_LOCKREF
0028 aligned_u64 lock_count;
0029 #endif
0030 struct {
0031 spinlock_t lock;
0032 int count;
0033 };
0034 };
0035 };
0036
0037 extern void lockref_get(struct lockref *);
0038 extern int lockref_put_return(struct lockref *);
0039 extern int lockref_get_not_zero(struct lockref *);
0040 extern int lockref_put_not_zero(struct lockref *);
0041 extern int lockref_put_or_lock(struct lockref *);
0042
0043 extern void lockref_mark_dead(struct lockref *);
0044 extern int lockref_get_not_dead(struct lockref *);
0045
0046
0047 static inline bool __lockref_is_dead(const struct lockref *l)
0048 {
0049 return ((int)l->count < 0);
0050 }
0051
0052 #endif