Class: Ractor::TVar
- Inherits:
-
Object
- Object
- Ractor::TVar
- Defined in:
- lib/ractor/tvar.rb,
lib/ractor/tvar/version.rb,
ext/ractor/tvar/tvar.c
Constant Summary collapse
- VERSION =
"0.4.0"
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.new(*args) ⇒ Object
580 581 582 583 584 585 586 |
# File 'ext/ractor/tvar/tvar.c', line 580
static VALUE
tvar_new(int argc, VALUE *argv, VALUE self)
{
VALUE init = Qnil;
rb_scan_args(argc, argv, "01", &init);
return tvar_new_(self, init);
}
|
Instance Method Details
#__increment__(inc) ⇒ Object
8 9 10 11 12 |
# File 'lib/ractor/tvar.rb', line 8 def __increment__ inc Ractor::atomically do self.value += inc end end |
#increment(*args) ⇒ Object
667 668 669 670 671 672 673 674 675 676 |
# File 'ext/ractor/tvar/tvar.c', line 667
static VALUE
tvar_value_increment(int argc, VALUE *argv, VALUE self)
{
switch (argc) {
case 0: return tvar_value_increment_(self, INT2FIX(1));
case 1: return tvar_value_increment_(self, argv[0]);
// todo: scan args
default: rb_raise(rb_eArgError, "2 or more arguments");
}
}
|
#value ⇒ Object
588 589 590 591 592 593 594 595 596 597 598 599 600 601 |
# File 'ext/ractor/tvar/tvar.c', line 588
static VALUE
tvar_value(VALUE self)
{
struct tx_logs *tx = tx_logs();
struct tvar_slot *slot = DATA_PTR(self);
if (tx->enabled) {
return tx_get(tx, slot, self);
}
else {
// TODO: warn on multi-ractors?
return slot->value;
}
}
|
#value=(val) ⇒ Object
603 604 605 606 607 608 609 610 611 612 613 614 615 |
# File 'ext/ractor/tvar/tvar.c', line 603
static VALUE
tvar_value_set(VALUE self, VALUE val)
{
if (RB_UNLIKELY(!rb_ractor_shareable_p(val))) {
rb_raise(rb_eArgError, "only shareable object are allowed");
}
struct tx_logs *tx = tx_logs();
tx_check(tx);
struct tvar_slot *slot = DATA_PTR(self);
tx_set(tx, val, slot, self);
return val;
}
|