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)
14 rb_nativethread_lock_t lock;
16#if RACTOR_CHECK_MODE > 0
20#ifndef RUBY_THREAD_PTHREAD_H
21 rb_nativethread_cond_t wakeup_cond;
28 struct ccan_list_head waiters;
31 VALUE default_port_value;
36 struct ccan_list_head monitors;
71 struct ccan_list_head set;
73 unsigned int blocking_cnt;
80 VALUE thgroup_default;
85 enum ractor_status status_;
87 struct ccan_list_node vmlr_node;
93 VALUE local_storage_store_lock;
121int rb_ractor_living_thread_num(
const rb_ractor_t *);
122VALUE rb_ractor_thread_list(
void);
123bool rb_ractor_p(
VALUE rv);
128void rb_ractor_blocking_threads_inc(
rb_ractor_t *r,
const char *file,
int line);
129void rb_ractor_blocking_threads_dec(
rb_ractor_t *r,
const char *file,
int line);
131void rb_ractor_vm_barrier_interrupt_running_thread(
rb_ractor_t *r);
132void rb_ractor_terminate_interrupt_main_thread(
rb_ractor_t *r);
133void rb_ractor_terminate_all(
void);
134bool rb_ractor_main_p_(
void);
142RUBY_SYMBOL_EXPORT_BEGIN
143void rb_ractor_finish_marking(
void);
145bool rb_ractor_shareable_p_continue(
VALUE obj);
151RUBY_SYMBOL_EXPORT_END
154rb_ractor_main_p(
void)
156 if (ruby_single_main_ractor) {
160 return rb_ractor_main_p_();
165rb_ractor_status_p(
rb_ractor_t *r,
enum ractor_status status)
167 return r->status_ == status;
173 r->threads.sleeper++;
179 r->threads.sleeper--;
185 r->threads.sleeper = 0;
191 return r->threads.sleeper;
197 RUBY_DEBUG_LOG(
"th:%d->%u%s",
198 cr->threads.running_ec ? (
int)rb_th_serial(cr->threads.running_ec->thread_ptr) : -1,
199 rb_th_serial(th), cr->threads.running_ec == th->ec ?
" (same)" :
"");
201 if (cr->threads.running_ec != th->ec || always_reset) {
202 th->running_time_us = 0;
205 if (cr->threads.running_ec != th->ec) {
207 ruby_debug_printf(
"rb_ractor_thread_switch ec:%p->%p\n",
208 (
void *)cr->threads.running_ec, (
void *)th->ec);
215 cr->threads.running_ec = th->ec;
217 VM_ASSERT(cr == GET_RACTOR());
220#define rb_ractor_set_current_ec(cr, ec) rb_ractor_set_current_ec_(cr, ec, __FILE__, __LINE__)
221#ifdef RB_THREAD_LOCAL_SPECIFIER
228#ifdef RB_THREAD_LOCAL_SPECIFIER
229 rb_current_ec_set(ec);
231 native_tls_set(ruby_current_ec_key, ec);
233 RUBY_DEBUG_LOG2(file, line,
"ec:%p->%p", (
void *)cr->threads.running_ec, (
void *)ec);
234 VM_ASSERT(ec == NULL || cr->threads.running_ec != ec);
235 cr->threads.running_ec = ec;
238void rb_vm_ractor_blocking_cnt_inc(
rb_vm_t *vm,
rb_ractor_t *cr,
const char *file,
int line);
239void rb_vm_ractor_blocking_cnt_dec(
rb_vm_t *vm,
rb_ractor_t *cr,
const char *file,
int line);
241static inline uint32_t
247#if RACTOR_CHECK_MODE > 0
248# define RACTOR_BELONGING_ID(obj) (*(uint32_t *)(((uintptr_t)(obj)) + rb_gc_obj_slot_size(obj)))
250uint32_t rb_ractor_current_id(
void);
253rb_ractor_setup_belonging_to(
VALUE obj, uint32_t rid)
255 RACTOR_BELONGING_ID(obj) = rid;
258static inline uint32_t
259rb_ractor_belonging(
VALUE obj)
265 return RACTOR_BELONGING_ID(obj);
269extern bool rb_ractor_ignore_belonging_flag;
272rb_ractor_confirm_belonging(
VALUE obj)
274 if (rb_ractor_ignore_belonging_flag)
return obj;
276 uint32_t
id = rb_ractor_belonging(obj);
281 rb_bug(
"id == 0 but not shareable");
284 else if (UNLIKELY(
id != rb_ractor_current_id())) {
290 rb_bug(
"rb_ractor_confirm_belonging object-ractor id:%u, current-ractor id:%u",
id, rb_ractor_current_id());
297rb_ractor_ignore_belonging(
bool flag)
299 rb_ractor_ignore_belonging_flag = flag;
303#define rb_ractor_confirm_belonging(obj) obj
304#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.