diff options
| author | Zhi Wang <zhi.a.wang@intel.com> | 2018-05-14 00:19:07 +0300 |
|---|---|---|
| committer | Zhi Wang <zhi.a.wang@intel.com> | 2018-05-14 00:22:01 +0300 |
| commit | bba9525520b6028ecbe7486e13216e9ede8636be (patch) | |
| tree | f82f4f2adecf6f97933c88050682d44336db783e /lib/lockref.c | |
| parent | cb8ba171ae6c1e4f5fa027162c06d50fc2b43055 (diff) | |
| parent | 0c79f9cb77eae28d48a4f9fc1b3341aacbbd260c (diff) | |
| download | linux-bba9525520b6028ecbe7486e13216e9ede8636be.tar.xz | |
Merge branch 'drm-intel-next-queued' into gvt-next
Signed-off-by: Zhi Wang <zhi.a.wang@intel.com>
Diffstat (limited to 'lib/lockref.c')
| -rw-r--r-- | lib/lockref.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/lib/lockref.c b/lib/lockref.c index 47169ed7e964..3d468b53d4c9 100644 --- a/lib/lockref.c +++ b/lib/lockref.c @@ -81,6 +81,34 @@ int lockref_get_not_zero(struct lockref *lockref) EXPORT_SYMBOL(lockref_get_not_zero); /** + * lockref_put_not_zero - Decrements count unless count <= 1 before decrement + * @lockref: pointer to lockref structure + * Return: 1 if count updated successfully or 0 if count would become zero + */ +int lockref_put_not_zero(struct lockref *lockref) +{ + int retval; + + CMPXCHG_LOOP( + new.count--; + if (old.count <= 1) + return 0; + , + return 1; + ); + + spin_lock(&lockref->lock); + retval = 0; + if (lockref->count > 1) { + lockref->count--; + retval = 1; + } + spin_unlock(&lockref->lock); + return retval; +} +EXPORT_SYMBOL(lockref_put_not_zero); + +/** * lockref_get_or_lock - Increments count unless the count is 0 or dead * @lockref: pointer to lockref structure * Return: 1 if count updated successfully or 0 if count was zero |
