Class: Concurrent::CAtomicFixnum
- Inherits:
-
Object
- Object
- Concurrent::CAtomicFixnum
- Defined in:
- ext/concurrent-ruby-ext/rb_concurrent.c
Constant Summary collapse
- MIN_VALUE =
CAtomicFixnum
LL2NUM(LLONG_MIN)
- MAX_VALUE =
LL2NUM(LLONG_MAX)
Instance Method Summary collapse
- #compare_and_set(rb_expect, rb_update) ⇒ Object
- #decrement(*args) ⇒ Object (also: #down)
- #increment(*args) ⇒ Object (also: #up)
- #initialize(*args) ⇒ Object constructor
- #update ⇒ Object
- #value ⇒ Object
- #value=(value) ⇒ Object
Constructor Details
#initialize(*args) ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'ext/concurrent-ruby-ext/atomic_fixnum.c', line 14
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
57 58 59 60 61 |
# File 'ext/concurrent-ruby-ext/atomic_fixnum.c', line 57
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);
}
|
#decrement(*args) ⇒ Object Also known as: down
46 47 48 49 50 51 52 53 54 55 |
# File 'ext/concurrent-ruby-ext/atomic_fixnum.c', line 46
VALUE method_atomic_fixnum_decrement(int argc, VALUE* argv, VALUE self) {
long long value = NUM2LL((VALUE) DATA_PTR(self));
long long delta = 1;
rb_check_arity(argc, 0, 1);
if (argc == 1) {
Check_Type(argv[0], T_FIXNUM);
delta = NUM2LL(argv[0]);
}
return method_atomic_fixnum_value_set(self, LL2NUM(value - delta));
}
|
#increment(*args) ⇒ Object Also known as: up
35 36 37 38 39 40 41 42 43 44 |
# File 'ext/concurrent-ruby-ext/atomic_fixnum.c', line 35
VALUE method_atomic_fixnum_increment(int argc, VALUE* argv, VALUE self) {
long long value = NUM2LL((VALUE) DATA_PTR(self));
long long delta = 1;
rb_check_arity(argc, 0, 1);
if (argc == 1) {
Check_Type(argv[0], T_FIXNUM);
delta = NUM2LL(argv[0]);
}
return method_atomic_fixnum_value_set(self, LL2NUM(value + delta));
}
|
#update ⇒ Object
63 64 65 66 67 68 69 70 71 72 |
# File 'ext/concurrent-ruby-ext/atomic_fixnum.c', line 63
VALUE method_atomic_fixnum_update(VALUE self) {
VALUE old_value, new_value;
for (;;) {
old_value = method_atomic_fixnum_value(self);
new_value = rb_yield(old_value);
if (ir_compare_and_set(self, old_value, new_value) == Qtrue) {
return new_value;
}
}
}
|
#value ⇒ Object
25 26 27 |
# File 'ext/concurrent-ruby-ext/atomic_fixnum.c', line 25
VALUE method_atomic_fixnum_value(VALUE self) {
return (VALUE) DATA_PTR(self);
}
|
#value=(value) ⇒ Object
29 30 31 32 33 |
# File 'ext/concurrent-ruby-ext/atomic_fixnum.c', line 29
VALUE method_atomic_fixnum_value_set(VALUE self, VALUE value) {
Check_Type(value, T_FIXNUM);
DATA_PTR(self) = (void *) value;
return(value);
}
|