summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJerome Marchand <jmarchan@redhat.com>2011-01-05 16:57:37 +0100
committerJens Axboe <jaxboe@fusionio.com>2011-01-05 16:57:37 +0100
commite4a683c899cd5a49f8d684a054c95bd115a0c005 (patch)
treec7e79e24199a5ed34a488b06cfd3fa890637db7d /lib
parentbio-integrity: mark kintegrityd_wq highpri and CPU intensive (diff)
downloadlinux-e4a683c899cd5a49f8d684a054c95bd115a0c005.tar.xz
linux-e4a683c899cd5a49f8d684a054c95bd115a0c005.zip
kref: add kref_test_and_get
Add kref_test_and_get() function, which atomically add a reference only if refcount is not zero. This prevent to add a reference to an object that is already being removed. Signed-off-by: Jerome Marchand <jmarchan@redhat.com> Cc: stable@kernel.org Signed-off-by: Jens Axboe <jaxboe@fusionio.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/kref.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/kref.c b/lib/kref.c
index d3d227a08a4b..e7a6e1067122 100644
--- a/lib/kref.c
+++ b/lib/kref.c
@@ -37,6 +37,18 @@ void kref_get(struct kref *kref)
}
/**
+ * kref_test_and_get - increment refcount for object only if refcount is not
+ * zero.
+ * @kref: object.
+ *
+ * Return non-zero if the refcount was incremented, 0 otherwise
+ */
+int kref_test_and_get(struct kref *kref)
+{
+ return atomic_inc_not_zero(&kref->refcount);
+}
+
+/**
* kref_put - decrement refcount for object.
* @kref: object.
* @release: pointer to the function that will clean up the object when the