2023-02-17 14:14:53 +00:00
|
|
|
#include "internal/gc.h"
|
2020-03-10 02:22:11 +09:00
|
|
|
#include "ruby/ruby.h"
|
2020-11-17 16:40:47 +09:00
|
|
|
#include "ruby/ractor.h"
|
2020-03-10 02:22:11 +09:00
|
|
|
#include "vm_core.h"
|
|
|
|
#include "id_table.h"
|
|
|
|
#include "vm_debug.h"
|
|
|
|
|
|
|
|
#ifndef RACTOR_CHECK_MODE
|
2022-08-23 13:23:40 -07:00
|
|
|
#define RACTOR_CHECK_MODE (VM_CHECK_MODE || RUBY_DEBUG) && (SIZEOF_UINT64_T == SIZEOF_VALUE)
|
2020-03-10 02:22:11 +09:00
|
|
|
#endif
|
|
|
|
|
|
|
|
enum rb_ractor_basket_type {
|
2023-02-24 18:46:17 +09:00
|
|
|
// basket is empty
|
2020-03-10 02:22:11 +09:00
|
|
|
basket_type_none,
|
2023-02-24 18:46:17 +09:00
|
|
|
|
|
|
|
// value is available
|
2020-10-31 00:40:04 +09:00
|
|
|
basket_type_ref,
|
|
|
|
basket_type_copy,
|
2020-03-10 02:22:11 +09:00
|
|
|
basket_type_move,
|
2020-10-31 00:40:04 +09:00
|
|
|
basket_type_will,
|
2023-02-24 18:46:17 +09:00
|
|
|
|
|
|
|
// basket should be deleted
|
2020-12-08 14:04:18 +09:00
|
|
|
basket_type_deleted,
|
2023-02-24 18:46:17 +09:00
|
|
|
|
|
|
|
// basket is reserved
|
2020-12-08 14:04:18 +09:00
|
|
|
basket_type_reserved,
|
2023-02-24 18:46:17 +09:00
|
|
|
|
|
|
|
// take_basket is available
|
|
|
|
basket_type_take_basket,
|
|
|
|
|
|
|
|
// basket is keeping by yielding ractor
|
|
|
|
basket_type_yielding,
|
|
|
|
};
|
|
|
|
|
|
|
|
// per ractor taking configuration
|
|
|
|
struct rb_ractor_selector_take_config {
|
|
|
|
bool closed;
|
|
|
|
bool oneshot;
|
2020-03-10 02:22:11 +09:00
|
|
|
};
|
|
|
|
|
|
|
|
struct rb_ractor_basket {
|
2023-02-24 18:46:17 +09:00
|
|
|
union {
|
|
|
|
enum rb_ractor_basket_type e;
|
|
|
|
rb_atomic_t atomic;
|
|
|
|
} type;
|
Get ractor message passing working with > 1 thread sending/receiving values in same ractor
Rework ractors so that any ractor action (Ractor.receive, Ractor#send, Ractor.yield, Ractor#take,
Ractor.select) will operate on the thread that called the action. It will put that thread to sleep if
it's a blocking function and it needs to put it to sleep, and the awakening action (Ractor.yield,
Ractor#send) will wake up the blocked thread.
Before this change every blocking ractor action was associated with the ractor struct and its fields.
If a ractor called Ractor.receive, its wait status was wait_receiving, and when another ractor calls
r.send on it, it will look for that status in the ractor struct fields and wake it up. The problem was that
what if 2 threads call blocking ractor actions in the same ractor. Imagine if 1 thread has called Ractor.receive
and another r.take. Then, when a different ractor calls r.send on it, it doesn't know which ruby thread is associated
to which ractor action, so what ruby thread should it schedule? This change moves some fields onto the ruby thread
itself so that ruby threads are the ones that have ractor blocking statuses, and threads are then specifically scheduled
when unblocked.
Fixes [#17624]
Fixes [#21037]
2025-05-12 18:03:22 -04:00
|
|
|
VALUE sender; // Ractor object sending message
|
|
|
|
rb_thread_t *sending_th;
|
2023-02-24 18:46:17 +09:00
|
|
|
|
|
|
|
union {
|
|
|
|
struct {
|
|
|
|
VALUE v;
|
|
|
|
bool exception;
|
|
|
|
} send;
|
|
|
|
|
|
|
|
struct {
|
|
|
|
struct rb_ractor_basket *basket;
|
|
|
|
struct rb_ractor_selector_take_config *config;
|
|
|
|
} take;
|
|
|
|
} p; // payload
|
2020-03-10 02:22:11 +09:00
|
|
|
};
|
|
|
|
|
2023-02-24 18:46:17 +09:00
|
|
|
static inline bool
|
|
|
|
basket_type_p(struct rb_ractor_basket *b, enum rb_ractor_basket_type type)
|
|
|
|
{
|
|
|
|
return b->type.e == type;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool
|
|
|
|
basket_none_p(struct rb_ractor_basket *b)
|
|
|
|
{
|
|
|
|
return basket_type_p(b, basket_type_none);
|
|
|
|
}
|
|
|
|
|
2020-03-10 02:22:11 +09:00
|
|
|
struct rb_ractor_queue {
|
|
|
|
struct rb_ractor_basket *baskets;
|
2020-10-07 17:51:19 +09:00
|
|
|
int start;
|
2020-03-10 02:22:11 +09:00
|
|
|
int cnt;
|
|
|
|
int size;
|
2020-12-08 14:04:18 +09:00
|
|
|
unsigned int serial;
|
|
|
|
unsigned int reserved_cnt;
|
2020-03-10 02:22:11 +09:00
|
|
|
};
|
|
|
|
|
2022-07-22 16:57:25 +09:00
|
|
|
enum rb_ractor_wait_status {
|
2022-07-22 16:49:08 +09:00
|
|
|
wait_none = 0x00,
|
|
|
|
wait_receiving = 0x01,
|
|
|
|
wait_taking = 0x02,
|
|
|
|
wait_yielding = 0x04,
|
|
|
|
wait_moving = 0x08,
|
|
|
|
};
|
|
|
|
|
2022-07-22 16:57:25 +09:00
|
|
|
enum rb_ractor_wakeup_status {
|
2022-07-22 16:49:08 +09:00
|
|
|
wakeup_none,
|
|
|
|
wakeup_by_send,
|
|
|
|
wakeup_by_yield,
|
|
|
|
wakeup_by_take,
|
|
|
|
wakeup_by_close,
|
|
|
|
wakeup_by_interrupt,
|
|
|
|
wakeup_by_retry,
|
|
|
|
};
|
|
|
|
|
2020-12-08 00:42:20 +09:00
|
|
|
struct rb_ractor_sync {
|
2020-03-10 02:22:11 +09:00
|
|
|
// ractor lock
|
|
|
|
rb_nativethread_lock_t lock;
|
|
|
|
#if RACTOR_CHECK_MODE > 0
|
|
|
|
VALUE locked_by;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
bool incoming_port_closed;
|
|
|
|
bool outgoing_port_closed;
|
|
|
|
|
2023-02-24 18:46:17 +09:00
|
|
|
// All sent messages will be pushed into recv_queue
|
|
|
|
struct rb_ractor_queue recv_queue;
|
|
|
|
|
|
|
|
// The following ractors waiting for the yielding by this ractor
|
|
|
|
struct rb_ractor_queue takers_queue;
|
|
|
|
|
|
|
|
// Enabled if the ractor already terminated and not taken yet.
|
|
|
|
struct rb_ractor_basket will_basket;
|
|
|
|
|
2020-03-10 02:22:11 +09:00
|
|
|
struct ractor_wait {
|
Get ractor message passing working with > 1 thread sending/receiving values in same ractor
Rework ractors so that any ractor action (Ractor.receive, Ractor#send, Ractor.yield, Ractor#take,
Ractor.select) will operate on the thread that called the action. It will put that thread to sleep if
it's a blocking function and it needs to put it to sleep, and the awakening action (Ractor.yield,
Ractor#send) will wake up the blocked thread.
Before this change every blocking ractor action was associated with the ractor struct and its fields.
If a ractor called Ractor.receive, its wait status was wait_receiving, and when another ractor calls
r.send on it, it will look for that status in the ractor struct fields and wake it up. The problem was that
what if 2 threads call blocking ractor actions in the same ractor. Imagine if 1 thread has called Ractor.receive
and another r.take. Then, when a different ractor calls r.send on it, it doesn't know which ruby thread is associated
to which ractor action, so what ruby thread should it schedule? This change moves some fields onto the ruby thread
itself so that ruby threads are the ones that have ractor blocking statuses, and threads are then specifically scheduled
when unblocked.
Fixes [#17624]
Fixes [#21037]
2025-05-12 18:03:22 -04:00
|
|
|
struct ccan_list_head waiting_threads;
|
|
|
|
// each thread has struct ccan_list_node ractor_waiting.waiting_node
|
2020-03-10 02:22:11 +09:00
|
|
|
} wait;
|
2020-12-08 00:42:20 +09:00
|
|
|
};
|
|
|
|
|
2022-07-22 16:49:08 +09:00
|
|
|
// created
|
|
|
|
// | ready to run
|
|
|
|
// ====================== inserted to vm->ractor
|
|
|
|
// v
|
|
|
|
// blocking <---+ all threads are blocking
|
|
|
|
// | |
|
|
|
|
// v |
|
|
|
|
// running -----+
|
|
|
|
// | all threads are terminated.
|
|
|
|
// ====================== removed from vm->ractor
|
|
|
|
// v
|
|
|
|
// terminated
|
|
|
|
//
|
|
|
|
// status is protected by VM lock (global state)
|
|
|
|
enum ractor_status {
|
|
|
|
ractor_created,
|
|
|
|
ractor_running,
|
|
|
|
ractor_blocking,
|
|
|
|
ractor_terminated,
|
|
|
|
};
|
|
|
|
|
2020-12-08 00:42:20 +09:00
|
|
|
struct rb_ractor_struct {
|
2020-12-20 01:44:41 +09:00
|
|
|
struct rb_ractor_pub pub;
|
|
|
|
|
2020-12-08 00:42:20 +09:00
|
|
|
struct rb_ractor_sync sync;
|
2020-03-10 02:22:11 +09:00
|
|
|
|
|
|
|
// vm wide barrier synchronization
|
|
|
|
rb_nativethread_cond_t barrier_wait_cond;
|
|
|
|
|
|
|
|
// thread management
|
|
|
|
struct {
|
2022-03-30 16:36:31 +09:00
|
|
|
struct ccan_list_head set;
|
2020-03-10 02:22:11 +09:00
|
|
|
unsigned int cnt;
|
|
|
|
unsigned int blocking_cnt;
|
|
|
|
unsigned int sleeper;
|
2022-04-17 03:40:23 +09:00
|
|
|
struct rb_thread_sched sched;
|
2020-03-10 02:22:11 +09:00
|
|
|
rb_execution_context_t *running_ec;
|
|
|
|
rb_thread_t *main;
|
|
|
|
} threads;
|
|
|
|
VALUE thgroup_default;
|
|
|
|
|
|
|
|
VALUE name;
|
|
|
|
VALUE loc;
|
|
|
|
|
2022-07-22 16:49:08 +09:00
|
|
|
enum ractor_status status_;
|
2020-03-10 02:22:11 +09:00
|
|
|
|
2022-03-30 16:36:31 +09:00
|
|
|
struct ccan_list_node vmlr_node;
|
2020-03-10 02:22:11 +09:00
|
|
|
|
2020-11-28 04:39:09 +09:00
|
|
|
// ractor local data
|
|
|
|
|
|
|
|
st_table *local_storage;
|
2020-12-22 01:55:15 +09:00
|
|
|
struct rb_id_table *idkey_local_storage;
|
2024-12-13 04:52:34 +09:00
|
|
|
VALUE local_storage_store_lock;
|
2020-11-28 04:39:09 +09:00
|
|
|
|
2020-03-10 02:22:11 +09:00
|
|
|
VALUE r_stdin;
|
|
|
|
VALUE r_stdout;
|
|
|
|
VALUE r_stderr;
|
Some global variables can be accessed from ractors
Some global variables should be used from non-main Ractors.
[Bug #17268]
```ruby
# ractor-local (derived from created ractor): debug
'$DEBUG' => $DEBUG,
'$-d' => $-d,
# ractor-local (derived from created ractor): verbose
'$VERBOSE' => $VERBOSE,
'$-w' => $-w,
'$-W' => $-W,
'$-v' => $-v,
# process-local (readonly): other commandline parameters
'$-p' => $-p,
'$-l' => $-l,
'$-a' => $-a,
# process-local (readonly): getpid
'$$' => $$,
# thread local: process result
'$?' => $?,
# scope local: match
'$~' => $~.inspect,
'$&' => $&,
'$`' => $`,
'$\'' => $',
'$+' => $+,
'$1' => $1,
# scope local: last line
'$_' => $_,
# scope local: last backtrace
'$@' => $@,
'$!' => $!,
# ractor local: stdin, out, err
'$stdin' => $stdin.inspect,
'$stdout' => $stdout.inspect,
'$stderr' => $stderr.inspect,
```
2020-10-20 10:46:43 +09:00
|
|
|
VALUE verbose;
|
|
|
|
VALUE debug;
|
2020-10-21 13:53:46 +09:00
|
|
|
|
2024-05-03 12:00:24 -04:00
|
|
|
void *newobj_cache;
|
2020-03-10 02:22:11 +09:00
|
|
|
}; // rb_ractor_t is defined in vm_core.h
|
|
|
|
|
2020-12-20 01:44:41 +09:00
|
|
|
|
|
|
|
static inline VALUE
|
|
|
|
rb_ractor_self(const rb_ractor_t *r)
|
|
|
|
{
|
|
|
|
return r->pub.self;
|
|
|
|
}
|
|
|
|
|
2020-03-10 02:22:11 +09:00
|
|
|
rb_ractor_t *rb_ractor_main_alloc(void);
|
|
|
|
void rb_ractor_main_setup(rb_vm_t *vm, rb_ractor_t *main_ractor, rb_thread_t *main_thread);
|
|
|
|
void rb_ractor_atexit(rb_execution_context_t *ec, VALUE result);
|
|
|
|
void rb_ractor_atexit_exception(rb_execution_context_t *ec);
|
|
|
|
void rb_ractor_teardown(rb_execution_context_t *ec);
|
2020-10-03 14:05:15 +02:00
|
|
|
void rb_ractor_receive_parameters(rb_execution_context_t *ec, rb_ractor_t *g, int len, VALUE *ptr);
|
2020-03-10 02:22:11 +09:00
|
|
|
void rb_ractor_send_parameters(rb_execution_context_t *ec, rb_ractor_t *g, VALUE args);
|
|
|
|
|
|
|
|
VALUE rb_thread_create_ractor(rb_ractor_t *g, VALUE args, VALUE proc); // defined in thread.c
|
|
|
|
|
|
|
|
int rb_ractor_living_thread_num(const rb_ractor_t *);
|
2023-03-30 02:38:08 +09:00
|
|
|
VALUE rb_ractor_thread_list(void);
|
2021-10-04 08:21:40 +09:00
|
|
|
bool rb_ractor_p(VALUE rv);
|
2020-03-10 02:22:11 +09:00
|
|
|
|
|
|
|
void rb_ractor_living_threads_init(rb_ractor_t *r);
|
|
|
|
void rb_ractor_living_threads_insert(rb_ractor_t *r, rb_thread_t *th);
|
|
|
|
void rb_ractor_living_threads_remove(rb_ractor_t *r, rb_thread_t *th);
|
|
|
|
void rb_ractor_blocking_threads_inc(rb_ractor_t *r, const char *file, int line); // TODO: file, line only for RUBY_DEBUG_LOG
|
|
|
|
void rb_ractor_blocking_threads_dec(rb_ractor_t *r, const char *file, int line); // TODO: file, line only for RUBY_DEBUG_LOG
|
|
|
|
|
|
|
|
void rb_ractor_vm_barrier_interrupt_running_thread(rb_ractor_t *r);
|
|
|
|
void rb_ractor_terminate_interrupt_main_thread(rb_ractor_t *r);
|
|
|
|
void rb_ractor_terminate_all(void);
|
2020-11-17 16:40:47 +09:00
|
|
|
bool rb_ractor_main_p_(void);
|
2020-12-24 04:29:59 +09:00
|
|
|
void rb_ractor_atfork(rb_vm_t *vm, rb_thread_t *th);
|
2025-03-25 15:26:55 -07:00
|
|
|
void rb_ractor_terminate_atfork(rb_vm_t *vm, rb_ractor_t *th);
|
2024-11-05 04:54:06 +09:00
|
|
|
VALUE rb_ractor_require(VALUE feature);
|
|
|
|
VALUE rb_ractor_autoload_load(VALUE space, ID id);
|
2020-11-17 16:40:47 +09:00
|
|
|
|
2020-12-24 10:59:27 +09:00
|
|
|
VALUE rb_ractor_ensure_shareable(VALUE obj, VALUE name);
|
|
|
|
|
2020-11-18 10:52:56 +09:00
|
|
|
RUBY_SYMBOL_EXPORT_BEGIN
|
2024-05-03 12:00:24 -04:00
|
|
|
void rb_ractor_finish_marking(void);
|
|
|
|
|
2020-11-18 10:52:56 +09:00
|
|
|
bool rb_ractor_shareable_p_continue(VALUE obj);
|
2020-11-28 04:39:09 +09:00
|
|
|
|
|
|
|
// THIS FUNCTION SHOULD NOT CALL WHILE INCREMENTAL MARKING!!
|
|
|
|
// This function is for T_DATA::free_func
|
|
|
|
void rb_ractor_local_storage_delkey(rb_ractor_local_key_t key);
|
|
|
|
|
2020-11-18 10:52:56 +09:00
|
|
|
RUBY_SYMBOL_EXPORT_END
|
|
|
|
|
2020-11-17 16:40:47 +09:00
|
|
|
static inline bool
|
|
|
|
rb_ractor_main_p(void)
|
|
|
|
{
|
2020-12-02 03:37:56 +09:00
|
|
|
if (ruby_single_main_ractor) {
|
2020-11-17 16:40:47 +09:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return rb_ractor_main_p_();
|
|
|
|
}
|
|
|
|
}
|
2020-03-10 02:22:11 +09:00
|
|
|
|
|
|
|
static inline bool
|
|
|
|
rb_ractor_status_p(rb_ractor_t *r, enum ractor_status status)
|
|
|
|
{
|
|
|
|
return r->status_ == status;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
rb_ractor_sleeper_threads_inc(rb_ractor_t *r)
|
|
|
|
{
|
|
|
|
r->threads.sleeper++;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
rb_ractor_sleeper_threads_dec(rb_ractor_t *r)
|
|
|
|
{
|
|
|
|
r->threads.sleeper--;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
rb_ractor_sleeper_threads_clear(rb_ractor_t *r)
|
|
|
|
{
|
|
|
|
r->threads.sleeper = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
rb_ractor_sleeper_thread_num(rb_ractor_t *r)
|
|
|
|
{
|
|
|
|
return r->threads.sleeper;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
rb_ractor_thread_switch(rb_ractor_t *cr, rb_thread_t *th)
|
|
|
|
{
|
2023-03-31 17:33:05 +09:00
|
|
|
RUBY_DEBUG_LOG("th:%d->%u%s",
|
|
|
|
cr->threads.running_ec ? (int)rb_th_serial(cr->threads.running_ec->thread_ptr) : -1,
|
|
|
|
rb_th_serial(th), cr->threads.running_ec == th->ec ? " (same)" : "");
|
|
|
|
|
2021-09-09 23:21:06 +09:00
|
|
|
if (cr->threads.running_ec != th->ec) {
|
|
|
|
if (0) {
|
|
|
|
ruby_debug_printf("rb_ractor_thread_switch ec:%p->%p\n",
|
|
|
|
(void *)cr->threads.running_ec, (void *)th->ec);
|
|
|
|
}
|
2020-03-10 02:22:11 +09:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cr->threads.running_ec != th->ec) {
|
|
|
|
th->running_time_us = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
cr->threads.running_ec = th->ec;
|
|
|
|
|
|
|
|
VM_ASSERT(cr == GET_RACTOR());
|
|
|
|
}
|
|
|
|
|
2022-05-24 01:44:17 +09:00
|
|
|
#define rb_ractor_set_current_ec(cr, ec) rb_ractor_set_current_ec_(cr, ec, __FILE__, __LINE__)
|
2024-11-23 09:28:17 +00:00
|
|
|
#ifdef RB_THREAD_LOCAL_SPECIFIER
|
|
|
|
void rb_current_ec_set(rb_execution_context_t *ec);
|
|
|
|
#endif
|
2022-05-24 01:44:17 +09:00
|
|
|
|
2020-03-10 02:22:11 +09:00
|
|
|
static inline void
|
2022-05-24 01:44:17 +09:00
|
|
|
rb_ractor_set_current_ec_(rb_ractor_t *cr, rb_execution_context_t *ec, const char *file, int line)
|
2020-03-10 02:22:11 +09:00
|
|
|
{
|
2020-10-19 16:47:32 +09:00
|
|
|
#ifdef RB_THREAD_LOCAL_SPECIFIER
|
|
|
|
rb_current_ec_set(ec);
|
|
|
|
#else
|
2020-03-10 02:22:11 +09:00
|
|
|
native_tls_set(ruby_current_ec_key, ec);
|
2020-10-19 16:47:32 +09:00
|
|
|
#endif
|
2022-07-28 09:10:16 +09:00
|
|
|
RUBY_DEBUG_LOG2(file, line, "ec:%p->%p", (void *)cr->threads.running_ec, (void *)ec);
|
2023-03-31 17:33:17 +09:00
|
|
|
VM_ASSERT(ec == NULL || cr->threads.running_ec != ec);
|
2020-03-10 02:22:11 +09:00
|
|
|
cr->threads.running_ec = ec;
|
|
|
|
}
|
|
|
|
|
|
|
|
void rb_vm_ractor_blocking_cnt_inc(rb_vm_t *vm, rb_ractor_t *cr, const char *file, int line);
|
|
|
|
void rb_vm_ractor_blocking_cnt_dec(rb_vm_t *vm, rb_ractor_t *cr, const char *file, int line);
|
|
|
|
|
2020-12-20 01:44:41 +09:00
|
|
|
static inline uint32_t
|
|
|
|
rb_ractor_id(const rb_ractor_t *r)
|
|
|
|
{
|
|
|
|
return r->pub.id;
|
|
|
|
}
|
2020-03-10 02:22:11 +09:00
|
|
|
|
|
|
|
#if RACTOR_CHECK_MODE > 0
|
2022-11-18 10:07:06 -05:00
|
|
|
# define RACTOR_BELONGING_ID(obj) (*(uint32_t *)(((uintptr_t)(obj)) + rb_gc_obj_slot_size(obj)))
|
|
|
|
|
2020-03-10 02:22:11 +09:00
|
|
|
uint32_t rb_ractor_current_id(void);
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
rb_ractor_setup_belonging_to(VALUE obj, uint32_t rid)
|
|
|
|
{
|
2022-11-18 10:07:06 -05:00
|
|
|
RACTOR_BELONGING_ID(obj) = rid;
|
2020-03-10 02:22:11 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline uint32_t
|
|
|
|
rb_ractor_belonging(VALUE obj)
|
|
|
|
{
|
2020-10-21 22:56:35 +09:00
|
|
|
if (SPECIAL_CONST_P(obj) || RB_OBJ_SHAREABLE_P(obj)) {
|
2020-03-10 02:22:11 +09:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else {
|
2022-11-18 10:07:06 -05:00
|
|
|
return RACTOR_BELONGING_ID(obj);
|
2020-03-10 02:22:11 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline VALUE
|
|
|
|
rb_ractor_confirm_belonging(VALUE obj)
|
|
|
|
{
|
|
|
|
uint32_t id = rb_ractor_belonging(obj);
|
|
|
|
|
|
|
|
if (id == 0) {
|
2020-09-16 09:11:16 +09:00
|
|
|
if (UNLIKELY(!rb_ractor_shareable_p(obj))) {
|
2020-03-10 02:22:11 +09:00
|
|
|
rp(obj);
|
|
|
|
rb_bug("id == 0 but not shareable");
|
|
|
|
}
|
|
|
|
}
|
2020-09-16 09:11:16 +09:00
|
|
|
else if (UNLIKELY(id != rb_ractor_current_id())) {
|
2020-10-21 22:56:35 +09:00
|
|
|
if (rb_ractor_shareable_p(obj)) {
|
|
|
|
// ok
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rp(obj);
|
|
|
|
rb_bug("rb_ractor_confirm_belonging object-ractor id:%u, current-ractor id:%u", id, rb_ractor_current_id());
|
|
|
|
}
|
2020-03-10 02:22:11 +09:00
|
|
|
}
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#define rb_ractor_confirm_belonging(obj) obj
|
|
|
|
#endif
|