aboutsummaryrefslogtreecommitdiffstats
path: root/include/drm/drmP.h
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2013-08-06 09:59:46 +0100
committerDave Airlie <airlied@redhat.com>2013-08-07 10:07:17 +1000
commit7fc65eb731cda8304865669166fb9a4c519bee69 (patch)
treeeeeff7e07e01ccdef46a1f2b6c82c9624f53acb0 /include/drm/drmP.h
parentdrm/gem: create drm_gem_dumb_destroy (diff)
downloadlinux-dev-7fc65eb731cda8304865669166fb9a4c519bee69.tar.xz
linux-dev-7fc65eb731cda8304865669166fb9a4c519bee69.zip
drm: Apply kref_put_mutex() optimisations to drm_gem_object_unreference_unlocked()
We can apply the same optimisation tricks as kref_put_mutex() in our local equivalent function. However, we have a different locking semantic (we unlock ourselves, in kref_put_mutex() the callee unlocks) so that we can use the same callbacks for both locked and unlocked kref_put()s and so can not simply convert to using kref_put_mutex() directly. Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk> Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch> Signed-off-by: Dave Airlie <airlied@redhat.com>
Diffstat (limited to 'include/drm/drmP.h')
-rw-r--r--include/drm/drmP.h6
1 files changed, 4 insertions, 2 deletions
diff --git a/include/drm/drmP.h b/include/drm/drmP.h
index a029dea13f48..3b7fda557b8d 100644
--- a/include/drm/drmP.h
+++ b/include/drm/drmP.h
@@ -1629,10 +1629,12 @@ drm_gem_object_unreference(struct drm_gem_object *obj)
static inline void
drm_gem_object_unreference_unlocked(struct drm_gem_object *obj)
{
- if (obj != NULL) {
+ if (obj && !atomic_add_unless(&obj->refcount.refcount, -1, 1)) {
struct drm_device *dev = obj->dev;
+
mutex_lock(&dev->struct_mutex);
- kref_put(&obj->refcount, drm_gem_object_free);
+ if (likely(atomic_dec_and_test(&obj->refcount.refcount)))
+ drm_gem_object_free(&obj->refcount);
mutex_unlock(&dev->struct_mutex);
}
}