summaryrefslogtreecommitdiff
path: root/thread.c
diff options
context:
space:
mode:
authorKoichi Sasada <ko1@atdot.net>2022-04-17 03:40:23 +0900
committerKoichi Sasada <ko1@atdot.net>2022-04-22 07:54:09 +0900
commit1c4fc0241d125879e1e5169f267f26637772f3a7 (patch)
treed23704a9fc31fe8bfb29835ce0bdae3dc278b513 /thread.c
parentcb02324c4e5c7aae0add0a5c4e5adbf637d9acb0 (diff)
downloadruby-1c4fc0241d125879e1e5169f267f26637772f3a7.tar.gz
rename thread internal naming
Now GVL is not process *Global* so this patch try to use another words. * `rb_global_vm_lock_t` -> `struct rb_thread_sched` * `gvl->owner` -> `sched->running` * `gvl->waitq` -> `sched->readyq` * `rb_gvl_init` -> `rb_thread_sched_init` * `gvl_destroy` -> `rb_thread_sched_destroy` * `gvl_acquire` -> `thread_sched_to_running` # waiting -> ready -> running * `gvl_release` -> `thread_sched_to_waiting` # running -> waiting * `gvl_yield` -> `thread_sched_yield` * `GVL_UNLOCK_BEGIN` -> `THREAD_BLOCKING_BEGIN` * `GVL_UNLOCK_END` -> `THREAD_BLOCKING_END` * removed * `rb_ractor_gvl` * `rb_vm_gvl_destroy` (not used) There are GVL functions such as `rb_thread_call_without_gvl()` yet but I don't have good name to replace them. Maybe GVL stands for "Greate Valuable Lock" or something like that.
Diffstat (limited to 'thread.c')
-rw-r--r--thread.c37
1 files changed, 17 insertions, 20 deletions
diff --git a/thread.c b/thread.c
index 1d32d6dc15..7881a8c05b 100644
--- a/thread.c
+++ b/thread.c
@@ -70,6 +70,8 @@
# include <alloca.h>
#endif
+#define TH_SCHED(th) (&(th)->ractor->threads.sched)
+
#include "eval_intern.h"
#include "gc.h"
#include "hrtime.h"
@@ -170,12 +172,13 @@ static inline int blocking_region_begin(rb_thread_t *th, struct rb_blocking_regi
rb_unblock_function_t *ubf, void *arg, int fail_if_interrupted);
static inline void blocking_region_end(rb_thread_t *th, struct rb_blocking_region_buffer *region);
-#define GVL_UNLOCK_BEGIN(th) do { \
+#define THREAD_BLOCKING_BEGIN(th) do { \
+ struct rb_thread_sched * const sched = TH_SCHED(th); \
RB_GC_SAVE_MACHINE_CONTEXT(th); \
- gvl_release(rb_ractor_gvl(th->ractor));
+ thread_sched_to_waiting(sched);
-#define GVL_UNLOCK_END(th) \
- gvl_acquire(rb_ractor_gvl(th->ractor), th); \
+#define THREAD_BLOCKING_END(th) \
+ thread_sched_to_running(sched, th); \
rb_ractor_thread_switch(th->ractor, th); \
} while(0)
@@ -399,13 +402,6 @@ rb_thread_debug(
#include "thread_sync.c"
void
-rb_vm_gvl_destroy(rb_global_vm_lock_t *gvl)
-{
- gvl_release(gvl);
- gvl_destroy(gvl);
-}
-
-void
rb_nativethread_lock_initialize(rb_nativethread_lock_t *lock)
{
rb_native_mutex_initialize(lock);
@@ -756,6 +752,7 @@ thread_do_start(rb_thread_t *th)
}
void rb_ec_clear_current_thread_trace_func(const rb_execution_context_t *ec);
+#define thread_sched_to_dead thread_sched_to_waiting
static int
thread_start_func_2(rb_thread_t *th, VALUE *stack_start)
@@ -771,7 +768,7 @@ thread_start_func_2(rb_thread_t *th, VALUE *stack_start)
thread_debug("thread start: %p\n", (void *)th);
// setup native thread
- gvl_acquire(rb_ractor_gvl(th->ractor), th);
+ thread_sched_to_running(TH_SCHED(th), th);
ruby_thread_set_native(th);
// setup ractor
@@ -896,12 +893,12 @@ thread_start_func_2(rb_thread_t *th, VALUE *stack_start)
// after rb_ractor_living_threads_remove()
// GC will happen anytime and this ractor can be collected (and destroy GVL).
// So gvl_release() should be before it.
- gvl_release(rb_ractor_gvl(th->ractor));
+ thread_sched_to_dead(TH_SCHED(th));
rb_ractor_living_threads_remove(th->ractor, th);
}
else {
rb_ractor_living_threads_remove(th->ractor, th);
- gvl_release(rb_ractor_gvl(th->ractor));
+ thread_sched_to_dead(TH_SCHED(th));
}
return 0;
@@ -1545,7 +1542,7 @@ rb_thread_schedule_limits(uint32_t limits_us)
if (th->running_time_us >= limits_us) {
thread_debug("rb_thread_schedule/switch start\n");
RB_GC_SAVE_MACHINE_CONTEXT(th);
- gvl_yield(rb_ractor_gvl(th->ractor), th);
+ thread_sched_yield(TH_SCHED(th), th);
rb_ractor_thread_switch(th->ractor, th);
thread_debug("rb_thread_schedule/switch done\n");
}
@@ -1572,7 +1569,7 @@ blocking_region_begin(rb_thread_t *th, struct rb_blocking_region_buffer *region,
rb_ractor_blocking_threads_inc(th->ractor, __FILE__, __LINE__);
thread_debug("enter blocking region (%p)\n", (void *)th);
RB_GC_SAVE_MACHINE_CONTEXT(th);
- gvl_release(rb_ractor_gvl(th->ractor));
+ thread_sched_to_waiting(TH_SCHED(th));
return TRUE;
}
else {
@@ -1588,7 +1585,7 @@ blocking_region_end(rb_thread_t *th, struct rb_blocking_region_buffer *region)
/* entry to ubf_list impossible at this point, so unregister is safe: */
unregister_ubf_list(th);
- gvl_acquire(rb_ractor_gvl(th->ractor), th);
+ thread_sched_to_running(TH_SCHED(th), th);
rb_ractor_thread_switch(th->ractor, th);
thread_debug("leave blocking region (%p)\n", (void *)th);
@@ -4658,7 +4655,7 @@ rb_thread_atfork_internal(rb_thread_t *th, void (*atfork)(rb_thread_t *, const r
r->threads.main = th;
r->status_ = ractor_created;
- gvl_atfork(rb_ractor_gvl(th->ractor));
+ thread_sched_atfork(TH_SCHED(th));
ubf_list_atfork();
// OK. Only this thread accesses:
@@ -5441,8 +5438,8 @@ Init_Thread(void)
/* main thread setting */
{
/* acquire global vm lock */
- rb_global_vm_lock_t *gvl = rb_ractor_gvl(th->ractor);
- gvl_acquire(gvl, th);
+ struct rb_thread_sched *sched = TH_SCHED(th);
+ thread_sched_to_running(sched, th);
th->pending_interrupt_queue = rb_ary_tmp_new(0);
th->pending_interrupt_queue_checked = 0;