Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion ext/concurrent-ruby-ext/atomic_boolean.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,16 @@ void atomic_boolean_mark(void *value) {
rb_gc_mark_maybe((VALUE) value);
}

const rb_data_type_t atomic_boolean_type = {
"Concurrent::CAtomicBoolean",
{
atomic_boolean_mark,
RUBY_NEVER_FREE,
},
};

VALUE atomic_boolean_allocate(VALUE klass) {
return rb_data_object_wrap(klass, (void *) Qfalse, atomic_boolean_mark, NULL);
return rb_data_typed_object_wrap(klass, (void *) Qfalse, &atomic_boolean_type);
}

VALUE method_atomic_boolean_initialize(int argc, VALUE* argv, VALUE self) {
Expand Down
10 changes: 9 additions & 1 deletion ext/concurrent-ruby-ext/atomic_fixnum.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,16 @@ void atomic_fixnum_mark(void *value) {
rb_gc_mark_maybe((VALUE) value);
}

const rb_data_type_t atomic_fixnum_type = {
"Concurrent::CAtomicFixnum",
{
atomic_fixnum_mark,
RUBY_NEVER_FREE,
},
};

VALUE atomic_fixnum_allocate(VALUE klass) {
return rb_data_object_wrap(klass, (void *) Qnil, atomic_fixnum_mark, NULL);
return rb_data_typed_object_wrap(klass, (void *) Qnil, &atomic_fixnum_type);
}

VALUE method_atomic_fixnum_initialize(int argc, VALUE* argv, VALUE self) {
Expand Down
16 changes: 14 additions & 2 deletions ext/concurrent-ruby-ext/atomic_reference.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,16 @@ void ir_mark(void *value) {
rb_gc_mark_maybe((VALUE) value);
}

const rb_data_type_t ir_type = {
"Concurrent::CAtomicReference",
{
ir_mark,
RUBY_NEVER_FREE,
},
};

VALUE ir_alloc(VALUE klass) {
return rb_data_object_wrap(klass, (void *) Qnil, ir_mark, NULL);
return rb_data_typed_object_wrap(klass, (void *) Qnil, &ir_type);
}

VALUE ir_initialize(int argc, VALUE* argv, VALUE self) {
Expand Down Expand Up @@ -78,7 +86,11 @@ VALUE ir_get_and_set(VALUE self, VALUE new_value) {
}

VALUE ir_compare_and_set(volatile VALUE self, VALUE expect_value, VALUE new_value) {
#if defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 1050
#if defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 101200
if (atomic_compare_exchange_strong_explicit((_Atomic uintptr_t *)&DATA_PTR(self), &expect_value, new_value, memory_order_seq_cst, memory_order_seq_cst)) {
return Qtrue;
}
#elif defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 1050
if (OSAtomicCompareAndSwap64(expect_value, new_value, &DATA_PTR(self))) {
return Qtrue;
}
Expand Down
3 changes: 3 additions & 0 deletions ext/concurrent-ruby-ext/atomic_reference.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
#include <atomic.h>
#endif

#if defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 101200
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can change this to a check for C11 atomics since that's what this is using.
Not sure what's a good way to test that though.
Maybe have_header 'stdatomic.h'?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably.

#include <stdatomic.h>
#endif
#ifdef HAVE_LIBKERN_OSATOMIC_H
#include <libkern/OSAtomic.h>
#endif
Expand Down
Loading