1#include "internal/gc.h"
8#ifndef RACTOR_CHECK_MODE
9#define RACTOR_CHECK_MODE (VM_CHECK_MODE || RUBY_DEBUG) && (SIZEOF_UINT64_T == SIZEOF_VALUE)
13#define RUBY_TYPED_FROZEN_SHAREABLE_NO_REC RUBY_FL_FINALIZE
17 rb_nativethread_lock_t lock;
19#if RACTOR_CHECK_MODE > 0
23#ifndef RUBY_THREAD_PTHREAD_H
24 rb_nativethread_cond_t wakeup_cond;
31 struct ccan_list_head waiters;
34 VALUE default_port_value;
39 struct ccan_list_head monitors;
74 struct ccan_list_head set;
76 unsigned int blocking_cnt;
83 VALUE thgroup_default;
88 enum ractor_status status_;
90 struct ccan_list_node vmlr_node;
94 rb_serial_t next_fiber_serial;
98 VALUE local_storage_store_lock;
106 bool malloc_gc_disabled;
127int rb_ractor_living_thread_num(
const rb_ractor_t *);
128VALUE rb_ractor_thread_list(
void);
129bool rb_ractor_p(
VALUE rv);
134void rb_ractor_blocking_threads_inc(
rb_ractor_t *r,
const char *file,
int line);
135void rb_ractor_blocking_threads_dec(
rb_ractor_t *r,
const char *file,
int line);
137void rb_ractor_vm_barrier_interrupt_running_thread(
rb_ractor_t *r);
138void rb_ractor_terminate_interrupt_main_thread(
rb_ractor_t *r);
139void rb_ractor_terminate_all(
void);
140bool rb_ractor_main_p_(
void);
143VALUE rb_ractor_require(
VALUE feature,
bool silent);
148RUBY_SYMBOL_EXPORT_BEGIN
149void rb_ractor_finish_marking(
void);
151bool rb_ractor_shareable_p_continue(
VALUE obj);
157RUBY_SYMBOL_EXPORT_END
160rb_ractor_main_p(
void)
162 if (ruby_single_main_ractor) {
166 return rb_ractor_main_p_();
171rb_ractor_status_p(
rb_ractor_t *r,
enum ractor_status status)
173 return r->status_ == status;
179 r->threads.sleeper++;
185 r->threads.sleeper--;
191 r->threads.sleeper = 0;
197 return r->threads.sleeper;
203 RUBY_DEBUG_LOG(
"th:%d->%u%s",
204 cr->threads.running_ec ? (
int)rb_th_serial(cr->threads.running_ec->thread_ptr) : -1,
205 rb_th_serial(th), cr->threads.running_ec == th->ec ?
" (same)" :
"");
207 if (cr->threads.running_ec != th->ec || always_reset) {
208 th->running_time_us = 0;
211 if (cr->threads.running_ec != th->ec) {
213 ruby_debug_printf(
"rb_ractor_thread_switch ec:%p->%p\n",
214 (
void *)cr->threads.running_ec, (
void *)th->ec);
221 cr->threads.running_ec = th->ec;
223 VM_ASSERT(cr == GET_RACTOR());
226#define rb_ractor_set_current_ec(cr, ec) rb_ractor_set_current_ec_(cr, ec, __FILE__, __LINE__)
227#ifdef RB_THREAD_LOCAL_SPECIFIER
234#ifdef RB_THREAD_LOCAL_SPECIFIER
235 rb_current_ec_set(ec);
237 native_tls_set(ruby_current_ec_key, ec);
239 RUBY_DEBUG_LOG2(file, line,
"ec:%p->%p", (
void *)cr->threads.running_ec, (
void *)ec);
240 VM_ASSERT(ec == NULL || cr->threads.running_ec != ec);
241 cr->threads.running_ec = ec;
244void rb_vm_ractor_blocking_cnt_inc(
rb_vm_t *vm,
rb_ractor_t *cr,
const char *file,
int line);
245void rb_vm_ractor_blocking_cnt_dec(
rb_vm_t *vm,
rb_ractor_t *cr,
const char *file,
int line);
247static inline uint32_t
253#if RACTOR_CHECK_MODE > 0
254# define RACTOR_BELONGING_ID(obj) (*(uint32_t *)(((uintptr_t)(obj)) + rb_gc_obj_slot_size(obj)))
256uint32_t rb_ractor_current_id(
void);
259rb_ractor_setup_belonging_to(
VALUE obj, uint32_t rid)
261 RACTOR_BELONGING_ID(obj) = rid;
264static inline uint32_t
265rb_ractor_belonging(
VALUE obj)
271 return RACTOR_BELONGING_ID(obj);
275extern bool rb_ractor_ignore_belonging_flag;
278rb_ractor_confirm_belonging(
VALUE obj)
280 if (rb_ractor_ignore_belonging_flag)
return obj;
282 uint32_t
id = rb_ractor_belonging(obj);
287 rb_bug(
"id == 0 but not shareable");
290 else if (UNLIKELY(
id != rb_ractor_current_id())) {
296 rb_bug(
"rb_ractor_confirm_belonging object-ractor id:%u, current-ractor id:%u",
id, rb_ractor_current_id());
303rb_ractor_ignore_belonging(
bool flag)
305 rb_ractor_ignore_belonging_flag = flag;
309#define rb_ractor_confirm_belonging(obj) obj
310#define rb_ractor_ignore_belonging(flag) (0)
#define SPECIAL_CONST_P
Old name of RB_SPECIAL_CONST_P.
int len
Length of the buffer.
static bool rb_ractor_shareable_p(VALUE obj)
Queries if multiple Ractors can share the passed object or not.
#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.