1#ifndef RUBY_RACTOR_CORE_H
2#define RUBY_RACTOR_CORE_H
3#include "internal/gc.h"
11#ifndef RACTOR_CHECK_MODE
12#define RACTOR_CHECK_MODE (VM_CHECK_MODE || RUBY_DEBUG) && (SIZEOF_UINT64_T == SIZEOF_VALUE)
16#define RUBY_TYPED_FROZEN_SHAREABLE_NO_REC RUBY_FL_FINALIZE
23 rb_nativethread_lock_t lock;
25#if RACTOR_CHECK_MODE > 0
33 struct ccan_list_head waiters;
36 VALUE default_port_value;
43 struct ccan_list_head off_queue_baskets;
46 struct ccan_list_head monitors;
85 VALUE *registered_marks;
86 size_t registered_marks_cnt, registered_marks_capa;
95 struct ccan_list_head set;
97 unsigned int blocking_cnt;
116 VALUE thgroup_default;
121 enum ractor_status status_;
123 struct ccan_list_node vmlr_node;
124 bool in_terminated_set;
132 rb_serial_t next_ec_serial;
136 VALUE local_storage_store_lock;
147 bool malloc_gc_disabled;
160 void *creating_child_objspace;
166void rb_ractor_mark_terminated_join_value(
rb_ractor_t *r);
174enum ractor_wakeup_status {
182 enum ractor_wakeup_status wakeup_status;
184 struct ccan_list_node node;
188 const rb_hrtime_t *end;
208int rb_ractor_living_thread_num(
const rb_ractor_t *);
209VALUE rb_ractor_thread_list(
void);
210bool rb_ractor_p(
VALUE rv);
225void rb_ractor_blocking_threads_inc(
rb_ractor_t *r,
const char *file,
int line);
226void rb_ractor_blocking_threads_dec(
rb_ractor_t *r,
const char *file,
int line);
228void rb_ractor_vm_barrier_interrupt_running_thread(
rb_ractor_t *r);
229void rb_ractor_terminate_interrupt_main_thread(
rb_ractor_t *r);
230void rb_ractor_terminate_all(
void);
231bool rb_ractor_main_p_(
void);
234VALUE rb_ractor_require(
VALUE feature,
bool silent);
240RUBY_SYMBOL_EXPORT_BEGIN
241void rb_ractor_finish_marking(
bool full_mark);
243bool rb_ractor_shareable_p_continue(
VALUE obj);
249RUBY_SYMBOL_EXPORT_END
252rb_ractor_main_p(
void)
254 if (ruby_single_main_ractor) {
258 return rb_ractor_main_p_();
263rb_ractor_status_p(
rb_ractor_t *r,
enum ractor_status status)
265 return r->status_ == status;
271 r->threads.sleeper++;
277 r->threads.sleeper--;
283 r->threads.sleeper = 0;
289 return r->threads.sleeper;
295 RUBY_DEBUG_LOG(
"th:%d->%u%s",
296 cr->threads.running_ec ? (
int)rb_th_serial(cr->threads.running_ec->thread_ptr) : -1,
297 rb_th_serial(th), cr->threads.running_ec == th->ec ?
" (same)" :
"");
299 if (cr->threads.running_ec != th->ec || always_reset) {
300 th->running_time_us = 0;
303 if (cr->threads.running_ec != th->ec) {
305 ruby_debug_printf(
"rb_ractor_thread_switch ec:%p->%p\n",
306 (
void *)cr->threads.running_ec, (
void *)th->ec);
313 cr->threads.running_ec = th->ec;
315 VM_ASSERT(cr == GET_RACTOR());
318#define rb_ractor_set_current_ec(cr, ec) rb_ractor_set_current_ec_(cr, ec, __FILE__, __LINE__)
319#ifdef RB_THREAD_LOCAL_SPECIFIER
326#ifdef RB_THREAD_LOCAL_SPECIFIER
327 rb_current_ec_set(ec);
329 native_tls_set(ruby_current_ec_key, ec);
331 RUBY_DEBUG_LOG2(file, line,
"ec:%p->%p", (
void *)cr->threads.running_ec, (
void *)ec);
332 VM_ASSERT(ec == NULL || cr->threads.running_ec != ec);
333 cr->threads.running_ec = ec;
336void rb_vm_ractor_blocking_cnt_inc(
rb_vm_t *vm,
rb_ractor_t *cr,
const char *file,
int line);
337void rb_vm_ractor_blocking_cnt_dec(
rb_vm_t *vm,
rb_ractor_t *cr,
const char *file,
int line);
339static inline rb_serial_t
348 cr->pub.targeted_hooks_cnt++;
355 cr->pub.targeted_hooks_cnt--;
358static inline unsigned int
361 return cr->pub.targeted_hooks_cnt;
364#if RACTOR_CHECK_MODE > 0
366extern bool rb_ractor_ignore_belonging_flag;
372rb_ractor_confirm_belonging(
VALUE obj)
374 if (rb_ractor_ignore_belonging_flag)
return obj;
377 if (UNLIKELY(rb_gc_obj_foreign_p(obj))) {
379 rb_bug(
"rb_ractor_confirm_belonging: unshareable object of another Ractor's objspace");
385rb_ractor_ignore_belonging(
bool flag)
387 rb_ractor_ignore_belonging_flag = flag;
391#define rb_ractor_confirm_belonging(obj) obj
392#define rb_ractor_ignore_belonging(flag) (0)
#define RUBY_ASSERT(...)
Asserts that the given expression is truthy if and only if RUBY_DEBUG is truthy.
std::atomic< unsigned > rb_atomic_t
Type that is eligible for atomic operations.
#define SPECIAL_CONST_P
Old name of RB_SPECIAL_CONST_P.
int len
Length of the buffer.
#define RB_OBJ_SHAREABLE_P(obj)
Queries if the passed object has previously classified as shareable or not.
uintptr_t ID
Type that represents a Ruby identifier such as a variable name.
uintptr_t VALUE
Type that represents a Ruby object.