Skip to content

Commit eeb74d4

Browse files
committed
fix: revert condvar wakeup, keep 1ms polling for mesh scheduler
1 parent 278859a commit eeb74d4

1 file changed

Lines changed: 6 additions & 14 deletions

File tree

src/client/world/MeshSchedulerThread.zig

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,7 @@ pub const MeshSchedulerThread = struct {
5252

5353
// Unbounded inbox (main thread produces via queueMesh, scheduler thread drains)
5454
// Mutex-protected — push is O(1) amortized, never fails (C2ME-style)
55-
// Condvar wakeup eliminates 1ms polling sleep (C2ME uses semaphores)
5655
inbox_mutex: Io.Mutex = Io.Mutex.init,
57-
inbox_cond: Io.Condition = Io.Condition.init,
5856
inbox: std.ArrayListUnmanaged(MeshRequest) = .{},
5957

6058
// Direct pool submission (thread-safe via mutex)
@@ -113,7 +111,6 @@ pub const MeshSchedulerThread = struct {
113111

114112
logger.info("MeshSchedulerThread shutting down...", .{});
115113
self.running.store(false, .release);
116-
self.inbox_cond.signal(self.io); // Wake thread so it sees running=false
117114

118115
if (self.thread) |thread| {
119116
thread.join();
@@ -125,18 +122,14 @@ pub const MeshSchedulerThread = struct {
125122

126123
/// Queue a mesh request from the main thread (unbounded, never fails).
127124
/// C2ME-style: push always succeeds, no retry mechanism needed.
128-
/// Signals condvar to wake scheduler thread immediately (no polling delay).
129125
pub fn queueMesh(self: *Self, req: MeshRequest) void {
130126
self.inbox_mutex.lockUncancelable(self.io);
127+
defer self.inbox_mutex.unlock(self.io);
131128
self.inbox.append(self.allocator, req) catch {
132129
logger.warn("Failed to queue mesh request for ({},{},{}): OOM", .{
133130
req.pos.x, req.pos.z, req.pos.section_y,
134131
});
135-
self.inbox_mutex.unlock(self.io);
136-
return;
137132
};
138-
self.inbox_mutex.unlock(self.io);
139-
self.inbox_cond.signal(self.io);
140133
}
141134

142135
fn threadLoop(self: *Self) void {
@@ -153,13 +146,12 @@ pub const MeshSchedulerThread = struct {
153146
// 2. Process pending_mesh_queue (FIFO, no per-tick cap — not on render thread)
154147
const submitted = self.processPendingQueue();
155148

156-
// Wait for work when idle (C2ME-style: condvar wakeup, no polling)
149+
// Sleep when idle (1ms polling)
157150
if (drained == 0 and submitted == 0) {
158-
self.inbox_mutex.lockUncancelable(self.io);
159-
if (self.inbox.items.len == 0 and self.running.load(.acquire)) {
160-
self.inbox_cond.waitUncancelable(self.io, &self.inbox_mutex);
161-
}
162-
self.inbox_mutex.unlock(self.io);
151+
Io.Clock.Duration.sleep(.{
152+
.clock = .awake,
153+
.raw = .fromNanoseconds(1_000_000), // 1ms
154+
}, self.io) catch {};
163155
}
164156
}
165157

0 commit comments

Comments
 (0)