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)
12enum rb_ractor_basket_type {
29 basket_type_take_basket,
43 enum rb_ractor_basket_type e;
65 return b->type.e ==
type;
71 return basket_type_p(b, basket_type_none);
80 unsigned int reserved_cnt;
83enum rb_ractor_wait_status {
85 wait_receiving = 0x01,
91enum rb_ractor_wakeup_status {
103 rb_nativethread_lock_t lock;
104#if RACTOR_CHECK_MODE > 0
108 bool incoming_port_closed;
109 bool outgoing_port_closed;
121 struct ccan_list_head waiting_threads;
153 rb_nativethread_cond_t barrier_wait_cond;
157 struct ccan_list_head set;
159 unsigned int blocking_cnt;
160 unsigned int sleeper;
165 VALUE thgroup_default;
170 enum ractor_status status_;
172 struct ccan_list_node vmlr_node;
178 VALUE local_storage_store_lock;
206int rb_ractor_living_thread_num(
const rb_ractor_t *);
207VALUE rb_ractor_thread_list(
void);
208bool rb_ractor_p(
VALUE rv);
213void rb_ractor_blocking_threads_inc(
rb_ractor_t *r,
const char *file,
int line);
214void rb_ractor_blocking_threads_dec(
rb_ractor_t *r,
const char *file,
int line);
216void rb_ractor_vm_barrier_interrupt_running_thread(
rb_ractor_t *r);
217void rb_ractor_terminate_interrupt_main_thread(
rb_ractor_t *r);
218void rb_ractor_terminate_all(
void);
219bool rb_ractor_main_p_(
void);
227RUBY_SYMBOL_EXPORT_BEGIN
228void rb_ractor_finish_marking(
void);
230bool rb_ractor_shareable_p_continue(
VALUE obj);
236RUBY_SYMBOL_EXPORT_END
239rb_ractor_main_p(
void)
241 if (ruby_single_main_ractor) {
245 return rb_ractor_main_p_();
250rb_ractor_status_p(
rb_ractor_t *r,
enum ractor_status status)
252 return r->status_ == status;
258 r->threads.sleeper++;
264 r->threads.sleeper--;
270 r->threads.sleeper = 0;
276 return r->threads.sleeper;
282 RUBY_DEBUG_LOG(
"th:%d->%u%s",
283 cr->threads.running_ec ? (
int)rb_th_serial(cr->threads.running_ec->thread_ptr) : -1,
284 rb_th_serial(th), cr->threads.running_ec == th->ec ?
" (same)" :
"");
286 if (cr->threads.running_ec != th->ec || always_reset) {
287 th->running_time_us = 0;
290 if (cr->threads.running_ec != th->ec) {
292 ruby_debug_printf(
"rb_ractor_thread_switch ec:%p->%p\n",
293 (
void *)cr->threads.running_ec, (
void *)th->ec);
300 cr->threads.running_ec = th->ec;
302 VM_ASSERT(cr == GET_RACTOR());
305#define rb_ractor_set_current_ec(cr, ec) rb_ractor_set_current_ec_(cr, ec, __FILE__, __LINE__)
306#ifdef RB_THREAD_LOCAL_SPECIFIER
313#ifdef RB_THREAD_LOCAL_SPECIFIER
314 rb_current_ec_set(ec);
316 native_tls_set(ruby_current_ec_key, ec);
318 RUBY_DEBUG_LOG2(file, line,
"ec:%p->%p", (
void *)cr->threads.running_ec, (
void *)ec);
319 VM_ASSERT(ec == NULL || cr->threads.running_ec != ec);
320 cr->threads.running_ec = ec;
323void rb_vm_ractor_blocking_cnt_inc(
rb_vm_t *vm,
rb_ractor_t *cr,
const char *file,
int line);
324void rb_vm_ractor_blocking_cnt_dec(
rb_vm_t *vm,
rb_ractor_t *cr,
const char *file,
int line);
326static inline uint32_t
332#if RACTOR_CHECK_MODE > 0
333# define RACTOR_BELONGING_ID(obj) (*(uint32_t *)(((uintptr_t)(obj)) + rb_gc_obj_slot_size(obj)))
335uint32_t rb_ractor_current_id(
void);
338rb_ractor_setup_belonging_to(
VALUE obj, uint32_t rid)
340 RACTOR_BELONGING_ID(obj) = rid;
343static inline uint32_t
344rb_ractor_belonging(
VALUE obj)
350 return RACTOR_BELONGING_ID(obj);
355rb_ractor_confirm_belonging(
VALUE obj)
357 uint32_t
id = rb_ractor_belonging(obj);
362 rb_bug(
"id == 0 but not shareable");
365 else if (UNLIKELY(
id != rb_ractor_current_id())) {
371 rb_bug(
"rb_ractor_confirm_belonging object-ractor id:%u, current-ractor id:%u",
id, rb_ractor_current_id());
377#define rb_ractor_confirm_belonging(obj) obj
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.
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.
VALUE type(ANYARGS)
ANYARGS-ed function type.
uintptr_t ID
Type that represents a Ruby identifier such as a variable name.
uintptr_t VALUE
Type that represents a Ruby object.