1#include "internal/gc.h"
9#ifndef RACTOR_CHECK_MODE
10#define RACTOR_CHECK_MODE (VM_CHECK_MODE || RUBY_DEBUG) && (SIZEOF_UINT64_T == SIZEOF_VALUE)
14#define RUBY_TYPED_FROZEN_SHAREABLE_NO_REC RUBY_FL_FINALIZE
21 rb_nativethread_lock_t lock;
23#if RACTOR_CHECK_MODE > 0
31 struct ccan_list_head waiters;
34 VALUE default_port_value;
41 struct ccan_list_head off_queue_baskets;
44 struct ccan_list_head monitors;
83 VALUE *registered_marks;
84 size_t registered_marks_cnt, registered_marks_capa;
93 struct ccan_list_head set;
95 unsigned int blocking_cnt;
114 VALUE thgroup_default;
119 enum ractor_status status_;
121 struct ccan_list_node vmlr_node;
122 bool in_terminated_set;
130 rb_serial_t next_ec_serial;
134 VALUE local_storage_store_lock;
145 bool malloc_gc_disabled;
158 void *creating_child_objspace;
164void rb_ractor_mark_terminated_join_value(
rb_ractor_t *r);
172enum ractor_wakeup_status {
180 enum ractor_wakeup_status wakeup_status;
182 struct ccan_list_node node;
186 const rb_hrtime_t *end;
206int rb_ractor_living_thread_num(
const rb_ractor_t *);
207VALUE rb_ractor_thread_list(
void);
208bool rb_ractor_p(
VALUE rv);
223void rb_ractor_blocking_threads_inc(
rb_ractor_t *r,
const char *file,
int line);
224void rb_ractor_blocking_threads_dec(
rb_ractor_t *r,
const char *file,
int line);
226void rb_ractor_vm_barrier_interrupt_running_thread(
rb_ractor_t *r);
227void rb_ractor_terminate_interrupt_main_thread(
rb_ractor_t *r);
228void rb_ractor_terminate_all(
void);
229bool rb_ractor_main_p_(
void);
232VALUE rb_ractor_require(
VALUE feature,
bool silent);
238RUBY_SYMBOL_EXPORT_BEGIN
239void rb_ractor_finish_marking(
bool full_mark);
241bool rb_ractor_shareable_p_continue(
VALUE obj);
247RUBY_SYMBOL_EXPORT_END
250rb_ractor_main_p(
void)
252 if (ruby_single_main_ractor) {
256 return rb_ractor_main_p_();
261rb_ractor_status_p(
rb_ractor_t *r,
enum ractor_status status)
263 return r->status_ == status;
269 r->threads.sleeper++;
275 r->threads.sleeper--;
281 r->threads.sleeper = 0;
287 return r->threads.sleeper;
293 RUBY_DEBUG_LOG(
"th:%d->%u%s",
294 cr->threads.running_ec ? (
int)rb_th_serial(cr->threads.running_ec->thread_ptr) : -1,
295 rb_th_serial(th), cr->threads.running_ec == th->ec ?
" (same)" :
"");
297 if (cr->threads.running_ec != th->ec || always_reset) {
298 th->running_time_us = 0;
301 if (cr->threads.running_ec != th->ec) {
303 ruby_debug_printf(
"rb_ractor_thread_switch ec:%p->%p\n",
304 (
void *)cr->threads.running_ec, (
void *)th->ec);
311 cr->threads.running_ec = th->ec;
313 VM_ASSERT(cr == GET_RACTOR());
316#define rb_ractor_set_current_ec(cr, ec) rb_ractor_set_current_ec_(cr, ec, __FILE__, __LINE__)
317#ifdef RB_THREAD_LOCAL_SPECIFIER
324#ifdef RB_THREAD_LOCAL_SPECIFIER
325 rb_current_ec_set(ec);
327 native_tls_set(ruby_current_ec_key, ec);
329 RUBY_DEBUG_LOG2(file, line,
"ec:%p->%p", (
void *)cr->threads.running_ec, (
void *)ec);
330 VM_ASSERT(ec == NULL || cr->threads.running_ec != ec);
331 cr->threads.running_ec = ec;
334void rb_vm_ractor_blocking_cnt_inc(
rb_vm_t *vm,
rb_ractor_t *cr,
const char *file,
int line);
335void rb_vm_ractor_blocking_cnt_dec(
rb_vm_t *vm,
rb_ractor_t *cr,
const char *file,
int line);
337static inline uint32_t
346 cr->pub.targeted_hooks_cnt++;
353 cr->pub.targeted_hooks_cnt--;
356static inline unsigned int
359 return cr->pub.targeted_hooks_cnt;
362#if RACTOR_CHECK_MODE > 0
364extern bool rb_ractor_ignore_belonging_flag;
370rb_ractor_confirm_belonging(
VALUE obj)
372 if (rb_ractor_ignore_belonging_flag)
return obj;
375 if (UNLIKELY(rb_gc_obj_foreign_p(obj))) {
377 rb_bug(
"rb_ractor_confirm_belonging: unshareable object of another Ractor's objspace");
383rb_ractor_ignore_belonging(
bool flag)
385 rb_ractor_ignore_belonging_flag = flag;
389#define rb_ractor_confirm_belonging(obj) obj
390#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.