7 #ifndef RACTOR_CHECK_MODE
8 #define RACTOR_CHECK_MODE (0 || VM_CHECK_MODE || RUBY_DEBUG)
11 enum rb_ractor_basket_type {
23 enum rb_ractor_basket_type type;
34 unsigned int reserved_cnt;
45 rb_nativethread_lock_t lock;
46 #if RACTOR_CHECK_MODE > 0
49 rb_nativethread_cond_t cond;
55 bool incoming_port_closed;
56 bool outgoing_port_closed;
59 enum ractor_wait_status {
61 wait_receiving = 0x01,
67 enum ractor_wakeup_status {
86 VALUE receiving_mutex;
90 rb_nativethread_cond_t barrier_wait_cond;
96 unsigned int blocking_cnt;
102 VALUE thgroup_default;
129 struct list_node vmlr_node;
147 void (*mark_func)(
VALUE v,
void *data);
169 int rb_ractor_living_thread_num(
const rb_ractor_t *);
171 bool rb_ractor_p(
VALUE rv);
173 void rb_ractor_living_threads_init(
rb_ractor_t *r);
176 void rb_ractor_blocking_threads_inc(
rb_ractor_t *r,
const char *file,
int line);
177 void rb_ractor_blocking_threads_dec(
rb_ractor_t *r,
const char *file,
int line);
179 void rb_ractor_vm_barrier_interrupt_running_thread(
rb_ractor_t *r);
180 void rb_ractor_terminate_interrupt_main_thread(
rb_ractor_t *r);
181 void rb_ractor_terminate_all(
void);
182 bool rb_ractor_main_p_(
void);
183 void rb_ractor_finish_marking(
void);
188 RUBY_SYMBOL_EXPORT_BEGIN
189 bool rb_ractor_shareable_p_continue(
VALUE obj);
195 RUBY_SYMBOL_EXPORT_END
198 rb_ractor_main_p(
void)
200 if (ruby_single_main_ractor) {
204 return rb_ractor_main_p_();
209 rb_ractor_status_p(
rb_ractor_t *r,
enum ractor_status status)
211 return r->status_ == status;
217 r->threads.sleeper++;
223 r->threads.sleeper--;
229 r->threads.sleeper = 0;
235 return r->threads.sleeper;
241 if (cr->threads.running_ec != th->ec) {
243 ruby_debug_printf(
"rb_ractor_thread_switch ec:%p->%p\n",
244 (
void *)cr->threads.running_ec, (
void *)th->ec);
251 if (cr->threads.running_ec != th->ec) {
252 th->running_time_us = 0;
255 cr->threads.running_ec = th->ec;
257 VM_ASSERT(cr == GET_RACTOR());
263 #ifdef RB_THREAD_LOCAL_SPECIFIER
265 rb_current_ec_set(ec);
267 ruby_current_ec = ec;
270 native_tls_set(ruby_current_ec_key, ec);
273 if (cr->threads.running_ec != ec) {
275 ruby_debug_printf(
"rb_ractor_set_current_ec ec:%p->%p\n",
276 (
void *)cr->threads.running_ec, (
void *)ec);
283 cr->threads.running_ec = ec;
286 void rb_vm_ractor_blocking_cnt_inc(
rb_vm_t *vm,
rb_ractor_t *cr,
const char *file,
int line);
287 void rb_vm_ractor_blocking_cnt_dec(
rb_vm_t *vm,
rb_ractor_t *cr,
const char *file,
int line);
289 static inline uint32_t
295 #if RACTOR_CHECK_MODE > 0
296 uint32_t rb_ractor_current_id(
void);
299 rb_ractor_setup_belonging_to(
VALUE obj, uint32_t rid)
306 rb_ractor_setup_belonging(
VALUE obj)
308 rb_ractor_setup_belonging_to(obj, rb_ractor_current_id());
311 static inline uint32_t
312 rb_ractor_belonging(
VALUE obj)
318 return RBASIC(obj)->flags >> 32;
323 rb_ractor_confirm_belonging(
VALUE obj)
325 uint32_t
id = rb_ractor_belonging(obj);
330 rb_bug(
"id == 0 but not shareable");
333 else if (UNLIKELY(
id != rb_ractor_current_id())) {
339 rb_bug(
"rb_ractor_confirm_belonging object-ractor id:%u, current-ractor id:%u",
id, rb_ractor_current_id());
345 #define rb_ractor_confirm_belonging(obj) obj
#define SPECIAL_CONST_P
Old name of RB_SPECIAL_CONST_P.
void rb_bug(const char *fmt,...)
Interpreter panic switch.
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.
#define RBASIC(obj)
Convenient casting macro.
uintptr_t VALUE
Type that represents a Ruby object.