issue #3978: improve st_utime's default impl. #3979
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
try to fix #3978
Background
check #3978
Research
I referred the Android platform's solution, because I have android background, and there is a loop to handle message inside android.
https://github.com/aosp-mirror/platform_frameworks_base/blob/ff007a03c01bf936d1e961a13adff9f266d5189c/core/java/android/os/Handler.java#L701-L706C6
https://github.com/aosp-mirror/platform_system_core/blob/59d9dc1f50b1ae8630ec11a431858a3cb66487b7/libutils/SystemClock.cpp#L37-L51
https://github.com/aosp-mirror/platform_system_core/blob/59d9dc1f50b1ae8630ec11a431858a3cb66487b7/libutils/Timers.cpp#L32-L55
For Linux system, we can use
clock_gettime
api, but it's first appeared in Mac OSX 10.12.man clock_gettime
The requirement is to find an alternative way to get the timestamp in microsecond unit, but the
clock_gettime
get nanoseconds, the math formula is the nanoseconds / 1000 = microsecond. Then I check the performance of this api + math division.I used those code to check the
clock_gettime
performance.Here is output:
env: Mac OS M2 chip.
We can see the
clock_gettime
is faster thangettimeofday
, so there are no performance risks.MacOS solution
clock_gettime
api only available until mac os 10.12, for the mac os older than 10.12, just keep thegettimeofday
.check osx version in
auto/options.sh
, then add MACRO inauto/depends.sh
, the MACRO isMD_OSX_HAS_NO_CLOCK_GETTIME
.CYGWIN
According to google search, it seems the
clock_gettime(CLOCK_MONOTONIC)
is not support well at least 10 years ago, but I didn't own an windows machine, so can't verify it. so keep win's solution.