ruby-changes:51441
From: normal <ko1@a...>
Date: Wed, 13 Jun 2018 19:00:52 +0900 (JST)
Subject: [ruby-changes:51441] normal:r63647 (trunk): thread.c: use flags for sleep_* functions
normal 2018-06-13 19:00:46 +0900 (Wed, 13 Jun 2018) New Revision: 63647 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=63647 Log: thread.c: use flags for sleep_* functions Same thing as https://bugs.ruby-lang.org/issues/14798 My easily-confused mind gets function call ordering confused easily: sleep_forever(..., TRUE, FALSE); sleep_forever(..., FALSE, TRUE); Modified files: trunk/thread.c Index: thread.c =================================================================== --- thread.c (revision 63646) +++ thread.c (revision 63647) @@ -92,8 +92,13 @@ static VALUE sym_on_blocking; https://github.com/ruby/ruby/blob/trunk/thread.c#L92 static VALUE sym_never; static ID id_locals; -static void sleep_timespec(rb_thread_t *, struct timespec, int spurious_check); -static void sleep_forever(rb_thread_t *th, int nodeadlock, int spurious_check); +enum SLEEP_FLAGS { + SLEEP_DEADLOCKABLE = 0x1, + SLEEP_SPURIOUS_CHECK = 0x2 +}; + +static void sleep_timespec(rb_thread_t *, struct timespec, unsigned int fl); +static void sleep_forever(rb_thread_t *th, unsigned int fl); static void rb_thread_sleep_deadly_allow_spurious_wakeup(void); static int rb_threadptr_dead(rb_thread_t *th); static void rb_check_deadlock(rb_vm_t *vm); @@ -1135,24 +1140,25 @@ double2timespec(struct timespec *ts, dou https://github.com/ruby/ruby/blob/trunk/thread.c#L1140 } static void -sleep_forever(rb_thread_t *th, int deadlockable, int spurious_check) +sleep_forever(rb_thread_t *th, unsigned int fl) { enum rb_thread_status prev_status = th->status; - enum rb_thread_status status = deadlockable ? THREAD_STOPPED_FOREVER : THREAD_STOPPED; + enum rb_thread_status status; + status = fl & SLEEP_DEADLOCKABLE ? THREAD_STOPPED_FOREVER : THREAD_STOPPED; th->status = status; RUBY_VM_CHECK_INTS_BLOCKING(th->ec); while (th->status == status) { - if (deadlockable) { + if (fl & SLEEP_DEADLOCKABLE) { th->vm->sleeper++; rb_check_deadlock(th->vm); } native_sleep(th, 0); - if (deadlockable) { + if (fl & SLEEP_DEADLOCKABLE) { th->vm->sleeper--; } RUBY_VM_CHECK_INTS_BLOCKING(th->ec); - if (!spurious_check) + if (!(fl & SLEEP_SPURIOUS_CHECK)) break; } th->status = prev_status; @@ -1238,7 +1244,7 @@ timespec_update_expire(struct timespec * https://github.com/ruby/ruby/blob/trunk/thread.c#L1244 } static void -sleep_timespec(rb_thread_t *th, struct timespec ts, int spurious_check) +sleep_timespec(rb_thread_t *th, struct timespec ts, unsigned int fl) { struct timespec end; enum rb_thread_status prev_status = th->status; @@ -1252,7 +1258,7 @@ sleep_timespec(rb_thread_t *th, struct t https://github.com/ruby/ruby/blob/trunk/thread.c#L1258 RUBY_VM_CHECK_INTS_BLOCKING(th->ec); if (timespec_update_expire(&ts, &end)) break; - if (!spurious_check) + if (!(fl & SLEEP_SPURIOUS_CHECK)) break; } th->status = prev_status; @@ -1262,21 +1268,21 @@ void https://github.com/ruby/ruby/blob/trunk/thread.c#L1268 rb_thread_sleep_forever(void) { thread_debug("rb_thread_sleep_forever\n"); - sleep_forever(GET_THREAD(), FALSE, TRUE); + sleep_forever(GET_THREAD(), SLEEP_SPURIOUS_CHECK); } void rb_thread_sleep_deadly(void) { thread_debug("rb_thread_sleep_deadly\n"); - sleep_forever(GET_THREAD(), TRUE, TRUE); + sleep_forever(GET_THREAD(), SLEEP_DEADLOCKABLE|SLEEP_SPURIOUS_CHECK); } static void rb_thread_sleep_deadly_allow_spurious_wakeup(void) { thread_debug("rb_thread_sleep_deadly_allow_spurious_wakeup\n"); - sleep_forever(GET_THREAD(), TRUE, FALSE); + sleep_forever(GET_THREAD(), SLEEP_DEADLOCKABLE); } void @@ -1286,7 +1292,7 @@ rb_thread_wait_for(struct timeval time) https://github.com/ruby/ruby/blob/trunk/thread.c#L1292 struct timespec ts; timespec_for(&ts, &time); - sleep_timespec(th, ts, 1); + sleep_timespec(th, ts, SLEEP_SPURIOUS_CHECK); } /* -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/