diff options
author | normal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-02-18 03:00:28 +0000 |
---|---|---|
committer | normal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-02-18 03:00:28 +0000 |
commit | fbad2c55923e2895adafbd5627e1995948fe3e41 (patch) | |
tree | a7b6ccb21996fea949d04410721425cdcae78396 /thread.c | |
parent | cd0673e654806eaa42bfe9bd4580a1e034af2911 (diff) |
thread.c (double2timespec): adjust to use NULL for infinity
Using:
strace ruby -e 'Thread.new { sleep }.join(Float::INFINITY)'
Will show a difference in futex() syscall args (not that I'd
ever advocate Float::INFINITY as a Thread#join arg :P)
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62461 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'thread.c')
-rw-r--r-- | thread.c | 30 |
1 files changed, 13 insertions, 17 deletions
@@ -1003,7 +1003,7 @@ thread_join(rb_thread_t *target_th, struct timespec *ts) return target_th->self; } -static struct timespec double2timespec(double); +static struct timespec *double2timespec(struct timespec *, double); /* * call-seq: @@ -1065,8 +1065,7 @@ thread_join_m(int argc, VALUE *argv, VALUE self) ts = ×pec; break; default: - timespec = double2timespec(rb_num2dbl(limit)); - ts = ×pec; + ts = double2timespec(×pec, rb_num2dbl(limit)); } return thread_join(rb_thread_ptr(self), ts); @@ -1108,31 +1107,28 @@ thread_value(VALUE self) #define TIMESPEC_SEC_MAX TIMET_MAX #define TIMESPEC_SEC_MIN TIMET_MIN -static struct timespec -double2timespec(double d) +static struct timespec * +double2timespec(struct timespec *ts, double d) { /* assume timespec.tv_sec has same signedness as time_t */ const double TIMESPEC_SEC_MAX_PLUS_ONE = TIMET_MAX_PLUS_ONE; - struct timespec time; - if (TIMESPEC_SEC_MAX_PLUS_ONE <= d) { - time.tv_sec = TIMESPEC_SEC_MAX; - time.tv_nsec = 999999999; + return NULL; } else if (d <= TIMESPEC_SEC_MIN) { - time.tv_sec = TIMESPEC_SEC_MIN; - time.tv_nsec = 0; + ts->tv_sec = TIMESPEC_SEC_MIN; + ts->tv_nsec = 0; } else { - time.tv_sec = (time_t)d; - time.tv_nsec = (long)((d - (time_t)d) * 1e9); - if (time.tv_nsec < 0) { - time.tv_nsec += (long)1e9; - time.tv_sec -= 1; + ts->tv_sec = (time_t)d; + ts->tv_nsec = (long)((d - (time_t)d) * 1e9); + if (ts->tv_nsec < 0) { + ts->tv_nsec += (long)1e9; + ts->tv_sec -= 1; } } - return time; + return ts; } static void |