Skip to content

Commit

Permalink
fix: pthread differs on linux vs macos (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
robbielyman authored Sep 23, 2023
1 parent 8da369c commit ef0787e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 16 deletions.
6 changes: 1 addition & 5 deletions src/clock.zig
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,7 @@ const Fabric = struct {
allocator.destroy(self);
}
fn loop(self: *Fabric) void {
const priority: pthread.sched_param = .{
.sched_priority = 90,
.__opaque = undefined,
};
_ = pthread.pthread_setschedparam(pthread.pthread_self(), pthread.SCHED_FIFO, &priority);
pthread.set_priority(90);
while (!self.quit) {
self.do_tick();
self.time += self.tick;
Expand Down
6 changes: 1 addition & 5 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,7 @@ pub fn main() !void {
defer if (option) |_| create.deinit();
while (go_again) {
try print_version();
const priority: pthread.sched_param = .{
.sched_priority = 99,
.__opaque = undefined,
};
_ = pthread.pthread_setschedparam(pthread.pthread_self(), pthread.SCHED_FIFO, &priority);
pthread.set_priority(99);

const path = try std.fs.path.join(allocator, &.{ location, "..", "share", "seamstress", "lua" });
defer allocator.free(path);
Expand Down
6 changes: 1 addition & 5 deletions src/metros.zig
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,7 @@ fn loop(self: *Metro, pid: *Thread) void {
self.status_lock.lock();
self.status = Status.Running;
self.status_lock.unlock();
const priority: pthread.sched_param = .{
.sched_priority = 90,
.__opaque = undefined,
};
_ = pthread.pthread_setschedparam(pthread.pthread_self(), pthread.SCHED_FIFO, &priority);
pthread.set_priority(90);
while (!pid.quit) {
self.wait();
self.stage_lock.lock();
Expand Down
17 changes: 16 additions & 1 deletion src/pthread.zig
Original file line number Diff line number Diff line change
@@ -1 +1,16 @@
pub usingnamespace @cImport(@cInclude("pthread.h"));
const c = @cImport(@cInclude("pthread.h"));
const builtin = @import("builtin");

pub fn set_priority(priority: u8) void {
const priority_struct: c.sched_param = switch (comptime builtin.os.tag) {
.linux => .{
.sched_priority = priority,
},
.macos => .{
.sched_priority = priority,
.__opaque = undefined,
},
else => return,
};
_ = c.pthread_setschedparam(c.pthread_self(), c.SCHED_FIFO, &priority_struct);
}

0 comments on commit ef0787e

Please sign in to comment.