On 4 July 2013 16:13, Paolo Bonzini <pbonz...@redhat.com> wrote: > +#ifndef atomic_xchg > +#ifdef __ATOMIC_SEQ_CST > +#define atomic_xchg(ptr, i) ({ \ > + typeof(*ptr) _new = (i), _old; \ > + __atomic_exchange(ptr, &_new, &_old, __ATOMIC_SEQ_CST); \ > + _old; \ > +}) > +#elif defined __clang__ > +#define atomic_xchg(ptr, i) __sync_exchange(ptr, i) > +#else > +/* __sync_lock_test_and_set() is documented to be an acquire barrier only. > */ > +#define atomic_xchg(ptr, i) (smp_mb(), __sync_lock_test_and_set(ptr, i)) > +#endif > +#endif
Hi. I'm afraid this doesn't compile on MacOSX/clang: CC util/qemu-thread-posix.o util/qemu-thread-posix.c:351:13: error: too many arguments to function call, expected 3, have 4 if (atomic_xchg(&ev->value, EV_SET) == EV_BUSY) { ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /Users/pm215/src/qemu/include/qemu/atomic.h:174:42: note: expanded from macro 'atomic_xchg' __atomic_exchange(ptr, &_new, &_old, __ATOMIC_SEQ_CST); \ ~~~~~~~~~~~~~~~~~ ^ <built-in>:16:26: note: expanded from macro '__ATOMIC_SEQ_CST' #define __ATOMIC_SEQ_CST 5 ^ 1 error generated. make: *** [util/qemu-thread-posix.o] Error 1 I tried the '#elif defined__clang__' block instead and that doesn't work either: CC util/qemu-thread-posix.o util/qemu-thread-posix.c:351:13: warning: implicit declaration of function '__sync_exchange' is invalid in C99 [-Wimplicit-function-declaration] if (atomic_xchg(&ev->value, EV_SET) == EV_BUSY) { ^ /Users/pm215/src/qemu/include/qemu/atomic.h:179:32: note: expanded from macro 'atomic_xchg' #define atomic_xchg(ptr, i) __sync_exchange(ptr, i) ^ 1 warning generated. LINK qemu-nbd Undefined symbols for architecture x86_64: "___sync_exchange", referenced from: _qemu_event_set in libqemuutil.a(qemu-thread-posix.o) ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) make: *** [qemu-nbd] Error 1 It looks like we need to select the '#else' case for MacOSX... any suggestions about how best to do that? thanks -- PMM