Skip to content

Commit

Permalink
Graduate some clock_gettime() constants to #define
Browse files Browse the repository at this point in the history
- CLOCK_THREAD_CPUTIME_ID
- CLOCK_PROCESS_CPUTIME_ID

Cosmo now supports the above constants universally across supported OSes
therefore it's now safe to let programs detect their presence w/ #ifdefs
  • Loading branch information
jart committed Jul 22, 2024
1 parent c83ec5f commit 3de6632
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
4 changes: 2 additions & 2 deletions ape/specification.md
Original file line number Diff line number Diff line change
Expand Up @@ -402,8 +402,8 @@ arises in the fact that our Linux-flavored GCC and Clang toolchains
producing TLS instructions that use the %fs convention.

To solve these challenges, the `cosmocc` compiler will rewrite binary
objects after they've been compiled by GCC, so that `%gs` register is
used, rather than `%fs`. Morphing x86-64 binaries after they've been
objects after they've been compiled by GCC, so that the `%gs` register
is used, rather than `%fs`. Morphing x86-64 binaries after they've been
compiled is normally difficult, due to the complexity of the machine
instruction language. However GCC provides `-mno-tls-direct-seg-refs`
which greatly reduces the complexity of this task. This flag forgoes
Expand Down
3 changes: 1 addition & 2 deletions libc/runtime/weakfree.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
* Thunks free() if it's linked, otherwise do nothing.
*/
void _weakfree(void *p) {
if (_weaken(free)) {
if (_weaken(free))
_weaken(free)(p);
}
}
6 changes: 4 additions & 2 deletions libc/sysv/consts/clock.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ extern const int CLOCK_UPTIME_PRECISE;

COSMOPOLITAN_C_END_

#define CLOCK_REALTIME 0
#define CLOCK_MONOTONIC CLOCK_MONOTONIC
#define CLOCK_REALTIME 0
#define CLOCK_MONOTONIC CLOCK_MONOTONIC
#define CLOCK_PROCESS_CPUTIME_ID CLOCK_PROCESS_CPUTIME_ID
#define CLOCK_THREAD_CPUTIME_ID CLOCK_THREAD_CPUTIME_ID

#endif /* COSMOPOLITAN_LIBC_SYSV_CONSTS_CLOCK_H_ */
2 changes: 1 addition & 1 deletion libc/thread/pthread_create.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ void _pthread_decimate(bool annihilation_only) {
if (status != kPosixThreadZombie)
break; // zombies only exist at the end of the linked list
if (atomic_load_explicit(&pt->tib->tib_tid, memory_order_acquire))
continue; // undead thread should that'll stop existing soon
continue; // undead thread that should stop existing soon
dll_remove(&_pthread_list, e);
dll_make_first(&list, e);
}
Expand Down

0 comments on commit 3de6632

Please sign in to comment.