Class: Concurrent::CAtomicFixnum

Inherits:
Object
  • Object
show all
Defined in:
ext/concurrent/rb_concurrent.c

Constant Summary collapse

MIN_VALUE =

CAtomicFixnum

LL2NUM(LLONG_MIN)
MAX_VALUE =
LL2NUM(LLONG_MAX)

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'ext/concurrent/atomic_fixnum.c', line 15

VALUE method_atomic_fixnum_initialize(int argc, VALUE* argv, VALUE self) {
  VALUE value = LL2NUM(0);
  rb_check_arity(argc, 0, 1);
  if (argc == 1) {
    Check_Type(argv[0], T_FIXNUM);
    value = argv[0];
  }
  DATA_PTR(self) = (void *) value;
  return(self);
}

Instance Method Details

#compare_and_set(rb_expect, rb_update) ⇒ Object



46
47
48
49
50
# File 'ext/concurrent/atomic_fixnum.c', line 46

VALUE method_atomic_fixnum_compare_and_set(VALUE self, VALUE rb_expect, VALUE rb_update) {
  Check_Type(rb_expect, T_FIXNUM);
  Check_Type(rb_update, T_FIXNUM);
  return ir_compare_and_set(self, rb_expect, rb_update);
}

#decrementObject Also known as: down



41
42
43
44
# File 'ext/concurrent/atomic_fixnum.c', line 41

VALUE method_atomic_fixnum_decrement(VALUE self) {
  long long value = NUM2LL((VALUE) DATA_PTR(self));
  return method_atomic_fixnum_value_set(self, LL2NUM(value - 1));
}

#incrementObject Also known as: up



36
37
38
39
# File 'ext/concurrent/atomic_fixnum.c', line 36

VALUE method_atomic_fixnum_increment(VALUE self) {
  long long value = NUM2LL((VALUE) DATA_PTR(self));
  return method_atomic_fixnum_value_set(self, LL2NUM(value + 1));
}

#valueObject



26
27
28
# File 'ext/concurrent/atomic_fixnum.c', line 26

VALUE method_atomic_fixnum_value(VALUE self) {
  return (VALUE) DATA_PTR(self);
}

#value=(value) ⇒ Object



30
31
32
33
34
# File 'ext/concurrent/atomic_fixnum.c', line 30

VALUE method_atomic_fixnum_value_set(VALUE self, VALUE value) {
  Check_Type(value, T_FIXNUM);
  DATA_PTR(self) = (void *) value;
  return(value);
}