Skip to content

Commit 78312f5

Browse files
committed
WIP
1 parent cbf9c08 commit 78312f5

7 files changed

Lines changed: 50 additions & 1 deletion

File tree

inits.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ rb_call_inits(void)
7777
CALL(Prism);
7878
CALL(unicode_version);
7979
CALL(Set);
80+
CALL(ractor_debug);
8081

8182
// enable builtin loading
8283
CALL(builtin);

ractor.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2256,6 +2256,13 @@ bool
22562256
rb_ractor_main_p_(void)
22572257
{
22582258
VM_ASSERT(rb_multi_ractor_p());
2259+
2260+
#if RUBY_DEBUG
2261+
if (ractor_debug_mode) {
2262+
return false;
2263+
}
2264+
#endif
2265+
22592266
rb_execution_context_t *ec = GET_EC();
22602267
return rb_ec_ractor_ptr(ec) == rb_ec_vm_ptr(ec)->ractor.main_ractor;
22612268
}
@@ -4176,4 +4183,30 @@ rb_ractor_autoload_load(VALUE module, ID name)
41764183
}
41774184
}
41784185

4186+
#if RUBY_DEBUG
4187+
static VALUE
4188+
rb_ractor_debug_multi_ractor_mode(VALUE module)
4189+
{
4190+
struct rb_ractor_struct *previous_single_main_ractor = ruby_single_main_ractor;
4191+
bool previous_ractor_debug_mode = ractor_debug_mode;
4192+
4193+
ractor_debug_mode = true;
4194+
// ruby_single_main_ractor = NULL;
4195+
4196+
VALUE result = rb_yield(Qundef);
4197+
4198+
ruby_single_main_ractor = previous_single_main_ractor;
4199+
ractor_debug_mode = previous_ractor_debug_mode;
4200+
return RB_GC_GUARD(result);
4201+
}
4202+
#endif
4203+
4204+
void
4205+
Init_ractor_debug(void)
4206+
{
4207+
#if RUBY_DEBUG
4208+
rb_define_singleton_method(rb_cRactor, "debug_multi_ractor_mode", rb_ractor_debug_multi_ractor_mode, 0);
4209+
#endif
4210+
}
4211+
41794212
#include "ractor.rbinc"

ractor.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -885,7 +885,7 @@ def self.main
885885
# return true if the current ractor is main ractor
886886
def self.main?
887887
__builtin_cexpr! %q{
888-
RBOOL(GET_VM()->ractor.main_ractor == rb_ec_ractor_ptr(ec))
888+
RBOOL(rb_ractor_main_p())
889889
}
890890
end
891891

ractor_core.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,12 @@ RUBY_SYMBOL_EXPORT_END
242242
static inline bool
243243
rb_ractor_main_p(void)
244244
{
245+
#if RUBY_DEBUG
246+
if (ractor_debug_mode) {
247+
return false;
248+
}
249+
#endif
250+
245251
if (ruby_single_main_ractor) {
246252
return true;
247253
}

vm.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,10 @@ VALUE rb_block_param_proxy;
555555
VALUE ruby_vm_const_missing_count = 0;
556556
rb_vm_t *ruby_current_vm_ptr = NULL;
557557
rb_ractor_t *ruby_single_main_ractor;
558+
#if RUBY_DEBUG
559+
bool ractor_debug_mode = false;
560+
#endif
561+
558562
bool ruby_vm_keep_script_lines;
559563

560564
#ifdef RB_THREAD_LOCAL_SPECIFIER

vm_core.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1922,6 +1922,10 @@ rb_execution_context_t *rb_vm_main_ractor_ec(rb_vm_t *vm); // ractor.c
19221922
#if RUBY_VM_THREAD_MODEL == 2
19231923

19241924
RUBY_EXTERN struct rb_ractor_struct *ruby_single_main_ractor; // ractor.c
1925+
#if RUBY_DEBUG
1926+
RUBY_EXTERN bool ractor_debug_mode;
1927+
#endif
1928+
19251929
RUBY_EXTERN rb_vm_t *ruby_current_vm_ptr;
19261930
RUBY_EXTERN rb_event_flag_t ruby_vm_event_flags;
19271931
RUBY_EXTERN rb_event_flag_t ruby_vm_event_enabled_global_flags;

vm_insnhelper.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,6 +1101,7 @@ vm_get_ev_const(rb_execution_context_t *ec, VALUE orig_klass, ID id, bool allow_
11011101
return 1;
11021102
}
11031103
else {
1104+
fprintf(stderr, "here rb_ractor_main_p() = %d\n", rb_ractor_main_p());
11041105
if (UNLIKELY(!rb_ractor_main_p())) {
11051106
if (!rb_ractor_shareable_p(val)) {
11061107
rb_raise(rb_eRactorIsolationError,

0 commit comments

Comments
 (0)