summaryrefslogtreecommitdiff
path: root/include/ruby/ractor.h
diff options
context:
space:
mode:
authorKoichi Sasada <ko1@atdot.net>2025-09-24 02:34:45 +0900
committerKoichi Sasada <ko1@atdot.net>2025-10-23 13:08:26 +0900
commit45907b1b00d09ce2c40f5073ff540d8b63217d96 (patch)
treea2892e4cd0d6f8b37e081e56cf90d3725f91f4cc /include/ruby/ractor.h
parent271be0a2258061be486e24dc61994a3f4155d669 (diff)
add SET_SHAREABLE macros
* `RB_OBJ_SET_SHAREABLE(obj)` makes obj shareable. All of reachable objects from `obj` should be shareable. * `RB_OBJ_SET_FROZEN_SHAREABLE(obj)` same as above but freeze `obj` before making it shareable. Also `rb_gc_verify_shareable(obj)` is introduced to check the `obj` does not violate shareable rule (an shareable object only refers shareable objects) strictly. The rule has some exceptions (some shareable objects can refer to unshareable objects, such as a Ractor object (which is a shareable object) can refer to the Ractor local objects. To handle such case, `check_shareable` flag is also introduced. `STRICT_VERIFY_SHAREABLE` macro is also introduced to verify the strict shareable rule at `SET_SHAREABLE`.
Diffstat (limited to 'include/ruby/ractor.h')
-rw-r--r--include/ruby/ractor.h14
1 files changed, 14 insertions, 0 deletions
diff --git a/include/ruby/ractor.h b/include/ruby/ractor.h
index 7811616f6d..85222bbe11 100644
--- a/include/ruby/ractor.h
+++ b/include/ruby/ractor.h
@@ -261,4 +261,18 @@ rb_ractor_shareable_p(VALUE obj)
}
}
+// TODO: optimize on interpreter core
+#ifndef RB_OBJ_SET_SHAREABLE
+VALUE rb_obj_set_shareable(VALUE obj); // ractor.c
+#define RB_OBJ_SET_SHAREABLE(obj) rb_obj_set_shareable(obj)
+#endif
+
+static inline VALUE
+RB_OBJ_SET_FROZEN_SHAREABLE(VALUE obj)
+{
+ RB_OBJ_FREEZE(obj);
+ RB_OBJ_SET_SHAREABLE(obj);
+ return obj;
+}
+
#endif /* RUBY_RACTOR_H */