mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-03 03:02:28 +00:00
Make recursive mutexes faster
Recursive mutexes now go as fast as normal mutexes. The tradeoff is they are no longer safe to use in signal handlers. However you can still have signal safe mutexes if you set your mutex to both recursive and pshared. You can also make functions that use recursive mutexes signal safe using sigprocmask to ensure recursion doesn't happen due to any signal handler The impact of this change is that, on Windows, many functions which edit the file descriptor table rely on recursive mutexes, e.g. open(). If you develop your app so it uses pread() and pwrite() then your app should go very fast when performing a heavily multithreaded and contended workload For example, when scaling to 40+ cores, *NSYNC mutexes can go as much as 1000x faster (in CPU time) than the naive recursive lock implementation. Now recursive will use *NSYNC under the hood when it's possible to do so
This commit is contained in:
parent
58d252f3db
commit
2f48a02b44
37 changed files with 2684 additions and 2209 deletions
|
@ -18,6 +18,7 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/calls/state.internal.h"
|
||||
#include "libc/calls/struct/sigset.internal.h"
|
||||
#include "libc/calls/syscall_support-nt.internal.h"
|
||||
#include "libc/nt/createfile.h"
|
||||
#include "libc/nt/enum/accessmask.h"
|
||||
|
@ -33,7 +34,8 @@
|
|||
#include "libc/sysv/errfuns.h"
|
||||
#ifdef __x86_64__
|
||||
|
||||
textwindows int sys_socketpair_nt(int family, int type, int proto, int sv[2]) {
|
||||
textwindows static int sys_socketpair_nt_impl(int family, int type, int proto,
|
||||
int sv[2]) {
|
||||
uint32_t mode;
|
||||
int64_t hpipe, h1;
|
||||
char16_t pipename[64];
|
||||
|
@ -111,4 +113,12 @@ textwindows int sys_socketpair_nt(int family, int type, int proto, int sv[2]) {
|
|||
return rc;
|
||||
}
|
||||
|
||||
textwindows int sys_socketpair_nt(int family, int type, int proto, int sv[2]) {
|
||||
int rc;
|
||||
BLOCK_SIGNALS;
|
||||
rc = sys_socketpair_nt_impl(family, type, proto, sv);
|
||||
ALLOW_SIGNALS;
|
||||
return rc;
|
||||
}
|
||||
|
||||
#endif /* __x86_64__ */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue