Introduce new time retrieval Zend-API - #21370
Conversation
c34e5e4 to
bd5fb4c
Compare
TimWolla
left a comment
There was a problem hiding this comment.
The time retrieval functions are not inlined to make it possible to be mocked in unit tests.
Is it really necessary to mock them rather than mocking their implementation default? Not allowing them to be inlined is likely going to make them expensive for basically only being a wrapper.
I have inlined php-src/tests/unit/main/test_network.c Line 40 in 53e31d5 |
|
My #21715 PR desperately needs this API, so I would appreciate if it could be merged soon. Thanks, Marc, for working on this topic! |
d35c01c to
9c071b7
Compare
9c071b7 to
55f4ef9
Compare
This is split out from #19202 to first introduce the new time retrieval API. Later PRs will follow to refactor time retrieval usages.
Key Changes
Introduced
zend_time.hA new internal header that abstracts system time functions, replacing direct usage of
<time.h>and related platform-specific APIs.Added
zend_time_real_specA unified wrapper around
clock_gettime(),timespec_get(),gettimeofday(), andtime()using the real/wall clock.Returns a
timespecstructure with up-to nanosecond precision.Added
zend_time_real_secA lightweight wrapper around
time(NULL)for simple, low-resolution time retrieval in seconds.Added
zend_time_mono_fallback_nsecA wrapper for
zend_hrtimeor falls back tozend_time_real_spec.Useful for time measurements (e.g. timeout handling) where monotonic time is preferred, but wall time is an acceptable fallback.
Added helper functions
Added utilities to simplify usage of
timevalandtimespecstructures.The time retrieval functions are not inlined to make it possible to be mocked in unit tests.