Improve quality of our ANSI C clock() function

It now works most excellently across all supported operating
sytsems (earlier it didn't work on NT and XNU). Demo code is
available in examples/clock.c and this change also adds some
of the newer ANSI C time functions like timespec_get(), plus
timespec_getres() which hasn't even come out yet as it's C23
This commit is contained in:
Justine Tunney 2022-09-05 21:43:49 -07:00
parent 7ff0ea8c13
commit 12d9e1e128
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
24 changed files with 254 additions and 76 deletions

View file

@ -33,13 +33,13 @@ static int PosixThread(void *arg, int tid) {
((cthread_t)__get_tls())->pthread = pt;
pt->rc = pt->start_routine(pt->arg);
}
if (atomic_load_explicit(&pt->status, memory_order_relaxed) ==
if (atomic_load_explicit(&pt->status, memory_order_acquire) ==
kPosixThreadDetached) {
atomic_store_explicit(&pt->status, kPosixThreadZombie,
memory_order_relaxed);
memory_order_release);
} else {
atomic_store_explicit(&pt->status, kPosixThreadTerminated,
memory_order_relaxed);
memory_order_release);
}
return 0;
}
@ -47,6 +47,25 @@ static int PosixThread(void *arg, int tid) {
/**
* Creates thread.
*
* Here's the OSI model of threads in Cosmopolitan:
*
*
* pthread_create() - Standard
* Abstraction
*
* _spawn() - Cosmopolitan
* Abstraction
*
* clone() - Polyfill
*
* - Kernel
* Interfaces
* sys_clone tfork
*
* CreateThread
* bsdthread_create thr_new
*
*
* @return 0 on success, or errno on error
*/
int pthread_create(pthread_t *thread, const pthread_attr_t *attr,