Source
73
73
retval = 0;
74
74
if (lockref->count > 0) {
75
75
lockref->count++;
76
76
retval = 1;
77
77
}
78
78
spin_unlock(&lockref->lock);
79
79
return retval;
80
80
}
81
81
EXPORT_SYMBOL(lockref_get_not_zero);
82
82
83
+
/**
84
+
* lockref_put_not_zero - Decrements count unless count <= 1 before decrement
85
+
* @lockref: pointer to lockref structure
86
+
* Return: 1 if count updated successfully or 0 if count would become zero
87
+
*/
88
+
int lockref_put_not_zero(struct lockref *lockref)
89
+
{
90
+
int retval;
91
+
92
+
CMPXCHG_LOOP(
93
+
new.count--;
94
+
if (old.count <= 1)
95
+
return 0;
96
+
,
97
+
return 1;
98
+
);
99
+
100
+
spin_lock(&lockref->lock);
101
+
retval = 0;
102
+
if (lockref->count > 1) {
103
+
lockref->count--;
104
+
retval = 1;
105
+
}
106
+
spin_unlock(&lockref->lock);
107
+
return retval;
108
+
}
109
+
EXPORT_SYMBOL(lockref_put_not_zero);
110
+
83
111
/**
84
112
* lockref_get_or_lock - Increments count unless the count is 0 or dead
85
113
* @lockref: pointer to lockref structure
86
114
* Return: 1 if count updated successfully or 0 if count was zero
87
115
* and we got the lock instead.
88
116
*/
89
117
int lockref_get_or_lock(struct lockref *lockref)
90
118
{
91
119
CMPXCHG_LOOP(
92
120
new.count++;