update the codebase for the new std.Progress API

This commit is contained in:
Andrew Kelley
2024-05-24 08:22:47 -07:00
parent f6873c6b00
commit f97c2f28fd
49 changed files with 226 additions and 355 deletions

View File

@@ -77,19 +77,28 @@ const PdbOrDwarf = union(enum) {
}
};
var stderr_mutex = std.Thread.Mutex{};
/// Allows the caller to freely write to stderr until `unlockStdErr` is called.
///
/// During the lock, any `std.Progress` information is cleared from the terminal.
pub fn lockStdErr() void {
std.Progress.lockStdErr();
}
pub fn unlockStdErr() void {
std.Progress.unlockStdErr();
}
/// Print to stderr, unbuffered, and silently returning on failure. Intended
/// for use in "printf debugging." Use `std.log` functions for proper logging.
pub fn print(comptime fmt: []const u8, args: anytype) void {
stderr_mutex.lock();
defer stderr_mutex.unlock();
lockStdErr();
defer unlockStdErr();
const stderr = io.getStdErr().writer();
nosuspend stderr.print(fmt, args) catch return;
}
pub fn getStderrMutex() *std.Thread.Mutex {
return &stderr_mutex;
@compileError("deprecated. call std.debug.lockStdErr() and std.debug.unlockStdErr() instead which will integrate properly with std.Progress");
}
/// TODO multithreaded awareness
@@ -107,8 +116,8 @@ pub fn getSelfDebugInfo() !*DebugInfo {
/// Tries to print a hexadecimal view of the bytes, unbuffered, and ignores any error returned.
/// Obtains the stderr mutex while dumping.
pub fn dump_hex(bytes: []const u8) void {
stderr_mutex.lock();
defer stderr_mutex.unlock();
lockStdErr();
defer unlockStdErr();
dump_hex_fallible(bytes) catch {};
}