mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-03 17:58:30 +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
|
@ -16,6 +16,7 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/intrin/atomic.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/thread/lock.h"
|
||||
#include "libc/thread/posixthread.internal.h"
|
||||
|
@ -25,11 +26,13 @@
|
|||
* Unlocks mutex from child process after fork.
|
||||
*/
|
||||
int _pthread_mutex_wipe_np(pthread_mutex_t *mutex) {
|
||||
void *edges = mutex->_edges;
|
||||
uint64_t word = mutex->_word;
|
||||
bzero(mutex, sizeof(*mutex));
|
||||
mutex->_word = MUTEX_UNLOCK(word);
|
||||
mutex->_edges = edges;
|
||||
atomic_init(&mutex->_word, MUTEX_UNLOCK(atomic_load_explicit(
|
||||
&mutex->_word, memory_order_relaxed)));
|
||||
atomic_init(&mutex->_futex, 0);
|
||||
mutex->_pid = 0;
|
||||
mutex->_nsync[0] = 0;
|
||||
atomic_signal_fence(memory_order_relaxed); // avoid xmm
|
||||
mutex->_nsync[1] = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue