mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
debug: properly set thread names on macOS
This commit is contained in:
@ -81,6 +81,13 @@ pub fn init(gpa: Allocator) !void {
|
||||
fn initThread(gpa: Allocator) !void {
|
||||
if (comptime !build_options.sentry) return;
|
||||
|
||||
// Right now, on Darwin, `std.Thread.setName` can only name the current
|
||||
// thread, and we have no way to get the current thread from within it,
|
||||
// so instead we use this code to name the thread instead.
|
||||
if (builtin.os.tag.isDarwin()) {
|
||||
internal_os.macos.pthread_setname_np(&"sentry-init".*);
|
||||
}
|
||||
|
||||
var arena = std.heap.ArenaAllocator.init(gpa);
|
||||
defer arena.deinit();
|
||||
const alloc = arena.allocator();
|
||||
|
@ -8,6 +8,7 @@ const std = @import("std");
|
||||
const builtin = @import("builtin");
|
||||
const macos = @import("macos");
|
||||
|
||||
const internal_os = @import("../os/main.zig");
|
||||
const xev = @import("../global.zig").xev;
|
||||
const BlockingQueue = @import("../datastruct/main.zig").BlockingQueue;
|
||||
|
||||
@ -119,6 +120,13 @@ pub fn threadMain(self: *Thread) void {
|
||||
fn threadMain_(self: *Thread) !void {
|
||||
defer log.debug("cf release thread exited", .{});
|
||||
|
||||
// Right now, on Darwin, `std.Thread.setName` can only name the current
|
||||
// thread, and we have no way to get the current thread from within it,
|
||||
// so instead we use this code to name the thread instead.
|
||||
if (builtin.os.tag.isDarwin()) {
|
||||
internal_os.macos.pthread_setname_np(&"cf_release".*);
|
||||
}
|
||||
|
||||
// Start the async handlers. We start these first so that they're
|
||||
// registered even if anything below fails so we can drain the mailbox.
|
||||
self.wakeup.wait(&self.loop, &self.wakeup_c, Thread, self, wakeupCallback);
|
||||
|
@ -88,6 +88,10 @@ extern "c" fn pthread_set_qos_class_self_np(
|
||||
relative_priority: c_int,
|
||||
) c_int;
|
||||
|
||||
pub extern "c" fn pthread_setname_np(
|
||||
name: [*:0]const u8,
|
||||
) void;
|
||||
|
||||
pub const NSOperatingSystemVersion = extern struct {
|
||||
major: i64,
|
||||
minor: i64,
|
||||
|
@ -198,6 +198,13 @@ pub fn threadMain(self: *Thread) void {
|
||||
fn threadMain_(self: *Thread) !void {
|
||||
defer log.debug("renderer thread exited", .{});
|
||||
|
||||
// Right now, on Darwin, `std.Thread.setName` can only name the current
|
||||
// thread, and we have no way to get the current thread from within it,
|
||||
// so instead we use this code to name the thread instead.
|
||||
if (builtin.os.tag.isDarwin()) {
|
||||
internal_os.macos.pthread_setname_np(&"renderer".*);
|
||||
}
|
||||
|
||||
// Setup our crash metadata
|
||||
crash.sentry.thread_state = .{
|
||||
.type = .renderer,
|
||||
|
@ -1364,6 +1364,13 @@ pub const ReadThread = struct {
|
||||
// Always close our end of the pipe when we exit.
|
||||
defer posix.close(quit);
|
||||
|
||||
// Right now, on Darwin, `std.Thread.setName` can only name the current
|
||||
// thread, and we have no way to get the current thread from within it,
|
||||
// so instead we use this code to name the thread instead.
|
||||
if (builtin.os.tag.isDarwin()) {
|
||||
internal_os.macos.pthread_setname_np(&"io-reader".*);
|
||||
}
|
||||
|
||||
// Setup our crash metadata
|
||||
crash.sentry.thread_state = .{
|
||||
.type = .io,
|
||||
|
@ -16,6 +16,7 @@ const ArenaAllocator = std.heap.ArenaAllocator;
|
||||
const builtin = @import("builtin");
|
||||
const xev = @import("../global.zig").xev;
|
||||
const crash = @import("../crash/main.zig");
|
||||
const internal_os = @import("../os/main.zig");
|
||||
const termio = @import("../termio.zig");
|
||||
const renderer = @import("../renderer.zig");
|
||||
const BlockingQueue = @import("../datastruct/main.zig").BlockingQueue;
|
||||
@ -202,6 +203,13 @@ pub fn threadMain(self: *Thread, io: *termio.Termio) void {
|
||||
fn threadMain_(self: *Thread, io: *termio.Termio) !void {
|
||||
defer log.debug("IO thread exited", .{});
|
||||
|
||||
// Right now, on Darwin, `std.Thread.setName` can only name the current
|
||||
// thread, and we have no way to get the current thread from within it,
|
||||
// so instead we use this code to name the thread instead.
|
||||
if (builtin.os.tag.isDarwin()) {
|
||||
internal_os.macos.pthread_setname_np(&"io".*);
|
||||
}
|
||||
|
||||
// Setup our crash metadata
|
||||
crash.sentry.thread_state = .{
|
||||
.type = .io,
|
||||
|
Reference in New Issue
Block a user