Use __sync_val_compare_and_swap
__sync_lock_test_and_set
, not __sync_synchronize
.
This has the same function as InterlockedExchange.
Something like this (untested code!):
template<typename T> T InterlockedExchange(T& data, T& new_val) { return __sync_lock_test_and_set(&data, new_val); }
EDIT:
Oi, I read incorrectly, you wanted InterlockedExchange, not InterlockedCompareExchange ... so this is __sync_lock_test_and_set
(the name is misleading Intel number, but this is exactly what you want).
See here at the bottom of the page.
Damon source share