authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-06-12 17:16:42-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-06-12 17:43:49-07:00
logfad223d92ed34caac163695cc2a32cba80267c32
tree150a54a06351ff9317fec7be6023d1e097582146
parent506b3f6db6c13bcced94c80ddf9bd871fb721cc0

std.Progress: use a recursive mutex for stderr


1 files changed, 6 insertions(+), 1 deletions(-)

lib/std/Progress.zig+6-1
...@@ -521,6 +521,8 @@ fn windowsApiUpdateThreadRun() void {...@@ -521,6 +521,8 @@ fn windowsApiUpdateThreadRun() void {
521/// Allows the caller to freely write to stderr until `unlockStdErr` is called.521/// Allows the caller to freely write to stderr until `unlockStdErr` is called.
522///522///
523/// During the lock, any `std.Progress` information is cleared from the terminal.523/// During the lock, any `std.Progress` information is cleared from the terminal.
524///
525/// The lock is recursive; the same thread may hold the lock multiple times.
524pub fn lockStdErr() void {526pub fn lockStdErr() void {
525 stderr_mutex.lock();527 stderr_mutex.lock();
526 clearWrittenWithEscapeCodes() catch {};528 clearWrittenWithEscapeCodes() catch {};
...@@ -1378,4 +1380,7 @@ const have_sigwinch = switch (builtin.os.tag) {...@@ -1378,4 +1380,7 @@ const have_sigwinch = switch (builtin.os.tag) {
1378 else => false,1380 else => false,
1379};1381};
13801382
1381var stderr_mutex: std.Thread.Mutex = .{};1383/// The primary motivation for recursive mutex here is so that a panic while
1384/// stderr mutex is held still dumps the stack trace and other debug
1385/// information.
1386var stderr_mutex = std.Thread.Mutex.Recursive.init;