mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-27 15:52:28 +00:00
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:
parent
fdab49b30e
commit
15ea0524b3
17 changed files with 164 additions and 163 deletions
|
@ -45,7 +45,8 @@
|
|||
#include "libc/thread/posixthread.internal.h"
|
||||
#include "libc/thread/tls.h"
|
||||
|
||||
extern atomic_uint free_waiters_mu;
|
||||
extern pthread_mutex_t nsync_waiters_mu;
|
||||
extern pthread_mutex_t _pthread_lock_obj;
|
||||
|
||||
static void _onfork_prepare(void) {
|
||||
if (_weaken(_pthread_onfork_prepare))
|
||||
|
@ -53,12 +54,11 @@ static void _onfork_prepare(void) {
|
|||
_pthread_lock();
|
||||
__maps_lock();
|
||||
__fds_lock();
|
||||
while (atomic_exchange_explicit(&free_waiters_mu, 1, memory_order_acquire)) {
|
||||
}
|
||||
pthread_mutex_lock(&nsync_waiters_mu);
|
||||
}
|
||||
|
||||
static void _onfork_parent(void) {
|
||||
atomic_store_explicit(&free_waiters_mu, 0, memory_order_release);
|
||||
pthread_mutex_unlock(&nsync_waiters_mu);
|
||||
__fds_unlock();
|
||||
__maps_unlock();
|
||||
_pthread_unlock();
|
||||
|
@ -67,13 +67,9 @@ static void _onfork_parent(void) {
|
|||
}
|
||||
|
||||
static void _onfork_child(void) {
|
||||
pthread_mutexattr_t attr;
|
||||
pthread_mutexattr_init(&attr);
|
||||
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
|
||||
pthread_mutex_init(&__fds_lock_obj, &attr);
|
||||
atomic_store_explicit(&free_waiters_mu, 0, memory_order_relaxed);
|
||||
pthread_mutexattr_destroy(&attr);
|
||||
_pthread_init();
|
||||
__fds_lock_obj = (pthread_mutex_t)PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
|
||||
nsync_waiters_mu = (pthread_mutex_t)PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
|
||||
_pthread_lock_obj = (pthread_mutex_t)PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
|
||||
atomic_store_explicit(&__maps.lock, 0, memory_order_relaxed);
|
||||
atomic_store_explicit(&__get_tls()->tib_relock_maps, 0, memory_order_relaxed);
|
||||
if (_weaken(_pthread_onfork_child))
|
||||
|
@ -138,9 +134,8 @@ int _fork(uint32_t dwCreationFlags) {
|
|||
atomic_store_explicit(&pt->pt_canceled, false, memory_order_relaxed);
|
||||
|
||||
// run user fork callbacks
|
||||
if (__threaded) {
|
||||
if (__threaded)
|
||||
_onfork_child();
|
||||
}
|
||||
STRACE("fork() → 0 (child of %d)", parent);
|
||||
} else {
|
||||
// this is the parent process
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue