Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prefer platform specific memory barriers #708

Merged
merged 3 commits into from Jul 6, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 22 additions & 14 deletions ext/concurrent/atomic_reference.c
Expand Up @@ -9,6 +9,26 @@

#include "atomic_reference.h"

#if (defined(__i386__) || defined(__i386)) && (defined(__GNUC__) || defined(__INTEL_COMPILER))
#define memory_barrier() \
__asm__ __volatile__ ("lock; addl $0,0(%%esp)" : : : "memory", "cc")
#elif defined(__x86_64__) && (defined(__GNUC__) || defined(__INTEL_COMPILER))
#define memory_barrier() \
__asm__ __volatile__ ("lock; addl $0,0(%%rsp)" : : : "memory", "cc")
#elif defined(HAVE_GCC__ATOMIC_INT32_CAS)
#define memory_barrier() \
__atomic_thread_fence(__ATOMIC_SEQ_CST)
#elif (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1))
#define memory_barrier() \
__sync_synchronize();
#elif defined _MSC_VER
#define memory_barrier() \
MemoryBarrier();
#elif __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 1050
#define memory_barrier() \
OSMemoryBarrier();
#endif

void ir_mark(void *value) {
rb_gc_mark_maybe((VALUE) value);
}
Expand All @@ -27,25 +47,13 @@ VALUE ir_initialize(int argc, VALUE* argv, VALUE self) {
}

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
memory_barrier();
return (VALUE) DATA_PTR(self);
}

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
memory_barrier();
return new_value;
}

Expand Down
7 changes: 0 additions & 7 deletions ext/concurrent/extconf.rb
Expand Up @@ -43,13 +43,6 @@ def compiler_is_gcc
end
end

try_run(<<CODE,$CFLAGS) && ($defs << '-DHAVE_GCC_SYNC')
int main() {
__sync_synchronize();
return 0;
}
CODE

create_makefile('concurrent/' + EXTENSION_NAME)
rescue
create_dummy_makefile
Expand Down