Created
December 16, 2020 03:23
-
-
Save marler8997/27b8f24475326a65007d9943c88122f6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn runWorker(self: *ThreadPool) void { | |
const old_pool = tls_current_pool; | |
tls_current_pool = self; | |
defer tls_current_pool = old_pool; | |
while (true) { | |
const held = self.mutex.acquire(); | |
if (self.is_shutdown) { | |
held.release(); | |
break; | |
} | |
if (self.run_queue.pop()) |runnable| { | |
held.release(); | |
(runnable.callback)(runnable); | |
continue; | |
} | |
var idle_node = IdleQueue.Node{ .data = .{} }; | |
self.idle_queue.prepend(&idle_node); | |
held.release(); | |
idle_node.data.wait(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment