atomic: fix atomic_add_unless() fallback's return value

According to the kernel documentation:
  Returns non-zero if @v was not @u, and zero otherwise.

Fixes: 63fc571863 ("atomic: add atomic_add_unless()")
Closes: https://gitlab.freedesktop.org/mesa/drm/issues/17
Signed-off-by: David Shao <davshao@gmail.com>
Reviewed-by: Eric Engestrom <eric@engestrom.ch>

[Eric: fix its callers to maintain current behaviour]
Signed-off-by: Eric Engestrom <eric@engestrom.ch>
main
Eric Engestrom 2017-03-15 23:27:25 +00:00 committed by Matt Turner
parent cf54ebf6cf
commit 3ff3d59ed9
2 changed files with 21 additions and 19 deletions

View File

@ -1382,7 +1382,9 @@ static void drm_intel_gem_bo_unreference(drm_intel_bo *bo)
assert(atomic_read(&bo_gem->refcount) > 0); assert(atomic_read(&bo_gem->refcount) > 0);
if (atomic_add_unless(&bo_gem->refcount, -1, 1)) { if (atomic_add_unless(&bo_gem->refcount, -1, 1))
return;
drm_intel_bufmgr_gem *bufmgr_gem = drm_intel_bufmgr_gem *bufmgr_gem =
(drm_intel_bufmgr_gem *) bo->bufmgr; (drm_intel_bufmgr_gem *) bo->bufmgr;
struct timespec time; struct timespec time;
@ -1397,7 +1399,6 @@ static void drm_intel_gem_bo_unreference(drm_intel_bo *bo)
} }
pthread_mutex_unlock(&bufmgr_gem->lock); pthread_mutex_unlock(&bufmgr_gem->lock);
}
} }
static int drm_intel_gem_bo_map(drm_intel_bo *bo, int write_enable) static int drm_intel_gem_bo_map(drm_intel_bo *bo, int write_enable)
@ -3377,7 +3378,9 @@ drm_intel_bufmgr_gem_unref(drm_intel_bufmgr *bufmgr)
{ {
drm_intel_bufmgr_gem *bufmgr_gem = (drm_intel_bufmgr_gem *)bufmgr; drm_intel_bufmgr_gem *bufmgr_gem = (drm_intel_bufmgr_gem *)bufmgr;
if (atomic_add_unless(&bufmgr_gem->refcount, -1, 1)) { if (atomic_add_unless(&bufmgr_gem->refcount, -1, 1))
return;
pthread_mutex_lock(&bufmgr_list_mutex); pthread_mutex_lock(&bufmgr_list_mutex);
if (atomic_dec_and_test(&bufmgr_gem->refcount)) { if (atomic_dec_and_test(&bufmgr_gem->refcount)) {
@ -3386,7 +3389,6 @@ drm_intel_bufmgr_gem_unref(drm_intel_bufmgr *bufmgr)
} }
pthread_mutex_unlock(&bufmgr_list_mutex); pthread_mutex_unlock(&bufmgr_list_mutex);
}
} }
drm_public void *drm_intel_gem_bo_map__gtt(drm_intel_bo *bo) drm_public void *drm_intel_gem_bo_map__gtt(drm_intel_bo *bo)

View File

@ -108,7 +108,7 @@ static inline int atomic_add_unless(atomic_t *v, int add, int unless)
c = atomic_read(v); c = atomic_read(v);
while (c != unless && (old = atomic_cmpxchg(v, c, c + add)) != c) while (c != unless && (old = atomic_cmpxchg(v, c, c + add)) != c)
c = old; c = old;
return c == unless; return c != unless;
} }
#endif #endif