From 9bea887493d388e3308b15642a366d4aa784a207 Mon Sep 17 00:00:00 2001 From: Alex Dowad Date: Sat, 9 Aug 2014 13:51:44 +0200 Subject: [PATCH 1/5] Remove now-unneeded test for GCC CAS from extconf.rb Previously, there was a preprocessor conditional directive in atomic_reference.c which checked for HAVE_GCC_CAS. It's gone now. So there is no reason to waste time while compiling. --- ext/extconf.rb | 8 -------- 1 file changed, 8 deletions(-) diff --git a/ext/extconf.rb b/ext/extconf.rb index 03faf6e..369dec4 100644 --- a/ext/extconf.rb +++ b/ext/extconf.rb @@ -37,12 +37,4 @@ def compiler_is_gcc end end -try_run(< Date: Sat, 9 Aug 2014 13:56:21 +0200 Subject: [PATCH 2/5] #get/#set have 'volatile' semantics when compiled with GCC --- ext/atomic_reference.c | 6 ++++++ ext/extconf.rb | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/ext/atomic_reference.c b/ext/atomic_reference.c index 0a09cc6..75f3751 100644 --- a/ext/atomic_reference.c +++ b/ext/atomic_reference.c @@ -37,11 +37,17 @@ static VALUE ir_initialize(int argc, VALUE* argv, VALUE self) { } static VALUE ir_get(VALUE self) { +#if HAVE_GCC_SYNC + __sync_synchronize(); +#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(); +#endif return new_value; } diff --git a/ext/extconf.rb b/ext/extconf.rb index 369dec4..6baa607 100644 --- a/ext/extconf.rb +++ b/ext/extconf.rb @@ -37,4 +37,11 @@ def compiler_is_gcc end end +try_run(< Date: Sat, 9 Aug 2014 14:04:51 +0200 Subject: [PATCH 3/5] #get/#set have 'volatile' semantics when compiled with MS Visual C++ --- ext/atomic_reference.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ext/atomic_reference.c b/ext/atomic_reference.c index 75f3751..c5b9f78 100644 --- a/ext/atomic_reference.c +++ b/ext/atomic_reference.c @@ -39,6 +39,8 @@ 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(); #endif return (VALUE) DATA_PTR(self); } @@ -47,6 +49,8 @@ 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(); #endif return new_value; } From 0318aa503fd856afed6a5936f0e3077ef5022cce Mon Sep 17 00:00:00 2001 From: Alex Dowad Date: Sat, 9 Aug 2014 14:05:08 +0200 Subject: [PATCH 4/5] #get/#set have 'volatile' semantics when compiled on Mac OS X --- ext/atomic_reference.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ext/atomic_reference.c b/ext/atomic_reference.c index c5b9f78..0aefad0 100644 --- a/ext/atomic_reference.c +++ b/ext/atomic_reference.c @@ -41,6 +41,8 @@ static VALUE ir_get(VALUE self) { __sync_synchronize(); #elif defined _MSC_VER MemoryBarrier(); +#elif __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 1050 + OSMemoryBarrier(); #endif return (VALUE) DATA_PTR(self); } @@ -51,6 +53,8 @@ static VALUE ir_set(VALUE self, VALUE new_value) { __sync_synchronize(); #elif defined _MSC_VER MemoryBarrier(); +#elif __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 1050 + OSMemoryBarrier(); #endif return new_value; } From a762883cfac9d0a0a87f49167e77be6ac502bbe9 Mon Sep 17 00:00:00 2001 From: Alex Dowad Date: Sat, 9 Aug 2014 14:06:49 +0200 Subject: [PATCH 5/5] #swap also has 'volatile' semantics --- ext/atomic_reference.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ext/atomic_reference.c b/ext/atomic_reference.c index 0aefad0..fbbbca1 100644 --- a/ext/atomic_reference.c +++ b/ext/atomic_reference.c @@ -60,9 +60,8 @@ static VALUE ir_set(VALUE self, VALUE 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; }