Skip to content

Commit 40931a8

Browse files
committed
Turn back to double arithmetic for QPC, it turns out to be more reliable
1 parent d65d97b commit 40931a8

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

ext/standard/hrtime.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
# define WIN32_LEAN_AND_MEAN
3737

38-
static uint64_t _timer_freq = {0};
38+
static double _timer_scale = .0;
3939

4040
#elif PHP_HRTIME_PLATFORM_APPLE
4141

@@ -65,7 +65,7 @@ static int _timer_init()
6565
if (!QueryPerformanceFrequency(&tf) || 0 == tf.QuadPart) {
6666
return -1;
6767
}
68-
_timer_freq = (uint64_t)tf.QuadPart;
68+
_timer_scale = (double)NANO_IN_SEC / (php_hrtime_t)tf.QuadPart;
6969

7070
#elif PHP_HRTIME_PLATFORM_APPLE
7171

@@ -114,13 +114,9 @@ PHP_MINIT_FUNCTION(hrtime)
114114
static zend_always_inline php_hrtime_t _timer_current(void)
115115
{/*{{{*/
116116
#if PHP_HRTIME_PLATFORM_WINDOWS
117-
php_hrtime_t ret;
118117
LARGE_INTEGER lt = {0};
119118
QueryPerformanceCounter(&lt);
120-
ret = (php_hrtime_t)lt.QuadPart;
121-
ret *= (php_hrtime_t)NANO_IN_SEC;
122-
ret /= _timer_freq;
123-
return ret;
119+
return (php_hrtime_t)((php_hrtime_t)lt.QuadPart * _timer_scale);
124120
#elif PHP_HRTIME_PLATFORM_APPLE
125121
return (php_hrtime_t)mach_absolute_time() * _timerlib_info.numer / _timerlib_info.denom;
126122
#elif PHP_HRTIME_PLATFORM_POSIX

0 commit comments

Comments
 (0)