ruby-changes:50341
From: normal <ko1@a...>
Date: Sun, 18 Feb 2018 09:45:33 +0900 (JST)
Subject: [ruby-changes:50341] normal:r62456 (trunk): thread.c: introduce timespec_cmp for timespec comparisons
normal 2018-02-18 09:38:45 +0900 (Sun, 18 Feb 2018) New Revision: 62456 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=62456 Log: thread.c: introduce timespec_cmp for timespec comparisons This hopefully improves readability when comparing timespecs. Modified files: trunk/thread.c Index: thread.c =================================================================== --- thread.c (revision 62455) +++ thread.c (revision 62456) @@ -1197,6 +1197,26 @@ timespec_sub(struct timespec *dst, const https://github.com/ruby/ruby/blob/trunk/thread.c#L1197 } } +static int +timespec_cmp(const struct timespec *a, const struct timespec *b) +{ + if (a->tv_sec > b->tv_sec) { + return 1; + } + else if (a->tv_sec < b->tv_sec) { + return -1; + } + else { + if (a->tv_nsec > b->tv_nsec) { + return 1; + } + else if (a->tv_nsec < b->tv_nsec) { + return -1; + } + return 0; + } +} + /* * @end is the absolute time when @ts is set to expire * Returns true if @end has past @@ -1208,8 +1228,7 @@ timespec_update_expire(struct timespec * https://github.com/ruby/ruby/blob/trunk/thread.c#L1228 struct timespec now; getclockofday(&now); - if (end->tv_sec < now.tv_sec) return 1; - if (end->tv_sec == now.tv_sec && end->tv_nsec <= now.tv_nsec) return 1; + if (timespec_cmp(&now, end) >= 0) return 1; thread_debug("timespec_update_expire: " "%"PRI_TIMET_PREFIX"d.%.6ld > %"PRI_TIMET_PREFIX"d.%.6ld\n", (time_t)end->tv_sec, (long)end->tv_nsec, -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/