Class: Ractor::LVar

Inherits:
Object
  • Object
show all
Defined in:
lib/ractor/lvar/version.rb,
ext/ractor/lvar/lvar.c

Constant Summary collapse

VERSION =
"0.2.0"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.newObject



47
48
49
50
51
52
53
54
55
56
57
58
# File 'ext/ractor/lvar/lvar.c', line 47

static VALUE
ractor_lvar_new(VALUE self)
{
    VALUE default_proc = rb_block_given_p() ? rb_block_proc() : Qnil;

    struct ractor_lvar *lvar;
    VALUE lv = TypedData_Make_Struct(rb_cRactorLVar, struct ractor_lvar, &ractor_lvar_data_type, lvar);
    lvar->key = rb_ractor_local_storage_value_newkey();
    lvar->default_proc = RTEST(default_proc) ? rb_proc_isolate(default_proc) : Qfalse;
    FL_SET_RAW(lv, RUBY_FL_SHAREABLE);
    return lv;
}

Instance Method Details

#ractor_local_valueObject



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'ext/ractor/lvar/lvar.c', line 67

static VALUE
ractor_lvar_get(VALUE self)
{
    rb_ractor_local_key_t key = ractor_lvar_ptr(self)->key;
    VALUE val;
    if (rb_ractor_local_storage_value(key, &val)) {
        return val;
    }
    else {
        VALUE default_proc = ractor_lvar_ptr(self)->default_proc;
        if (default_proc) {
            val = rb_proc_call_with_block(default_proc, 0, NULL, Qnil);
            rb_ractor_local_storage_value_set(key, val);
            return val;
        }
        else {
            return Qnil;
        }
    }
}

#ractor_local_value=(val) ⇒ Object



88
89
90
91
92
93
94
# File 'ext/ractor/lvar/lvar.c', line 88

static VALUE
ractor_lvar_set(VALUE self, VALUE val)
{
    rb_ractor_local_key_t key = ractor_lvar_ptr(self)->key;
    rb_ractor_local_storage_value_set(key, val);
    return val;
}