Class: AtomicRuby::Atom
- Inherits:
-
Object
- Object
- AtomicRuby::Atom
- Defined in:
- lib/atomic-ruby/atom.rb,
ext/atomic_ruby/atomic_ruby.c
Instance Method Summary collapse
- #_initialize(value) ⇒ Object
- #_swap ⇒ Object
- #_value ⇒ Object
-
#initialize(value) ⇒ Atom
constructor
A new instance of Atom.
- #swap(&block) ⇒ Object
- #value ⇒ Object
Constructor Details
#initialize(value) ⇒ Atom
Returns a new instance of Atom.
5 6 7 8 9 |
# File 'lib/atomic-ruby/atom.rb', line 5 def initialize(value) _initialize(value) Ractor.make_shareable(self) end |
Instance Method Details
#_initialize(value) ⇒ Object
44 45 46 47 48 49 |
# File 'ext/atomic_ruby/atomic_ruby.c', line 44
static VALUE rb_cAtom_initialize(VALUE self, VALUE value) {
atomic_ruby_atom_t *atomic_ruby_atom;
TypedData_Get_Struct(self, atomic_ruby_atom_t, &atomic_ruby_atom_type, atomic_ruby_atom);
atomic_ruby_atom->value = value;
return self;
}
|
#_swap ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'ext/atomic_ruby/atomic_ruby.c', line 57
static VALUE rb_cAtom_swap(VALUE self) {
atomic_ruby_atom_t *atomic_ruby_atom;
TypedData_Get_Struct(self, atomic_ruby_atom_t, &atomic_ruby_atom_type, atomic_ruby_atom);
VALUE expected_old_value, new_value;
do {
expected_old_value = atomic_ruby_atom->value;
new_value = rb_yield(expected_old_value);
} while (RUBY_ATOMIC_VALUE_CAS(atomic_ruby_atom->value, expected_old_value, new_value) != expected_old_value);
return new_value;
}
|
#_value ⇒ Object
51 52 53 54 55 |
# File 'ext/atomic_ruby/atomic_ruby.c', line 51
static VALUE rb_cAtom_value(VALUE self) {
atomic_ruby_atom_t *atomic_ruby_atom;
TypedData_Get_Struct(self, atomic_ruby_atom_t, &atomic_ruby_atom_type, atomic_ruby_atom);
return (VALUE)RUBY_ATOMIC_PTR_LOAD(atomic_ruby_atom->value);
}
|
#swap(&block) ⇒ Object
15 16 17 |
# File 'lib/atomic-ruby/atom.rb', line 15 def swap(&block) _swap(&block) end |
#value ⇒ Object
11 12 13 |
# File 'lib/atomic-ruby/atom.rb', line 11 def value _value end |