Reduce code size of mandatory runtime

This change reduces o/tiny/examples/life from 44kb to 24kb in size since
it avoids linking mmap() when unnecessary. This is important, to helping
cosmo not completely lose touch with its roots.
This commit is contained in:
Justine Tunney 2024-07-04 02:50:20 -07:00
parent fdab49b30e
commit 15ea0524b3
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
17 changed files with 164 additions and 163 deletions

View file

@ -85,39 +85,38 @@ wontreturn void pthread_exit(void *rc) {
_pthread_decimate();
// run atexit handlers if orphaned thread
if (pthread_orphan_np()) {
if (_weaken(__cxa_finalize)) {
if (pthread_orphan_np())
if (_weaken(__cxa_finalize))
_weaken(__cxa_finalize)(NULL);
}
}
// transition the thread to a terminated state
status = atomic_load_explicit(&pt->pt_status, memory_order_acquire);
do {
switch (status) {
case kPosixThreadJoinable:
transition = kPosixThreadTerminated;
break;
case kPosixThreadDetached:
transition = kPosixThreadZombie;
break;
default:
__builtin_unreachable();
if (status == kPosixThreadZombie) {
transition = kPosixThreadZombie;
break;
} else if (status == kPosixThreadTerminated) {
transition = kPosixThreadTerminated;
break;
} else if (status == kPosixThreadJoinable) {
transition = kPosixThreadTerminated;
} else if (status == kPosixThreadDetached) {
transition = kPosixThreadZombie;
} else {
__builtin_trap();
}
} while (!atomic_compare_exchange_weak_explicit(
&pt->pt_status, &status, transition, memory_order_release,
memory_order_relaxed));
// make this thread a zombie if it was detached
if (transition == kPosixThreadZombie) {
if (transition == kPosixThreadZombie)
_pthread_zombify(pt);
}
// check if this is the last survivor
if (pthread_orphan_np()) {
for (const uintptr_t *p = __fini_array_end; p > __fini_array_start;) {
for (const uintptr_t *p = __fini_array_end; p > __fini_array_start;)
((void (*)(void))(*--p))();
}
_Exit(0);
}