[libdispatch-changes] [136] trunk/src/time.c
source_changes at macosforge.org
source_changes at macosforge.org
Wed Nov 4 15:11:04 PST 2009
Revision: 136
http://trac.macosforge.org/projects/libdispatch/changeset/136
Author: robert at fledge.watson.org
Date: 2009-11-04 15:11:04 -0800 (Wed, 04 Nov 2009)
Log Message:
-----------
Refactor time mathematics in _dispatch_timeout_ts() to avoid overflowing
timespec.tv_nsec.
Modified Paths:
--------------
trunk/src/time.c
Modified: trunk/src/time.c
===================================================================
--- trunk/src/time.c 2009-11-04 23:10:32 UTC (rev 135)
+++ trunk/src/time.c 2009-11-04 23:11:04 UTC (rev 136)
@@ -194,7 +194,7 @@
_dispatch_timeout_ts(dispatch_time_t when)
{
struct timespec ts_realtime;
- uint64_t abstime;
+ uint64_t abstime, realtime;
int ret;
if (when == 0) {
@@ -220,8 +220,10 @@
abstime = _dispatch_absolute_time();
ret = clock_gettime(CLOCK_REALTIME, &ts_realtime);
(void)dispatch_assume_zero(ret);
- ts_realtime.tv_sec += (when - abstime) / NSEC_PER_SEC;
- ts_realtime.tv_nsec += (when - abstime) % NSEC_PER_SEC;
+ realtime = ts_realtime.tv_sec * NSEC_PER_SEC + ts_realtime.tv_nsec +
+ (when - abstime);
+ ts_realtime.tv_sec = realtime / NSEC_PER_SEC;
+ ts_realtime.tv_nsec = realtime % NSEC_PER_SEC;
return (ts_realtime);
}
#endif
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/libdispatch-changes/attachments/20091104/09ee9d73/attachment.html>
More information about the libdispatch-changes
mailing list