diff options
author | 2022-01-23 21:14:20 -0800 | |
---|---|---|
committer | 2022-01-23 21:14:20 -0800 | |
commit | 962b7fa8d91404bb3a7f516fbda92b3235a4a327 (patch) | |
tree | 8e8b9c6fc12ebee4d6397563de2f990fd87eab27 | |
parent | d6ebb478e35c7f666a2e5da1ec5a9039265a10f0 (diff) | |
download | bun-962b7fa8d91404bb3a7f516fbda92b3235a4a327.tar.gz bun-962b7fa8d91404bb3a7f516fbda92b3235a4a327.tar.zst bun-962b7fa8d91404bb3a7f516fbda92b3235a4a327.zip |
Add a callback when a thread spawns
Diffstat (limited to '')
-rw-r--r-- | src/thread_pool.zig | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/thread_pool.zig b/src/thread_pool.zig index 34bc45fc0..b3d25b015 100644 --- a/src/thread_pool.zig +++ b/src/thread_pool.zig @@ -8,10 +8,11 @@ const AsyncIO = @import("io"); const assert = std.debug.assert; const Atomic = std.atomic.Atomic; - +pub const OnSpawnCallback = fn () void; io: ?*AsyncIO = null, sleep_on_idle_network_thread: bool = true, - +/// executed on the thread +on_thread_spawn: ?OnSpawnCallback = null, stack_size: u32, max_threads: u32, sync: Atomic(u32) = Atomic(u32).init(@bitCast(u32, Sync{})), @@ -383,6 +384,10 @@ const Thread = struct { var self = Thread{}; current = &self; + if (thread_pool.on_thread_spawn) |spawn| { + spawn(); + } + thread_pool.register(&self); defer thread_pool.unregister(&self); |