summaryrefslogtreecommitdiff
path: root/vm.c
diff options
context:
space:
mode:
authorKoichi Sasada <ko1@atdot.net>2022-04-22 21:19:03 +0900
committerKoichi Sasada <ko1@atdot.net>2022-04-23 03:08:27 +0900
commit03d21a4fb099da7c52e6591e17704c297871b7db (patch)
treedb2d58907b7c841d8ca15967f063d229bd9e37cc /vm.c
parent69d41480ec1c91691b79f106f5376a2e2cab3a82 (diff)
downloadruby-03d21a4fb099da7c52e6591e17704c297871b7db.tar.gz
introduce struct `rb_native_thread`
`rb_thread_t` contained `native_thread_data_t` to represent thread implementation dependent data. This patch separates them and rename it `rb_native_thread` and point it from `rb_thraed_t`. Now, 1 Ruby thread (`rb_thread_t`) has 1 native thread (`rb_native_thread`).
Diffstat (limited to 'vm.c')
-rw-r--r--vm.c13
1 files changed, 6 insertions, 7 deletions
diff --git a/vm.c b/vm.c
index 8cec781f7a..8a1e01b2a3 100644
--- a/vm.c
+++ b/vm.c
@@ -3165,7 +3165,8 @@ thread_free(void *ptr)
RUBY_GC_INFO("MRI main thread\n");
}
else {
- ruby_xfree(ptr);
+ ruby_xfree(th->nt); // TODO
+ ruby_xfree(th);
}
RUBY_FREE_LEAVE("thread");
@@ -3207,11 +3208,8 @@ rb_obj_is_thread(VALUE obj)
static VALUE
thread_alloc(VALUE klass)
{
- VALUE obj;
rb_thread_t *th;
- obj = TypedData_Make_Struct(klass, rb_thread_t, &thread_data_type, th);
-
- return obj;
+ return TypedData_Make_Struct(klass, rb_thread_t, &thread_data_type, th);
}
inline void
@@ -3275,8 +3273,8 @@ th_init(rb_thread_t *th, VALUE self, rb_vm_t *vm, rb_ractor_t *r)
th->top_self = vm->top_self; // 0 while self == 0
th->value = Qundef;
-#ifdef NON_SCALAR_THREAD_ID
- th->thread_id_string[0] = '\0';
+#if defined(NON_SCALAR_THREAD_ID) && !defined(__wasm__) && !defined(__EMSCRIPTEN__)
+ th->nt->thread_id_string[0] = '\0';
#endif
th->ec->errinfo = Qnil;
@@ -3947,6 +3945,7 @@ Init_BareVM(void)
vm->constant_cache = rb_id_table_create(0);
// setup main thread
+ th->nt = ZALLOC(struct rb_native_thread);
Init_native_thread(th);
th_init(th, 0, vm, vm->ractor.main_ractor = rb_ractor_main_alloc());