Skip to content
This repository was archived by the owner on Mar 15, 2022. It is now read-only.

Commit 793012e

Browse files
committed
#get/#set have 'volatile' semantics when compiled with GCC
1 parent 9bea887 commit 793012e

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

ext/atomic_reference.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,17 @@ static VALUE ir_initialize(int argc, VALUE* argv, VALUE self) {
3737
}
3838

3939
static VALUE ir_get(VALUE self) {
40+
#if HAVE_GCC_SYNC
41+
__sync_synchronize();
42+
#endif
4043
return (VALUE) DATA_PTR(self);
4144
}
4245

4346
static VALUE ir_set(VALUE self, VALUE new_value) {
4447
DATA_PTR(self) = (void *) new_value;
48+
#if HAVE_GCC_SYNC
49+
__sync_synchronize();
50+
#endif
4551
return new_value;
4652
}
4753

ext/extconf.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,11 @@ def compiler_is_gcc
3737
end
3838
end
3939

40+
try_run(<<CODE,$CFLAGS) && ($defs << '-DHAVE_GCC_SYNC')
41+
int main() {
42+
__sync_synchronize();
43+
return 0;
44+
}
45+
CODE
46+
4047
create_makefile(extension_name)

0 commit comments

Comments
 (0)