@@ -2108,26 +2108,26 @@ struct MonoTimeImpl(ClockType clockType)
2108
2108
2109
2109
version (Windows )
2110
2110
{
2111
- long ticks;
2112
- if (QueryPerformanceCounter(&ticks) == 0 )
2113
- {
2114
- // This probably cannot happen on Windows 95 or later
2115
- import core.internal.abort : abort;
2116
- abort(" Call to QueryPerformanceCounter failed." );
2117
- }
2111
+ long ticks = void ;
2112
+ QueryPerformanceCounter(&ticks);
2118
2113
return MonoTimeImpl (ticks);
2119
2114
}
2120
2115
else version (Darwin)
2121
2116
return MonoTimeImpl (mach_absolute_time());
2122
2117
else version (Posix )
2123
2118
{
2124
- timespec ts;
2125
- if (clock_gettime(clockArg, &ts) != 0 )
2119
+ timespec ts = void ;
2120
+ immutable error = clock_gettime(clockArg, &ts);
2121
+ // clockArg is supported and if tv_sec is long or larger
2122
+ // overflow won't happen before 292 billion years A.D.
2123
+ static if (ts.tv_sec.max < long .max)
2126
2124
{
2127
- import core.internal.abort : abort;
2128
- abort(" Call to clock_gettime failed." );
2125
+ if (error)
2126
+ {
2127
+ import core.internal.abort : abort;
2128
+ abort(" Call to clock_gettime failed." );
2129
+ }
2129
2130
}
2130
-
2131
2131
return MonoTimeImpl (convClockFreq(ts.tv_sec * 1_000_000_000L + ts.tv_nsec,
2132
2132
1_000_000_000L,
2133
2133
ticksPerSecond));
@@ -3364,10 +3364,18 @@ struct TickDuration
3364
3364
{
3365
3365
static if (is (typeof (clock_gettime)))
3366
3366
{
3367
- timespec ts;
3368
- if (clock_gettime(CLOCK_MONOTONIC , &ts) != 0 )
3369
- abort(" Failed in clock_gettime()." );
3370
-
3367
+ timespec ts = void ;
3368
+ immutable error = clock_gettime(CLOCK_MONOTONIC , &ts);
3369
+ // CLOCK_MONOTONIC is supported and if tv_sec is long or larger
3370
+ // overflow won't happen before 292 billion years A.D.
3371
+ static if (ts.tv_sec.max < long .max)
3372
+ {
3373
+ if (error)
3374
+ {
3375
+ import core.internal.abort : abort;
3376
+ abort(" Call to clock_gettime failed." );
3377
+ }
3378
+ }
3371
3379
return TickDuration (ts.tv_sec * TickDuration.ticksPerSec +
3372
3380
ts.tv_nsec * TickDuration.ticksPerSec / 1000 / 1000 / 1000 );
3373
3381
}
0 commit comments