mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-02-07 06:53:33 +00:00
This change doubles the performance of thread spawning. That's thanks to our new stack manager, which allows us to avoid zeroing stacks. It gives us 15µs spawns rather than 30µs spawns on Linux. Also, pthread_exit() is faster now, since it doesn't need to acquire the pthread GIL. On NetBSD, that helps us avoid allocating too many semaphores. Even if that happens we're now able to survive semaphores running out and even memory running out, when allocating *NSYNC waiter objects. I found a lot more rare bugs in the POSIX threads runtime that could cause things to crash, if you've got dozens of threads all spawning and joining dozens of threads. I want cosmo to be world class production worthy for 2025 so happy holidays all
56 lines
1.3 KiB
C
56 lines
1.3 KiB
C
#ifndef COSMOPOLITAN_LIBC_PROC_H_
|
|
#define COSMOPOLITAN_LIBC_PROC_H_
|
|
#include "libc/atomic.h"
|
|
#include "libc/calls/struct/rusage.h"
|
|
#include "libc/intrin/atomic.h"
|
|
#include "libc/intrin/dll.h"
|
|
#include "libc/thread/thread.h"
|
|
COSMOPOLITAN_C_START_
|
|
|
|
#define PROC_ALIVE 0
|
|
#define PROC_ZOMBIE 1
|
|
#define PROC_UNDEAD 2
|
|
|
|
#define PROC_CONTAINER(e) DLL_CONTAINER(struct Proc, elem, e)
|
|
|
|
struct Proc {
|
|
int pid;
|
|
int status;
|
|
int waiters;
|
|
bool wasforked;
|
|
uint32_t wstatus;
|
|
int64_t handle;
|
|
struct Dll elem;
|
|
struct rusage ru;
|
|
};
|
|
|
|
struct Procs {
|
|
int waiters;
|
|
atomic_uint once;
|
|
pthread_mutex_t lock;
|
|
intptr_t thread;
|
|
intptr_t onbirth;
|
|
intptr_t haszombies;
|
|
struct Dll *list;
|
|
struct Dll *free;
|
|
struct Dll *undead;
|
|
struct Dll *zombies;
|
|
unsigned allocated;
|
|
struct rusage ruchlds;
|
|
};
|
|
|
|
extern struct Procs __proc;
|
|
|
|
void __proc_lock(void) libcesque;
|
|
void __proc_unlock(void) libcesque;
|
|
int64_t __proc_handle(int) libcesque;
|
|
int64_t __proc_search(int) libcesque;
|
|
struct Proc *__proc_new(void) libcesque;
|
|
void __proc_add(struct Proc *) libcesque;
|
|
void __proc_free(struct Proc *) libcesque;
|
|
void __proc_wipe_and_reset(void) libcesque;
|
|
int __proc_harvest(struct Proc *, bool) libcesque;
|
|
int sys_wait4_nt(int, int *, int, struct rusage *) libcesque;
|
|
|
|
COSMOPOLITAN_C_END_
|
|
#endif /* COSMOPOLITAN_LIBC_PROC_H_ */
|