File tree Expand file tree Collapse file tree 2 files changed +25
-4
lines changed Expand file tree Collapse file tree 2 files changed +25
-4
lines changed Original file line number Diff line number Diff line change 27
27
# include <time.h>
28
28
# include <string.h>
29
29
30
+ ZEND_API clockid_t zend_hrtime_posix_clock_id = CLOCK_MONOTONIC ;
31
+
30
32
#elif ZEND_HRTIME_PLATFORM_WINDOWS
31
33
32
34
# define WIN32_LEAN_AND_MEAN
@@ -66,5 +68,22 @@ void zend_startup_hrtime(void)
66
68
67
69
mach_timebase_info (& zend_hrtime_timerlib_info );
68
70
71
+ #elif ZEND_HRTIME_PLATFORM_POSIX
72
+
73
+ struct timespec ts ;
74
+
75
+ #ifdef CLOCK_MONOTONIC_RAW
76
+ if (EXPECTED (0 == clock_gettime (CLOCK_MONOTONIC_RAW , & ts ))) {
77
+ zend_hrtime_posix_clock_id = CLOCK_MONOTONIC_RAW ;
78
+ return ;
79
+ }
80
+ #endif
81
+
82
+ if (EXPECTED (0 == clock_gettime (zend_hrtime_posix_clock_id , & ts ))) {
83
+ return ;
84
+ }
85
+
86
+ ZEND_ASSERT (0 && "No working CLOCK_MONOTONIC* found, this should never happen" );
87
+
69
88
#endif
70
89
}
Original file line number Diff line number Diff line change @@ -72,6 +72,10 @@ ZEND_API extern double zend_hrtime_timer_scale;
72
72
# include <string.h>
73
73
ZEND_API extern mach_timebase_info_data_t zend_hrtime_timerlib_info ;
74
74
75
+ #elif ZEND_HRTIME_PLATFORM_POSIX
76
+
77
+ ZEND_API extern clockid_t zend_hrtime_posix_clock_id ;
78
+
75
79
#endif
76
80
77
81
#define ZEND_NANO_IN_SEC UINT64_C(1000000000)
@@ -92,10 +96,8 @@ static zend_always_inline zend_hrtime_t zend_hrtime(void)
92
96
return (zend_hrtime_t )mach_absolute_time () * zend_hrtime_timerlib_info .numer / zend_hrtime_timerlib_info .denom ;
93
97
#elif ZEND_HRTIME_PLATFORM_POSIX
94
98
struct timespec ts = { .tv_sec = 0 , .tv_nsec = 0 };
95
- if (EXPECTED (0 == clock_gettime (CLOCK_MONOTONIC , & ts ))) {
96
- return ((zend_hrtime_t ) ts .tv_sec * (zend_hrtime_t )ZEND_NANO_IN_SEC ) + ts .tv_nsec ;
97
- }
98
- return 0 ;
99
+ clock_gettime (zend_hrtime_posix_clock_id , & ts );
100
+ return ((zend_hrtime_t ) ts .tv_sec * (zend_hrtime_t )ZEND_NANO_IN_SEC ) + ts .tv_nsec ;
99
101
#elif ZEND_HRTIME_PLATFORM_HPUX
100
102
return (zend_hrtime_t ) gethrtime ();
101
103
#elif ZEND_HRTIME_PLATFORM_AIX
You can’t perform that action at this time.
0 commit comments