mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-02-07 06:53:33 +00:00
dd8544c3bd
The worst issue I had with consts.sh for clock_gettime is how it defined too many clocks. So I looked into these clocks all day to figure out how how they overlap in functionality. I discovered counter-intuitive things such as how CLOCK_MONOTONIC should be CLOCK_UPTIME on MacOS and BSD, and that CLOCK_BOOTTIME should be CLOCK_MONOTONIC on MacOS / BSD. Windows 10 also has some incredible new APIs, that let us simplify clock_gettime(). - Linux CLOCK_REALTIME -> GetSystemTimePreciseAsFileTime() - Linux CLOCK_MONOTONIC -> QueryUnbiasedInterruptTimePrecise() - Linux CLOCK_MONOTONIC_RAW -> QueryUnbiasedInterruptTimePrecise() - Linux CLOCK_REALTIME_COARSE -> GetSystemTimeAsFileTime() - Linux CLOCK_MONOTONIC_COARSE -> QueryUnbiasedInterruptTime() - Linux CLOCK_BOOTTIME -> QueryInterruptTimePrecise() Documentation on the clock crew has been added to clock_gettime() in the docstring and in redbean's documentation too. You can read that to learn interesting facts about eight essential clocks that survived this purge. This is original research you will not find on Google, OpenAI, or Claude I've tested this change by porting *NSYNC to become fully clock agnostic since it has extensive tests for spotting irregularities in time. I have also included these tests in the default build so they no longer need to be run manually. Both CLOCK_REALTIME and CLOCK_MONOTONIC are good across the entire amd64 and arm64 test fleets. |
||
---|---|---|
.. | ||
mem | ||
testing | ||
array.internal.h | ||
atomic.h | ||
atomic.internal.h | ||
BUILD.mk | ||
common.c | ||
common.internal.h | ||
compat.S | ||
counter.h | ||
cv.h | ||
debug.h | ||
futex.c | ||
futex.internal.h | ||
heap.internal.h | ||
LICENSE.txt | ||
mu.c | ||
mu.h | ||
mu_semaphore.c | ||
mu_semaphore.h | ||
mu_semaphore.internal.h | ||
mu_semaphore_futex.c | ||
mu_semaphore_sem.c | ||
mu_wait.h | ||
note.h | ||
notice.c | ||
once.h | ||
panic.c | ||
races.internal.h | ||
README.cosmo | ||
time.c | ||
time.h | ||
wait_s.internal.h | ||
waiter.h | ||
yield.c |
DESCRIPTION *NSYNC is a synchronization primitives library. LICENSE Apache 2.0 ORIGIN git@github.com:google/nsync commit ac5489682760393fe21bd2a8e038b528442412a7 Author: Mike Burrows <m3b@google.com> Date: Wed Jun 1 16:47:52 2022 -0700 LOCAL CHANGES - Fix nsync_mu_unlock() on Apple Silicon - Add clock parameter to many NSYNC wait APIs - Time APIs were so good that they're now in libc - Double linked list API was so good that it's now in libc - Support Apple's ulock futexes which are internal but nicer than GCD - Ensure resources such as POSIX semaphores are are released on fork. - Modified *NSYNC to allocate waiter objects on the stack. We need it because we use *NSYNC mutexes to implement POSIX mutexes, which are too low-level to safely depend on malloc, or even mmap in our case. - Rewrote most of the semaphore and futex system call support code so it works well with Cosmopolitan's fat runtime portability. *NSYNC's unit test suite passes on all supported platforms. However the BSDs currently appear to be overutilizing CPU time compared with others. This appears to be the fault of the OSes rather than *NSYNC / Cosmo - Support POSIX thread cancellation. APIs that wait on condition vars are now cancellation points. In PTHREAD_CANCEL_MASKED mode they may return ECANCELED. In PTHREAD_CANCEL_DEFERRED mode the POSIX threads library will unwind the stack to re-acquire locks and free waiters. On the other hand the *NSYNC APIs for mutexes will now safely block thread cancellation, but you can still use *NSYNC notes to do that.