summaryrefslogtreecommitdiff
path: root/vm.c
diff options
context:
space:
mode:
authorSamuel Williams <samuel.williams@oriontransfer.co.nz>2020-05-14 22:10:55 +1200
committerGitHub <noreply@github.com>2020-05-14 22:10:55 +1200
commit0e3b0fcdba70cf96a8e0654eb8f50aacb8024bd4 (patch)
tree74d381412dfd8ff49dd3039f8aeae09ad9e4e6e3 /vm.c
parent336119dfc5e6baae0a936d6feae780a61975479c (diff)
Thread scheduler for light weight concurrency.
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/3032 Merged-By: ioquatix <samuel@codeotaku.com>
Diffstat (limited to 'vm.c')
-rw-r--r--vm.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/vm.c b/vm.c
index 6f9c999..d286bc7 100644
--- a/vm.c
+++ b/vm.c
@@ -2620,6 +2620,8 @@ thread_mark(void *ptr)
RUBY_MARK_UNLESS_NULL(th->locking_mutex);
RUBY_MARK_UNLESS_NULL(th->name);
+ RUBY_MARK_UNLESS_NULL(th->scheduler);
+
RUBY_MARK_LEAVE("thread");
}
@@ -2734,6 +2736,10 @@ th_init(rb_thread_t *th, VALUE self)
th->self = self;
rb_threadptr_root_fiber_setup(th);
+ /* All threads are blocking until a non-blocking fiber is scheduled */
+ th->blocking = 1;
+ th->scheduler = Qnil;
+
if (self == 0) {
size_t size = th->vm->default_params.thread_vm_stack_size / sizeof(VALUE);
rb_ec_initialize_vm_stack(th->ec, ALLOC_N(VALUE, size), size);
@@ -3294,12 +3300,14 @@ Init_VM(void)
vm->self = TypedData_Wrap_Struct(rb_cRubyVM, &vm_data_type, vm);
/* create main thread */
- th->self = TypedData_Wrap_Struct(rb_cThread, &thread_data_type, th);
+ th->self = TypedData_Wrap_Struct(rb_cThread, &thread_data_type, th);
+
vm->main_thread = th;
vm->running_thread = th;
th->vm = vm;
th->top_wrapper = 0;
th->top_self = rb_vm_top_self();
+
rb_thread_set_current(th);
rb_vm_living_threads_insert(vm, th);