mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-07 19:58:30 +00:00
Make more threading improvements
- ASAN memory morgue is now lockless - Make C11 atomics header more portable - Rewrote pthread keys support to be lockless - Simplify Python's unicode table unpacking code - Make crash report write(2) closer to being atomic - Make it possible to strace/ftrace a single thread - ASAN now checks nul-terminated strings fast and properly - Windows fork() now restores TLS memory of calling thread
This commit is contained in:
parent
d7b88734cd
commit
e522aa3a07
189 changed files with 1363 additions and 1217 deletions
|
@ -480,7 +480,7 @@ static void PtyWriteTab(struct Pty *pty) {
|
|||
}
|
||||
}
|
||||
|
||||
int PtyAtoi(const char *s, const char **e) {
|
||||
static int PtyAtoi(const char *s, const char **e) {
|
||||
int i;
|
||||
for (i = 0; isdigit(*s); ++s) i *= 10, i += *s - '0';
|
||||
if (e) *e = s;
|
||||
|
@ -1102,7 +1102,8 @@ ssize_t PtyWrite(struct Pty *pty, const void *data, size_t n) {
|
|||
if (--pty->n8) break;
|
||||
}
|
||||
wc = pty->u8;
|
||||
if ((0x00 <= wc && wc <= 0x1F) || (0x7F <= wc && wc <= 0x9F)) {
|
||||
if ((0x00 <= wc && wc <= 0x1F) || //
|
||||
(0x7F <= wc && wc <= 0x9F)) {
|
||||
PtyCntrl(pty, wc);
|
||||
} else {
|
||||
PtyWriteGlyph(pty, wc, wcwidth(wc));
|
||||
|
|
|
@ -179,28 +179,28 @@ STATIC_YOINK("ShowCrashReportsEarly");
|
|||
#define HeaderEqualCase(H, S) \
|
||||
SlicesEqualCase(S, strlen(S), HeaderData(H), HeaderLength(H))
|
||||
|
||||
#define TRACE_BEGIN \
|
||||
do { \
|
||||
if (!IsTiny()) { \
|
||||
if (funtrace) { \
|
||||
atomic_fetch_add_explicit(&__ftrace, 1, memory_order_relaxed); \
|
||||
} \
|
||||
if (systrace) { \
|
||||
atomic_fetch_add_explicit(&__strace, 1, memory_order_relaxed); \
|
||||
} \
|
||||
} \
|
||||
#define TRACE_BEGIN \
|
||||
do { \
|
||||
if (!IsTiny()) { \
|
||||
if (funtrace) { \
|
||||
ftrace_enabled(+1); \
|
||||
} \
|
||||
if (systrace) { \
|
||||
strace_enabled(+1); \
|
||||
} \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define TRACE_END \
|
||||
do { \
|
||||
if (!IsTiny()) { \
|
||||
if (funtrace) { \
|
||||
atomic_fetch_sub_explicit(&__ftrace, 1, memory_order_relaxed); \
|
||||
} \
|
||||
if (systrace) { \
|
||||
atomic_fetch_sub_explicit(&__strace, 1, memory_order_relaxed); \
|
||||
} \
|
||||
} \
|
||||
#define TRACE_END \
|
||||
do { \
|
||||
if (!IsTiny()) { \
|
||||
if (funtrace) { \
|
||||
ftrace_enabled(-1); \
|
||||
} \
|
||||
if (systrace) { \
|
||||
strace_enabled(-1); \
|
||||
} \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
// letters not used: INOQYnoqwxy
|
||||
|
@ -5385,16 +5385,16 @@ static void LuaPrint(lua_State *L) {
|
|||
|
||||
static void EnableRawMode(void) {
|
||||
if (lua_repl_isterminal) {
|
||||
--__strace;
|
||||
strace_enabled(-1);
|
||||
linenoiseEnableRawMode(0);
|
||||
++__strace;
|
||||
strace_enabled(+1);
|
||||
}
|
||||
}
|
||||
|
||||
static void DisableRawMode(void) {
|
||||
--__strace;
|
||||
strace_enabled(-1);
|
||||
linenoiseDisableRawMode();
|
||||
++__strace;
|
||||
strace_enabled(+1);
|
||||
}
|
||||
|
||||
static int LuaInterpreter(lua_State *L) {
|
||||
|
@ -6893,14 +6893,14 @@ static void MakeExecutableModifiable(void) {
|
|||
if (IsNetbsd()) return; // TODO
|
||||
if (_endswith(zpath, ".com.dbg")) return;
|
||||
close(zfd);
|
||||
ft = __ftrace;
|
||||
ft = ftrace_enabled(0);
|
||||
if ((zfd = OpenExecutable()) == -1) {
|
||||
WARNF("(srvr) can't open executable for modification: %m");
|
||||
}
|
||||
if (ft > 0) {
|
||||
__ftrace = 0;
|
||||
ftrace_install();
|
||||
__ftrace = ft;
|
||||
ftrace_enabled(ft);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6980,9 +6980,9 @@ static int HandlePoll(int ms) {
|
|||
rc = HandleReadline();
|
||||
if (rc < 0) return rc;
|
||||
} else {
|
||||
--__strace;
|
||||
strace_enabled(-1);
|
||||
linenoiseRefreshLine(lua_repl_linenoise);
|
||||
++__strace;
|
||||
strace_enabled(+1);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -17,10 +17,10 @@
|
|||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/intrin/strace.internal.h"
|
||||
#include "libc/calls/struct/sigaction.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/intrin/likely.h"
|
||||
#include "libc/intrin/strace.internal.h"
|
||||
#include "libc/log/countbranch.h"
|
||||
#include "libc/log/countexpr.h"
|
||||
#include "libc/log/log.h"
|
||||
|
@ -673,9 +673,9 @@ struct T DispatchTrace(dword ea, dword tm, dword r, dword p1, dword p2,
|
|||
struct T DispatchFtrace(dword ea, dword tm, dword r, dword p1, dword p2,
|
||||
dword d) {
|
||||
ftrace_install();
|
||||
++__ftrace;
|
||||
ftrace_enabled(+1);
|
||||
ea = MAKE(recurse(MAKE(Cadr(LO(ea)), HI(ea)), p1, p2), 0);
|
||||
--__ftrace;
|
||||
ftrace_enabled(-1);
|
||||
return Ret(ea, tm, r);
|
||||
}
|
||||
|
||||
|
|
|
@ -80,8 +80,8 @@ int Vfnprintf(const char *f, va_list va, int fd, int n) {
|
|||
int b, c, i, x, y, si, prec, cols, sign;
|
||||
gotr = false;
|
||||
t = rdtsc();
|
||||
--__ftrace;
|
||||
--__strace;
|
||||
ftrace_enabled(-1);
|
||||
strace_enabled(-1);
|
||||
++recursive;
|
||||
for (ansi = 0;;) {
|
||||
for (;;) {
|
||||
|
@ -290,8 +290,8 @@ int Vfnprintf(const char *f, va_list va, int fd, int n) {
|
|||
}
|
||||
}
|
||||
--recursive;
|
||||
++__ftrace;
|
||||
++__strace;
|
||||
ftrace_enabled(+1);
|
||||
strace_enabled(+1);
|
||||
if (!recursive) {
|
||||
u = rdtsc();
|
||||
if (gotr) {
|
||||
|
|
|
@ -17,8 +17,8 @@
|
|||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/intrin/strace.internal.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/intrin/strace.internal.h"
|
||||
#include "libc/log/check.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/str/str.h"
|
||||
|
@ -280,10 +280,10 @@ static int Read1(int fd) {
|
|||
|
||||
int Read(int fd) {
|
||||
int r;
|
||||
--__ftrace;
|
||||
--__strace;
|
||||
ftrace_enabled(-1);
|
||||
strace_enabled(-1);
|
||||
r = Read1(fd);
|
||||
++__ftrace;
|
||||
++__strace;
|
||||
strace_enabled(+1);
|
||||
ftrace_enabled(+1);
|
||||
return r;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue