Open suzp1984 opened 3 months ago
Thank you for your excellent work. Please add new tests to validate your updates in the pull request. The utest is crucial and a necessary condition for merging the pull request. Without it and automated testing, we risk introducing bugs sooner or later due to many changes over time.
Add a UT in srs root project.
Failed in cygwin?
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 inauto/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.