diff --git a/ext/atomic_reference.c b/ext/atomic_reference.c index 0a09cc6..fbbbca1 100644 --- a/ext/atomic_reference.c +++ b/ext/atomic_reference.c @@ -37,18 +37,31 @@ static VALUE ir_initialize(int argc, VALUE* argv, VALUE self) { } static VALUE ir_get(VALUE self) { +#if HAVE_GCC_SYNC + __sync_synchronize(); +#elif defined _MSC_VER + MemoryBarrier(); +#elif __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 1050 + OSMemoryBarrier(); +#endif return (VALUE) DATA_PTR(self); } static VALUE ir_set(VALUE self, VALUE new_value) { DATA_PTR(self) = (void *) new_value; +#if HAVE_GCC_SYNC + __sync_synchronize(); +#elif defined _MSC_VER + MemoryBarrier(); +#elif __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 1050 + OSMemoryBarrier(); +#endif return new_value; } static VALUE ir_get_and_set(VALUE self, VALUE new_value) { - VALUE old_value; - old_value = (VALUE) DATA_PTR(self); - DATA_PTR(self) = (void *) new_value; + VALUE old_value = ir_get(self); + ir_set(self, new_value); return old_value; } diff --git a/ext/extconf.rb b/ext/extconf.rb index 03faf6e..6baa607 100644 --- a/ext/extconf.rb +++ b/ext/extconf.rb @@ -37,11 +37,10 @@ def compiler_is_gcc end end -try_run(<