diff options
author | Guillaume Tucker <guillaume.tucker@collabora.com> | 2019-06-24 17:22:35 +0100 |
---|---|---|
committer | Simon Ser <simon.ser@intel.com> | 2019-06-25 13:51:30 +0300 |
commit | b9b27e0955daefcd93d25caf4db7dd8d8afbd0c1 (patch) | |
tree | 5aedf307be0a82e633e3a7107c79171f5d8e0082 /tests/i915/gem_create.c | |
parent | 6cced294c77469b055d657b60e3051b56266491e (diff) |
i915/gem_create: use atomic_* instead of __sync_*
This fixes builds on some architectures, in particular MIPS which
doesn't have __sync_add_and_fetch_8 and __sync_val_compare_and_swap_8
for 64-bit variable handling.
* replace calls to the older __sync_* functions with the new atomic_*
standard ones
* use the _Atomic type modifier as required with stdatomic.h functions
* add dependency for gem_create on libatomic
Signed-off-by: Guillaume Tucker <guillaume.tucker@collabora.com>
Reviewed-by: Simon Ser <simon.ser@intel.com>
Diffstat (limited to 'tests/i915/gem_create.c')
-rw-r--r-- | tests/i915/gem_create.c | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/tests/i915/gem_create.c b/tests/i915/gem_create.c index 43cbf45f..9008cd8a 100644 --- a/tests/i915/gem_create.c +++ b/tests/i915/gem_create.c @@ -45,6 +45,7 @@ #include <sys/time.h> #include <getopt.h> #include <pthread.h> +#include <stdatomic.h> #include <drm.h> @@ -156,7 +157,14 @@ static void invalid_nonaligned_size(int fd) gem_close(fd, create.handle); } -static uint64_t get_npages(uint64_t *global, uint64_t npages) +static uint64_t atomic_compare_swap_u64(_Atomic(uint64_t) *ptr, + uint64_t oldval, uint64_t newval) +{ + atomic_compare_exchange_strong(ptr, &oldval, newval); + return oldval; +} + +static uint64_t get_npages(_Atomic(uint64_t) *global, uint64_t npages) { uint64_t try, old, max; @@ -165,13 +173,13 @@ static uint64_t get_npages(uint64_t *global, uint64_t npages) old = max; try = 1 + npages % (max / 2); max -= try; - } while ((max = __sync_val_compare_and_swap(global, old, max)) != old); + } while ((max = atomic_compare_swap_u64(global, old, max)) != old); return try; } struct thread_clear { - uint64_t max; + _Atomic(uint64_t) max; int timeout; int i915; }; @@ -202,7 +210,7 @@ static void *thread_clear(void *data) } gem_close(i915, create.handle); - __sync_add_and_fetch(&arg->max, npages); + atomic_fetch_add(&arg->max, npages); } return NULL; |