Skip to content

Commit a3e5528

Browse files
devnexennikic
authored andcommitted
hrtime implementation update for Mac
Using a more modern and simpler api available since Sierra (2016). Closes GH-6609.
1 parent 3dad63b commit a3e5528

File tree

1 file changed

+3
-10
lines changed

1 file changed

+3
-10
lines changed

ext/standard/hrtime.c

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,6 @@
3434

3535
static double _timer_scale = .0;
3636

37-
#elif PHP_HRTIME_PLATFORM_APPLE
38-
39-
# include <mach/mach_time.h>
40-
# include <string.h>
41-
static mach_timebase_info_data_t _timerlib_info;
42-
4337
#elif PHP_HRTIME_PLATFORM_HPUX
4438

4539
# include <sys/time.h>
@@ -66,9 +60,7 @@ static int _timer_init()
6660

6761
#elif PHP_HRTIME_PLATFORM_APPLE
6862

69-
if (mach_timebase_info(&_timerlib_info)) {
70-
return -1;
71-
}
63+
/* pass */
7264

7365
#elif PHP_HRTIME_PLATFORM_POSIX
7466

@@ -115,7 +107,8 @@ static zend_always_inline php_hrtime_t _timer_current(void)
115107
QueryPerformanceCounter(&lt);
116108
return (php_hrtime_t)((php_hrtime_t)lt.QuadPart * _timer_scale);
117109
#elif PHP_HRTIME_PLATFORM_APPLE
118-
return (php_hrtime_t)mach_absolute_time() * _timerlib_info.numer / _timerlib_info.denom;
110+
/* the value is of php_hrtime_t type already */
111+
return clock_gettime_nsec_np(CLOCK_MONOTONIC_RAW);
119112
#elif PHP_HRTIME_PLATFORM_POSIX
120113
struct timespec ts = { .tv_sec = 0, .tv_nsec = 0 };
121114
if (0 == clock_gettime(CLOCK_MONOTONIC, &ts)) {

0 commit comments

Comments
 (0)