mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-03 09:48:29 +00:00
Make fork() go 30% faster
This change makes fork() go nearly as fast as sys_fork() on UNIX. As for Windows this change shaves about 4-5ms off fork() + wait() latency. This is accomplished by using WriteProcessMemory() from the parent process to setup the address space of a suspended process; it is better than a pipe
This commit is contained in:
parent
98c5847727
commit
0b3c81dd4e
44 changed files with 769 additions and 649 deletions
|
@ -28,7 +28,19 @@
|
|||
|
||||
static int _rand64_pid;
|
||||
static unsigned __int128 _rand64_pool;
|
||||
pthread_mutex_t __rand64_lock_obj = PTHREAD_MUTEX_INITIALIZER;
|
||||
static pthread_mutex_t __rand64_lock_obj = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
void __rand64_lock(void) {
|
||||
_pthread_mutex_lock(&__rand64_lock_obj);
|
||||
}
|
||||
|
||||
void __rand64_unlock(void) {
|
||||
_pthread_mutex_unlock(&__rand64_lock_obj);
|
||||
}
|
||||
|
||||
void __rand64_wipe(void) {
|
||||
_pthread_mutex_wipe_np(&__rand64_lock_obj);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns nondeterministic random data.
|
||||
|
@ -43,7 +55,7 @@ pthread_mutex_t __rand64_lock_obj = PTHREAD_MUTEX_INITIALIZER;
|
|||
uint64_t _rand64(void) {
|
||||
void *p;
|
||||
uint128_t s;
|
||||
_pthread_mutex_lock(&__rand64_lock_obj);
|
||||
__rand64_lock();
|
||||
if (__pid == _rand64_pid) {
|
||||
s = _rand64_pool; // normal path
|
||||
} else {
|
||||
|
@ -64,6 +76,6 @@ uint64_t _rand64(void) {
|
|||
_rand64_pid = __pid;
|
||||
}
|
||||
_rand64_pool = (s *= 15750249268501108917ull); // lemur64
|
||||
_pthread_mutex_unlock(&__rand64_lock_obj);
|
||||
__rand64_unlock();
|
||||
return s >> 64;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue