mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-16 15:40:31 +00:00
Improve lock hierarchy
- NetBSD no longer needs a spin lock to create semaphores - Windows fork() now locks process manager in correct order
This commit is contained in:
parent
7ba9a73840
commit
d3a13e8d70
14 changed files with 73 additions and 71 deletions
|
@ -30,7 +30,6 @@
|
|||
#include "libc/intrin/strace.h"
|
||||
#include "libc/intrin/weaken.h"
|
||||
#include "libc/mem/leaks.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/nt/accounting.h"
|
||||
#include "libc/nt/enum/processaccess.h"
|
||||
#include "libc/nt/enum/processcreationflags.h"
|
||||
|
@ -45,12 +44,16 @@
|
|||
#include "libc/nt/synchronization.h"
|
||||
#include "libc/nt/thread.h"
|
||||
#include "libc/proc/proc.internal.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/consts/map.h"
|
||||
#include "libc/sysv/consts/prot.h"
|
||||
#include "libc/sysv/consts/sa.h"
|
||||
#include "libc/sysv/consts/sicode.h"
|
||||
#include "libc/sysv/consts/sig.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
#include "libc/thread/tls.h"
|
||||
#include "third_party/nsync/mu.h"
|
||||
#ifdef __x86_64__
|
||||
|
||||
/**
|
||||
|
@ -273,27 +276,21 @@ textwindows void __proc_wipe(void) {
|
|||
textwindows struct Proc *__proc_new(void) {
|
||||
struct Dll *e;
|
||||
struct Proc *proc = 0;
|
||||
// fork() + wait() don't depend on malloc() so neither shall we
|
||||
if (__proc.allocated < ARRAYLEN(__proc.pool)) {
|
||||
proc = __proc.pool + __proc.allocated++;
|
||||
} else {
|
||||
if ((e = dll_first(__proc.free))) {
|
||||
proc = PROC_CONTAINER(e);
|
||||
dll_remove(&__proc.free, &proc->elem);
|
||||
}
|
||||
if (!proc) {
|
||||
if (_weaken(malloc)) {
|
||||
proc = may_leak(_weaken(malloc)(sizeof(struct Proc)));
|
||||
} else {
|
||||
enomem();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if ((e = dll_first(__proc.free))) {
|
||||
proc = PROC_CONTAINER(e);
|
||||
dll_remove(&__proc.free, &proc->elem);
|
||||
}
|
||||
if (proc) {
|
||||
bzero(proc, sizeof(*proc));
|
||||
dll_init(&proc->elem);
|
||||
} else {
|
||||
proc = mmap(0, sizeof(struct Proc), PROT_READ | PROT_WRITE,
|
||||
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
|
||||
if (proc == MAP_FAILED) {
|
||||
enomem();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
dll_init(&proc->elem);
|
||||
return proc;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue