diff options
| -rw-r--r-- | CMakeLists.txt | 4 | ||||
| -rw-r--r-- | lib/std/Thread.zig | 2 | ||||
| -rw-r--r-- | lib/std/Thread/Pool.zig (renamed from src/ThreadPool.zig) | 16 | ||||
| -rw-r--r-- | lib/std/Thread/WaitGroup.zig (renamed from src/WaitGroup.zig) | 0 | ||||
| -rw-r--r-- | src/Compilation.zig | 4 | ||||
| -rw-r--r-- | src/Package.zig | 4 | ||||
| -rw-r--r-- | src/link/MachO/CodeSignature.zig | 4 | ||||
| -rw-r--r-- | src/main.zig | 2 | ||||
| -rw-r--r-- | src/test.zig | 4 |
9 files changed, 21 insertions, 19 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 5afea9354e..c77c66add4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -506,7 +506,9 @@ set(ZIG_STAGE2_SOURCES "${CMAKE_SOURCE_DIR}/lib/std/Thread.zig" "${CMAKE_SOURCE_DIR}/lib/std/Thread/Futex.zig" "${CMAKE_SOURCE_DIR}/lib/std/Thread/Mutex.zig" + "${CMAKE_SOURCE_DIR}/lib/std/Thread/Pool.zig" "${CMAKE_SOURCE_DIR}/lib/std/Thread/ResetEvent.zig" + "${CMAKE_SOURCE_DIR}/lib/std/Thread/WaitGroup.zig" "${CMAKE_SOURCE_DIR}/lib/std/time.zig" "${CMAKE_SOURCE_DIR}/lib/std/treap.zig" "${CMAKE_SOURCE_DIR}/lib/std/unicode.zig" @@ -530,9 +532,7 @@ set(ZIG_STAGE2_SOURCES "${CMAKE_SOURCE_DIR}/src/Package.zig" "${CMAKE_SOURCE_DIR}/src/RangeSet.zig" "${CMAKE_SOURCE_DIR}/src/Sema.zig" - "${CMAKE_SOURCE_DIR}/src/ThreadPool.zig" "${CMAKE_SOURCE_DIR}/src/TypedValue.zig" - "${CMAKE_SOURCE_DIR}/src/WaitGroup.zig" "${CMAKE_SOURCE_DIR}/src/Zir.zig" "${CMAKE_SOURCE_DIR}/src/arch/aarch64/CodeGen.zig" "${CMAKE_SOURCE_DIR}/src/arch/aarch64/Emit.zig" diff --git a/lib/std/Thread.zig b/lib/std/Thread.zig index 27f7fa5030..e3345e4a42 100644 --- a/lib/std/Thread.zig +++ b/lib/std/Thread.zig @@ -16,6 +16,8 @@ pub const Mutex = @import("Thread/Mutex.zig"); pub const Semaphore = @import("Thread/Semaphore.zig"); pub const Condition = @import("Thread/Condition.zig"); pub const RwLock = @import("Thread/RwLock.zig"); +pub const Pool = @import("Thread/Pool.zig"); +pub const WaitGroup = @import("Thread/WaitGroup.zig"); pub const use_pthreads = target.os.tag != .windows and target.os.tag != .wasi and builtin.link_libc; const is_gnu = target.abi.isGnu(); diff --git a/src/ThreadPool.zig b/lib/std/Thread/Pool.zig index fde5ed27db..930befbac5 100644 --- a/src/ThreadPool.zig +++ b/lib/std/Thread/Pool.zig @@ -1,6 +1,6 @@ const std = @import("std"); const builtin = @import("builtin"); -const ThreadPool = @This(); +const Pool = @This(); const WaitGroup = @import("WaitGroup.zig"); mutex: std.Thread.Mutex = .{}, @@ -17,7 +17,7 @@ const Runnable = struct { const RunProto = *const fn (*Runnable) void; -pub fn init(pool: *ThreadPool, allocator: std.mem.Allocator) !void { +pub fn init(pool: *Pool, allocator: std.mem.Allocator) !void { pool.* = .{ .allocator = allocator, .threads = &[_]std.Thread{}, @@ -41,12 +41,12 @@ pub fn init(pool: *ThreadPool, allocator: std.mem.Allocator) !void { } } -pub fn deinit(pool: *ThreadPool) void { +pub fn deinit(pool: *Pool) void { pool.join(pool.threads.len); // kill and join all threads. pool.* = undefined; } -fn join(pool: *ThreadPool, spawned: usize) void { +fn join(pool: *Pool, spawned: usize) void { if (builtin.single_threaded) { return; } @@ -69,7 +69,7 @@ fn join(pool: *ThreadPool, spawned: usize) void { pool.allocator.free(pool.threads); } -pub fn spawn(pool: *ThreadPool, comptime func: anytype, args: anytype) !void { +pub fn spawn(pool: *Pool, comptime func: anytype, args: anytype) !void { if (builtin.single_threaded) { @call(.auto, func, args); return; @@ -78,7 +78,7 @@ pub fn spawn(pool: *ThreadPool, comptime func: anytype, args: anytype) !void { const Args = @TypeOf(args); const Closure = struct { arguments: Args, - pool: *ThreadPool, + pool: *Pool, run_node: RunQueue.Node = .{ .data = .{ .runFn = runFn } }, fn runFn(runnable: *Runnable) void { @@ -112,7 +112,7 @@ pub fn spawn(pool: *ThreadPool, comptime func: anytype, args: anytype) !void { pool.cond.signal(); } -fn worker(pool: *ThreadPool) void { +fn worker(pool: *Pool) void { pool.mutex.lock(); defer pool.mutex.unlock(); @@ -135,7 +135,7 @@ fn worker(pool: *ThreadPool) void { } } -pub fn waitAndWork(pool: *ThreadPool, wait_group: *WaitGroup) void { +pub fn waitAndWork(pool: *Pool, wait_group: *WaitGroup) void { while (!wait_group.isDone()) { if (blk: { pool.mutex.lock(); diff --git a/src/WaitGroup.zig b/lib/std/Thread/WaitGroup.zig index c8be6658db..c8be6658db 100644 --- a/src/WaitGroup.zig +++ b/lib/std/Thread/WaitGroup.zig diff --git a/src/Compilation.zig b/src/Compilation.zig index de433a6800..63dd229ec5 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -7,6 +7,8 @@ const Allocator = std.mem.Allocator; const assert = std.debug.assert; const log = std.log.scoped(.compilation); const Target = std.Target; +const ThreadPool = std.Thread.Pool; +const WaitGroup = std.Thread.WaitGroup; const Value = @import("value.zig").Value; const Type = @import("type.zig").Type; @@ -30,8 +32,6 @@ const Cache = std.Build.Cache; const translate_c = @import("translate_c.zig"); const clang = @import("clang.zig"); const c_codegen = @import("codegen/c.zig"); -const ThreadPool = @import("ThreadPool.zig"); -const WaitGroup = @import("WaitGroup.zig"); const libtsan = @import("libtsan.zig"); const Zir = @import("Zir.zig"); const Autodoc = @import("Autodoc.zig"); diff --git a/src/Package.zig b/src/Package.zig index c238d3d567..87d52197bd 100644 --- a/src/Package.zig +++ b/src/Package.zig @@ -8,11 +8,11 @@ const Allocator = mem.Allocator; const assert = std.debug.assert; const log = std.log.scoped(.package); const main = @import("main.zig"); +const ThreadPool = std.Thread.Pool; +const WaitGroup = std.Thread.WaitGroup; const Compilation = @import("Compilation.zig"); const Module = @import("Module.zig"); -const ThreadPool = @import("ThreadPool.zig"); -const WaitGroup = @import("WaitGroup.zig"); const Cache = std.Build.Cache; const build_options = @import("build_options"); const Manifest = @import("Manifest.zig"); diff --git a/src/link/MachO/CodeSignature.zig b/src/link/MachO/CodeSignature.zig index 8bc00d9181..6d1cd7b536 100644 --- a/src/link/MachO/CodeSignature.zig +++ b/src/link/MachO/CodeSignature.zig @@ -7,12 +7,12 @@ const log = std.log.scoped(.link); const macho = std.macho; const mem = std.mem; const testing = std.testing; +const ThreadPool = std.Thread.Pool; +const WaitGroup = std.Thread.WaitGroup; const Allocator = mem.Allocator; const Compilation = @import("../../Compilation.zig"); const Sha256 = std.crypto.hash.sha2.Sha256; -const ThreadPool = @import("../../ThreadPool.zig"); -const WaitGroup = @import("../../WaitGroup.zig"); const hash_size = Sha256.digest_length; diff --git a/src/main.zig b/src/main.zig index 95cfca1463..dd0faa628c 100644 --- a/src/main.zig +++ b/src/main.zig @@ -9,6 +9,7 @@ const Allocator = mem.Allocator; const ArrayList = std.ArrayList; const Ast = std.zig.Ast; const warn = std.log.warn; +const ThreadPool = std.Thread.Pool; const tracy = @import("tracy.zig"); const Compilation = @import("Compilation.zig"); @@ -22,7 +23,6 @@ const translate_c = @import("translate_c.zig"); const clang = @import("clang.zig"); const Cache = std.Build.Cache; const target_util = @import("target.zig"); -const ThreadPool = @import("ThreadPool.zig"); const crash_report = @import("crash_report.zig"); pub const std_options = struct { diff --git a/src/test.zig b/src/test.zig index 61cdb705e3..ce87742606 100644 --- a/src/test.zig +++ b/src/test.zig @@ -4,14 +4,14 @@ const Allocator = std.mem.Allocator; const CrossTarget = std.zig.CrossTarget; const print = std.debug.print; const assert = std.debug.assert; +const ThreadPool = std.Thread.Pool; +const WaitGroup = std.Thread.WaitGroup; const link = @import("link.zig"); const Compilation = @import("Compilation.zig"); const Package = @import("Package.zig"); const introspect = @import("introspect.zig"); const build_options = @import("build_options"); -const ThreadPool = @import("ThreadPool.zig"); -const WaitGroup = @import("WaitGroup.zig"); const zig_h = link.File.C.zig_h; const enable_qemu: bool = build_options.enable_qemu; |
