mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-22 21:32:31 +00:00
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:
parent
7ff0ea8c13
commit
12d9e1e128
24 changed files with 254 additions and 76 deletions
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue