mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
introduce rb_ractor_atfork()
to reset main ractor at fork().
This commit is contained in:
parent
7fcb6b3dbe
commit
7340e7f827
3 changed files with 22 additions and 5 deletions
18
ractor.c
18
ractor.c
|
@ -1477,6 +1477,24 @@ rb_ractor_main_alloc(void)
|
|||
return r;
|
||||
}
|
||||
|
||||
#if defined(HAVE_WORKING_FORK)
|
||||
void
|
||||
rb_ractor_atfork(rb_vm_t *vm, rb_thread_t *th)
|
||||
{
|
||||
// initialize as a main ractor
|
||||
vm->ractor.cnt = 0;
|
||||
vm->ractor.blocking_cnt = 0;
|
||||
ruby_single_main_ractor = th->ractor;
|
||||
th->ractor->status_ = ractor_created;
|
||||
|
||||
rb_ractor_living_threads_init(th->ractor);
|
||||
rb_ractor_living_threads_insert(th->ractor, th);
|
||||
|
||||
VM_ASSERT(vm->ractor.blocking_cnt == 0);
|
||||
VM_ASSERT(vm->ractor.cnt == 1);
|
||||
}
|
||||
#endif
|
||||
|
||||
void rb_gvl_init(rb_global_vm_lock_t *gvl);
|
||||
|
||||
void
|
||||
|
|
|
@ -182,6 +182,7 @@ void rb_ractor_terminate_interrupt_main_thread(rb_ractor_t *r);
|
|||
void rb_ractor_terminate_all(void);
|
||||
bool rb_ractor_main_p_(void);
|
||||
void rb_ractor_finish_marking(void);
|
||||
void rb_ractor_atfork(rb_vm_t *vm, rb_thread_t *th);
|
||||
|
||||
RUBY_SYMBOL_EXPORT_BEGIN
|
||||
bool rb_ractor_shareable_p_continue(VALUE obj);
|
||||
|
|
8
thread.c
8
thread.c
|
@ -4719,6 +4719,7 @@ rb_clear_coverages(void)
|
|||
}
|
||||
|
||||
#if defined(HAVE_WORKING_FORK)
|
||||
|
||||
static void
|
||||
rb_thread_atfork_internal(rb_thread_t *th, void (*atfork)(rb_thread_t *, const rb_thread_t *))
|
||||
{
|
||||
|
@ -4741,11 +4742,7 @@ rb_thread_atfork_internal(rb_thread_t *th, void (*atfork)(rb_thread_t *, const r
|
|||
}
|
||||
rb_vm_living_threads_init(vm);
|
||||
|
||||
// threads
|
||||
vm->ractor.cnt = 0;
|
||||
rb_ractor_living_threads_init(th->ractor);
|
||||
rb_ractor_living_threads_insert(th->ractor, th);
|
||||
|
||||
rb_ractor_atfork(vm, th);
|
||||
|
||||
/* may be held by MJIT threads in parent */
|
||||
rb_native_mutex_initialize(&vm->waitpid_lock);
|
||||
|
@ -4758,6 +4755,7 @@ rb_thread_atfork_internal(rb_thread_t *th, void (*atfork)(rb_thread_t *, const r
|
|||
rb_ractor_sleeper_threads_clear(th->ractor);
|
||||
rb_clear_coverages();
|
||||
|
||||
VM_ASSERT(vm->ractor.blocking_cnt == 0);
|
||||
VM_ASSERT(vm->ractor.cnt == 1);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue