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
27#ifndef RUBY_THREAD_PTHREAD_H
28 rb_nativethread_cond_t wakeup_cond;
35 struct ccan_list_head waiters;
38 VALUE default_port_value;
45 struct ccan_list_head off_queue_baskets;
48 struct ccan_list_head monitors;
87 VALUE *registered_marks;
88 size_t registered_marks_cnt, registered_marks_capa;
97 struct ccan_list_head set;
99 unsigned int blocking_cnt;
100 unsigned int sleeper;
115 VALUE thgroup_default;
120 enum ractor_status status_;
122 struct ccan_list_node vmlr_node;
123 bool in_terminated_set;
131 rb_serial_t next_ec_serial;
135 VALUE local_storage_store_lock;
146 bool malloc_gc_disabled;
159 void *creating_child_objspace;
165void rb_ractor_mark_terminated_join_value(
rb_ractor_t *r);
173enum ractor_wakeup_status {
181 enum ractor_wakeup_status wakeup_status;
183 struct ccan_list_node node;
187 const rb_hrtime_t *end;
207int rb_ractor_living_thread_num(
const rb_ractor_t *);
208VALUE rb_ractor_thread_list(
void);
209bool rb_ractor_p(
VALUE rv);
224void rb_ractor_blocking_threads_inc(
rb_ractor_t *r,
const char *file,
int line);
225void rb_ractor_blocking_threads_dec(
rb_ractor_t *r,
const char *file,
int line);
227void rb_ractor_vm_barrier_interrupt_running_thread(
rb_ractor_t *r);
228void rb_ractor_terminate_interrupt_main_thread(
rb_ractor_t *r);
229void rb_ractor_terminate_all(
void);
230bool rb_ractor_main_p_(
void);
233VALUE rb_ractor_require(
VALUE feature,
bool silent);
239RUBY_SYMBOL_EXPORT_BEGIN
240void rb_ractor_finish_marking(
bool full_mark);
242bool rb_ractor_shareable_p_continue(
VALUE obj);
248RUBY_SYMBOL_EXPORT_END
251rb_ractor_main_p(
void)
253 if (ruby_single_main_ractor) {
257 return rb_ractor_main_p_();
262rb_ractor_status_p(
rb_ractor_t *r,
enum ractor_status status)
264 return r->status_ == status;
270 r->threads.sleeper++;
276 r->threads.sleeper--;
282 r->threads.sleeper = 0;
288 return r->threads.sleeper;
294 RUBY_DEBUG_LOG(
"th:%d->%u%s",
295 cr->threads.running_ec ? (
int)rb_th_serial(cr->threads.running_ec->thread_ptr) : -1,
296 rb_th_serial(th), cr->threads.running_ec == th->ec ?
" (same)" :
"");
298 if (cr->threads.running_ec != th->ec || always_reset) {
299 th->running_time_us = 0;
302 if (cr->threads.running_ec != th->ec) {
304 ruby_debug_printf(
"rb_ractor_thread_switch ec:%p->%p\n",
305 (
void *)cr->threads.running_ec, (
void *)th->ec);
312 cr->threads.running_ec = th->ec;
314 VM_ASSERT(cr == GET_RACTOR());
317#define rb_ractor_set_current_ec(cr, ec) rb_ractor_set_current_ec_(cr, ec, __FILE__, __LINE__)
318#ifdef RB_THREAD_LOCAL_SPECIFIER
325#ifdef RB_THREAD_LOCAL_SPECIFIER
326 rb_current_ec_set(ec);
328 native_tls_set(ruby_current_ec_key, ec);
330 RUBY_DEBUG_LOG2(file, line,
"ec:%p->%p", (
void *)cr->threads.running_ec, (
void *)ec);
331 VM_ASSERT(ec == NULL || cr->threads.running_ec != ec);
332 cr->threads.running_ec = ec;
335void rb_vm_ractor_blocking_cnt_inc(
rb_vm_t *vm,
rb_ractor_t *cr,
const char *file,
int line);
336void rb_vm_ractor_blocking_cnt_dec(
rb_vm_t *vm,
rb_ractor_t *cr,
const char *file,
int line);
338static inline uint32_t
347 cr->pub.targeted_hooks_cnt++;
354 cr->pub.targeted_hooks_cnt--;
357static inline unsigned int
360 return cr->pub.targeted_hooks_cnt;
363#if RACTOR_CHECK_MODE > 0
365extern bool rb_ractor_ignore_belonging_flag;
371rb_ractor_confirm_belonging(
VALUE obj)
373 if (rb_ractor_ignore_belonging_flag)
return obj;
376 if (UNLIKELY(rb_gc_obj_foreign_p(obj))) {
378 rb_bug(
"rb_ractor_confirm_belonging: unshareable object of another Ractor's objspace");
384rb_ractor_ignore_belonging(
bool flag)
386 rb_ractor_ignore_belonging_flag = flag;
390#define rb_ractor_confirm_belonging(obj) obj
391#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.