thread.c (timespec_update_expire): improve naming

Naming the constant timespec as "end" should make it more
apparent is is an absolute time.  Update callers, too.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62455 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
normal 2018-02-18 00:38:40 +00:00
parent 63d19f6bf2
commit b160a1139e

View File

@ -911,11 +911,11 @@ thread_join_sleep(VALUE arg)
{ {
struct join_arg *p = (struct join_arg *)arg; struct join_arg *p = (struct join_arg *)arg;
rb_thread_t *target_th = p->target, *th = p->waiting; rb_thread_t *target_th = p->target, *th = p->waiting;
struct timespec to; struct timespec end;
if (p->limit) { if (p->limit) {
getclockofday(&to); getclockofday(&end);
timespec_add(&to, p->limit); timespec_add(&end, p->limit);
} }
while (target_th->status != THREAD_KILLED) { while (target_th->status != THREAD_KILLED) {
@ -927,7 +927,7 @@ thread_join_sleep(VALUE arg)
th->vm->sleeper--; th->vm->sleeper--;
} }
else { else {
if (timespec_update_expire(p->limit, &to)) { if (timespec_update_expire(p->limit, &end)) {
thread_debug("thread_join: timeout (thid: %"PRI_THREAD_ID")\n", thread_debug("thread_join: timeout (thid: %"PRI_THREAD_ID")\n",
thread_id_str(target_th)); thread_id_str(target_th));
return Qfalse; return Qfalse;
@ -1197,19 +1197,24 @@ timespec_sub(struct timespec *dst, const struct timespec *tv)
} }
} }
/*
* @end is the absolute time when @ts is set to expire
* Returns true if @end has past
* Updates @ts and returns false otherwise
*/
static int static int
timespec_update_expire(struct timespec *ts, const struct timespec *to) timespec_update_expire(struct timespec *ts, const struct timespec *end)
{ {
struct timespec now; struct timespec now;
getclockofday(&now); getclockofday(&now);
if (to->tv_sec < now.tv_sec) return 1; if (end->tv_sec < now.tv_sec) return 1;
if (to->tv_sec == now.tv_sec && to->tv_nsec <= now.tv_nsec) return 1; if (end->tv_sec == now.tv_sec && end->tv_nsec <= now.tv_nsec) return 1;
thread_debug("timespec_update_expire: " thread_debug("timespec_update_expire: "
"%"PRI_TIMET_PREFIX"d.%.6ld > %"PRI_TIMET_PREFIX"d.%.6ld\n", "%"PRI_TIMET_PREFIX"d.%.6ld > %"PRI_TIMET_PREFIX"d.%.6ld\n",
(time_t)to->tv_sec, (long)to->tv_nsec, (time_t)end->tv_sec, (long)end->tv_nsec,
(time_t)now.tv_sec, (long)now.tv_nsec); (time_t)now.tv_sec, (long)now.tv_nsec);
*ts = *to; *ts = *end;
timespec_sub(ts, &now); timespec_sub(ts, &now);
return 0; return 0;
} }
@ -1217,17 +1222,17 @@ timespec_update_expire(struct timespec *ts, const struct timespec *to)
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, int spurious_check)
{ {
struct timespec to; struct timespec end;
enum rb_thread_status prev_status = th->status; enum rb_thread_status prev_status = th->status;
getclockofday(&to); getclockofday(&end);
timespec_add(&to, &ts); timespec_add(&end, &ts);
th->status = THREAD_STOPPED; th->status = THREAD_STOPPED;
RUBY_VM_CHECK_INTS_BLOCKING(th->ec); RUBY_VM_CHECK_INTS_BLOCKING(th->ec);
while (th->status == THREAD_STOPPED) { while (th->status == THREAD_STOPPED) {
native_sleep(th, &ts); native_sleep(th, &ts);
RUBY_VM_CHECK_INTS_BLOCKING(th->ec); RUBY_VM_CHECK_INTS_BLOCKING(th->ec);
if (timespec_update_expire(&ts, &to)) if (timespec_update_expire(&ts, &end))
break; break;
if (!spurious_check) if (!spurious_check)
break; break;