diff options
Diffstat (limited to 'include/linux/lockref.h')
| -rw-r--r-- | include/linux/lockref.h | 62 |
1 files changed, 15 insertions, 47 deletions
diff --git a/include/linux/lockref.h b/include/linux/lockref.h index 01233e01627a..f279ed9a9163 100644 --- a/include/linux/lockref.h +++ b/include/linux/lockref.h | |||
| @@ -17,55 +17,23 @@ | |||
| 17 | #include <linux/spinlock.h> | 17 | #include <linux/spinlock.h> |
| 18 | 18 | ||
| 19 | struct lockref { | 19 | struct lockref { |
| 20 | spinlock_t lock; | 20 | union { |
| 21 | unsigned int count; | 21 | #ifdef CONFIG_CMPXCHG_LOCKREF |
| 22 | aligned_u64 lock_count; | ||
| 23 | #endif | ||
| 24 | struct { | ||
| 25 | spinlock_t lock; | ||
| 26 | unsigned int count; | ||
| 27 | }; | ||
| 28 | }; | ||
| 22 | }; | 29 | }; |
| 23 | 30 | ||
| 24 | /** | 31 | extern void lockref_get(struct lockref *); |
| 25 | * lockref_get - Increments reference count unconditionally | 32 | extern int lockref_get_not_zero(struct lockref *); |
| 26 | * @lockcnt: pointer to lockref structure | 33 | extern int lockref_get_or_lock(struct lockref *); |
| 27 | * | 34 | extern int lockref_put_or_lock(struct lockref *); |
| 28 | * This operation is only valid if you already hold a reference | ||
| 29 | * to the object, so you know the count cannot be zero. | ||
| 30 | */ | ||
| 31 | static inline void lockref_get(struct lockref *lockref) | ||
| 32 | { | ||
| 33 | spin_lock(&lockref->lock); | ||
| 34 | lockref->count++; | ||
| 35 | spin_unlock(&lockref->lock); | ||
| 36 | } | ||
| 37 | |||
| 38 | /** | ||
| 39 | * lockref_get_not_zero - Increments count unless the count is 0 | ||
| 40 | * @lockcnt: pointer to lockref structure | ||
| 41 | * Return: 1 if count updated successfully or 0 if count is 0 | ||
| 42 | */ | ||
| 43 | static inline int lockref_get_not_zero(struct lockref *lockref) | ||
| 44 | { | ||
| 45 | int retval = 0; | ||
| 46 | |||
| 47 | spin_lock(&lockref->lock); | ||
| 48 | if (lockref->count) { | ||
| 49 | lockref->count++; | ||
| 50 | retval = 1; | ||
| 51 | } | ||
| 52 | spin_unlock(&lockref->lock); | ||
| 53 | return retval; | ||
| 54 | } | ||
| 55 | 35 | ||
| 56 | /** | 36 | extern void lockref_mark_dead(struct lockref *); |
| 57 | * lockref_put_or_lock - decrements count unless count <= 1 before decrement | 37 | extern int lockref_get_not_dead(struct lockref *); |
| 58 | * @lockcnt: pointer to lockref structure | ||
| 59 | * Return: 1 if count updated successfully or 0 if count <= 1 and lock taken | ||
| 60 | */ | ||
| 61 | static inline int lockref_put_or_lock(struct lockref *lockref) | ||
| 62 | { | ||
| 63 | spin_lock(&lockref->lock); | ||
| 64 | if (lockref->count <= 1) | ||
| 65 | return 0; | ||
| 66 | lockref->count--; | ||
| 67 | spin_unlock(&lockref->lock); | ||
| 68 | return 1; | ||
| 69 | } | ||
| 70 | 38 | ||
| 71 | #endif /* __LINUX_LOCKREF_H */ | 39 | #endif /* __LINUX_LOCKREF_H */ |
