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); git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63647 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
48de2ea5f9
commit
5ff2a1968d
32
thread.c
32
thread.c
@ -92,8 +92,13 @@ static VALUE sym_on_blocking;
|
|||||||
static VALUE sym_never;
|
static VALUE sym_never;
|
||||||
static ID id_locals;
|
static ID id_locals;
|
||||||
|
|
||||||
static void sleep_timespec(rb_thread_t *, struct timespec, int spurious_check);
|
enum SLEEP_FLAGS {
|
||||||
static void sleep_forever(rb_thread_t *th, int nodeadlock, int spurious_check);
|
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 void rb_thread_sleep_deadly_allow_spurious_wakeup(void);
|
||||||
static int rb_threadptr_dead(rb_thread_t *th);
|
static int rb_threadptr_dead(rb_thread_t *th);
|
||||||
static void rb_check_deadlock(rb_vm_t *vm);
|
static void rb_check_deadlock(rb_vm_t *vm);
|
||||||
@ -1135,24 +1140,25 @@ double2timespec(struct timespec *ts, double d)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
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 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;
|
th->status = status;
|
||||||
RUBY_VM_CHECK_INTS_BLOCKING(th->ec);
|
RUBY_VM_CHECK_INTS_BLOCKING(th->ec);
|
||||||
while (th->status == status) {
|
while (th->status == status) {
|
||||||
if (deadlockable) {
|
if (fl & SLEEP_DEADLOCKABLE) {
|
||||||
th->vm->sleeper++;
|
th->vm->sleeper++;
|
||||||
rb_check_deadlock(th->vm);
|
rb_check_deadlock(th->vm);
|
||||||
}
|
}
|
||||||
native_sleep(th, 0);
|
native_sleep(th, 0);
|
||||||
if (deadlockable) {
|
if (fl & SLEEP_DEADLOCKABLE) {
|
||||||
th->vm->sleeper--;
|
th->vm->sleeper--;
|
||||||
}
|
}
|
||||||
RUBY_VM_CHECK_INTS_BLOCKING(th->ec);
|
RUBY_VM_CHECK_INTS_BLOCKING(th->ec);
|
||||||
if (!spurious_check)
|
if (!(fl & SLEEP_SPURIOUS_CHECK))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
th->status = prev_status;
|
th->status = prev_status;
|
||||||
@ -1238,7 +1244,7 @@ timespec_update_expire(struct timespec *ts, const struct timespec *end)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
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;
|
struct timespec end;
|
||||||
enum rb_thread_status prev_status = th->status;
|
enum rb_thread_status prev_status = th->status;
|
||||||
@ -1252,7 +1258,7 @@ sleep_timespec(rb_thread_t *th, struct timespec ts, int spurious_check)
|
|||||||
RUBY_VM_CHECK_INTS_BLOCKING(th->ec);
|
RUBY_VM_CHECK_INTS_BLOCKING(th->ec);
|
||||||
if (timespec_update_expire(&ts, &end))
|
if (timespec_update_expire(&ts, &end))
|
||||||
break;
|
break;
|
||||||
if (!spurious_check)
|
if (!(fl & SLEEP_SPURIOUS_CHECK))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
th->status = prev_status;
|
th->status = prev_status;
|
||||||
@ -1262,21 +1268,21 @@ void
|
|||||||
rb_thread_sleep_forever(void)
|
rb_thread_sleep_forever(void)
|
||||||
{
|
{
|
||||||
thread_debug("rb_thread_sleep_forever\n");
|
thread_debug("rb_thread_sleep_forever\n");
|
||||||
sleep_forever(GET_THREAD(), FALSE, TRUE);
|
sleep_forever(GET_THREAD(), SLEEP_SPURIOUS_CHECK);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
rb_thread_sleep_deadly(void)
|
rb_thread_sleep_deadly(void)
|
||||||
{
|
{
|
||||||
thread_debug("rb_thread_sleep_deadly\n");
|
thread_debug("rb_thread_sleep_deadly\n");
|
||||||
sleep_forever(GET_THREAD(), TRUE, TRUE);
|
sleep_forever(GET_THREAD(), SLEEP_DEADLOCKABLE|SLEEP_SPURIOUS_CHECK);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
rb_thread_sleep_deadly_allow_spurious_wakeup(void)
|
rb_thread_sleep_deadly_allow_spurious_wakeup(void)
|
||||||
{
|
{
|
||||||
thread_debug("rb_thread_sleep_deadly_allow_spurious_wakeup\n");
|
thread_debug("rb_thread_sleep_deadly_allow_spurious_wakeup\n");
|
||||||
sleep_forever(GET_THREAD(), TRUE, FALSE);
|
sleep_forever(GET_THREAD(), SLEEP_DEADLOCKABLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -1286,7 +1292,7 @@ rb_thread_wait_for(struct timeval time)
|
|||||||
struct timespec ts;
|
struct timespec ts;
|
||||||
|
|
||||||
timespec_for(&ts, &time);
|
timespec_for(&ts, &time);
|
||||||
sleep_timespec(th, ts, 1);
|
sleep_timespec(th, ts, SLEEP_SPURIOUS_CHECK);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user