diff options
author | 2022-02-01 16:23:13 -0800 | |
---|---|---|
committer | 2022-02-01 16:23:13 -0800 | |
commit | 0a547304a7b4d807cb1fff0c641469f691b02381 (patch) | |
tree | f415c99464c79a1821afba30d47334acda478ac1 | |
parent | 45e7bb00278e92b0a1b972fcad733220068add78 (diff) | |
download | bun-0a547304a7b4d807cb1fff0c641469f691b02381.tar.gz bun-0a547304a7b4d807cb1fff0c641469f691b02381.tar.zst bun-0a547304a7b4d807cb1fff0c641469f691b02381.zip |
Set thread name
-rw-r--r-- | src/global.zig | 20 | ||||
-rw-r--r-- | src/http_client_async.zig | 3 |
2 files changed, 12 insertions, 11 deletions
diff --git a/src/global.zig b/src/global.zig index 046496029..fefc6b8bc 100644 --- a/src/global.zig +++ b/src/global.zig @@ -79,17 +79,9 @@ pub const Output = struct { source = Source.init(stdout_stream, stderr_stream); } - pub fn configureNamedThread(thread: std.Thread, name: StringTypes.stringZ) void { - if (source_set) return; + pub fn configureNamedThread(_: std.Thread, name: StringTypes.stringZ) void { + Global.setThreadName(name); configureThread(); - - // On Linux, thread may be undefined - // Fortunately, we can use a different syscall that only affects the current thread - if (Environment.isLinux) { - _ = std.os.prctl(.SET_NAME, .{@ptrToInt(name.ptr)}) catch 0; - } else { - thread.setName(name) catch {}; - } } fn isForceColor() ?bool { @@ -559,6 +551,14 @@ pub const Global = struct { return @import("root").start_time; } + pub fn setThreadName(name: StringTypes.stringZ) void { + if (Environment.isLinux) { + _ = std.os.prctl(.SET_NAME, .{@ptrToInt(name.ptr)}) catch 0; + } else if (Environment.isMac) { + _ = std.c.pthread_setname_np(name); + } + } + pub const AllocatorConfiguration = struct { verbose: bool = false, long_running: bool = false, diff --git a/src/http_client_async.zig b/src/http_client_async.zig index 107f576f3..ada77b8c4 100644 --- a/src/http_client_async.zig +++ b/src/http_client_async.zig @@ -46,6 +46,7 @@ pub fn onThreadStart() void { AsyncIO.global_loaded = true; NetworkThread.global.pool.io = &AsyncIO.global; + Global.setThreadName("HTTP"); } pub inline fn getAllocator() std.mem.Allocator { @@ -61,7 +62,7 @@ else pub const OPEN_SOCKET_FLAGS = SOCK.CLOEXEC; -pub const extremely_verbose = true; +pub const extremely_verbose = Environment.isDebug; fn writeRequest( comptime Writer: type, |