aboutsummaryrefslogtreecommitdiffstats
path: root/thread.c
diff options
context:
space:
mode:
authorKoichi Sasada <ko1@atdot.net>2023-03-31 19:26:06 +0900
committerKoichi Sasada <ko1@atdot.net>2023-03-31 19:26:47 +0900
commit1d19776c7f4daf30f7dae3ffb9c762ccd3669176 (patch)
tree5c06cc12f877b39fd6983d958c8d28f785389135 /thread.c
parent185f39df7916670afb2f89896d1324a5a107f480 (diff)
downloadruby-1d19776c7f4daf30f7dae3ffb9c762ccd3669176.tar.gz
cosmetic change
reorder `sleep_forever()` and so on.
Diffstat (limited to 'thread.c')
-rw-r--r--thread.c63
1 files changed, 31 insertions, 32 deletions
diff --git a/thread.c b/thread.c
index 7dd08b366a..1cfaa36958 100644
--- a/thread.c
+++ b/thread.c
@@ -116,11 +116,6 @@ static VALUE sym_immediate;
static VALUE sym_on_blocking;
static VALUE sym_never;
-enum SLEEP_FLAGS {
- SLEEP_DEADLOCKABLE = 0x1,
- SLEEP_SPURIOUS_CHECK = 0x2
-};
-
#define THREAD_LOCAL_STORAGE_INITIALISED FL_USER13
#define THREAD_LOCAL_STORAGE_INITIALISED_P(th) RB_FL_TEST_RAW((th), THREAD_LOCAL_STORAGE_INITIALISED)
@@ -134,8 +129,12 @@ rb_thread_local_storage(VALUE thread)
return rb_ivar_get(thread, idLocals);
}
+enum SLEEP_FLAGS {
+ SLEEP_DEADLOCKABLE = 0x01,
+ SLEEP_SPURIOUS_CHECK = 0x02,
+};
+
static int sleep_hrtime(rb_thread_t *, rb_hrtime_t, unsigned int fl);
-static void sleep_forever(rb_thread_t *th, unsigned int fl);
static void rb_thread_sleep_deadly_allow_spurious_wakeup(VALUE blocker, VALUE timeout, rb_hrtime_t end);
static int rb_threadptr_dead(rb_thread_t *th);
static void rb_check_deadlock(rb_ractor_t *r);
@@ -1258,32 +1257,6 @@ rb_hrtime_now(void)
return rb_timespec2hrtime(&ts);
}
-static void
-sleep_forever(rb_thread_t *th, unsigned int fl)
-{
- enum rb_thread_status prev_status = th->status;
- enum rb_thread_status status;
- int woke;
-
- status = fl & SLEEP_DEADLOCKABLE ? THREAD_STOPPED_FOREVER : THREAD_STOPPED;
- th->status = status;
- RUBY_VM_CHECK_INTS_BLOCKING(th->ec);
- while (th->status == status) {
- if (fl & SLEEP_DEADLOCKABLE) {
- rb_ractor_sleeper_threads_inc(th->ractor);
- rb_check_deadlock(th->ractor);
- }
- native_sleep(th, 0);
- if (fl & SLEEP_DEADLOCKABLE) {
- rb_ractor_sleeper_threads_dec(th->ractor);
- }
- woke = vm_check_ints_blocking(th->ec);
- if (woke && !(fl & SLEEP_SPURIOUS_CHECK))
- break;
- }
- th->status = prev_status;
-}
-
/*
* at least gcc 7.2 and 7.3 complains about "rb_hrtime_t end"
* being uninitialized, maybe other versions, too.
@@ -1358,6 +1331,32 @@ sleep_hrtime_until(rb_thread_t *th, rb_hrtime_t end, unsigned int fl)
return woke;
}
+static void
+sleep_forever(rb_thread_t *th, unsigned int fl)
+{
+ enum rb_thread_status prev_status = th->status;
+ enum rb_thread_status status;
+ int woke;
+
+ status = fl & SLEEP_DEADLOCKABLE ? THREAD_STOPPED_FOREVER : THREAD_STOPPED;
+ th->status = status;
+ RUBY_VM_CHECK_INTS_BLOCKING(th->ec);
+ while (th->status == status) {
+ if (fl & SLEEP_DEADLOCKABLE) {
+ rb_ractor_sleeper_threads_inc(th->ractor);
+ rb_check_deadlock(th->ractor);
+ }
+ native_sleep(th, 0);
+ if (fl & SLEEP_DEADLOCKABLE) {
+ rb_ractor_sleeper_threads_dec(th->ractor);
+ }
+ woke = vm_check_ints_blocking(th->ec);
+ if (woke && !(fl & SLEEP_SPURIOUS_CHECK))
+ break;
+ }
+ th->status = prev_status;
+}
+
void
rb_thread_sleep_forever(void)
{