authorgravatar for justus@klausecker.deJustus Klausecker <justus@klausecker.de> 2026-02-26 21:12:22+01:00
committergravatar for justus@klausecker.deJustus Klausecker <justus@klausecker.de> 2026-02-26 21:20:34+01:00
logbbc77df3eb91b9c9dc6b334cd344670f64c4a457
treea2a3f8d6145e487a1d0733885b83fe2986286f99
parent4e2cec265d37afd5ad320d0430060308de65326f

std.heap: delete `ThreadSafeAllocator`

We can keep ourselves safe from those threads perfectly well without you, thanks!

2 files changed, 0 insertions(+), 64 deletions(-)

lib/std/heap.zig-2
......@@ -13,7 +13,6 @@ pub const ArenaAllocator = @import("heap/ArenaAllocator.zig");
1313pub const SmpAllocator = @import("heap/SmpAllocator.zig");
1414pub const FixedBufferAllocator = @import("heap/FixedBufferAllocator.zig");
1515pub const PageAllocator = @import("heap/PageAllocator.zig");
16pub const ThreadSafeAllocator = @import("heap/ThreadSafeAllocator.zig");
1716pub const WasmAllocator = if (builtin.single_threaded) BrkAllocator else @compileError("unimplemented");
1817pub const BrkAllocator = @import("heap/BrkAllocator.zig");
1918
......@@ -1009,7 +1008,6 @@ test {
10091008 _ = ArenaAllocator;
10101009 _ = GeneralPurposeAllocator;
10111010 _ = FixedBufferAllocator;
1012 _ = ThreadSafeAllocator;
10131011 if (builtin.single_threaded) {
10141012 if (builtin.cpu.arch.isWasm() or (builtin.os.tag == .linux and !builtin.link_libc)) {
10151013 _ = brk_allocator;
lib/std/heap/ThreadSafeAllocator.zig deleted-62
......@@ -1,62 +0,0 @@
1//! Deprecated. Thread safety should be built into each Allocator instance
2//! directly rather than trying to do this "composable allocators" thing.
3const ThreadSafeAllocator = @This();
4
5const std = @import("../std.zig");
6const Io = std.Io;
7const Allocator = std.mem.Allocator;
8
9child_allocator: Allocator,
10io: Io,
11mutex: Io.Mutex = .init,
12
13pub fn allocator(self: *ThreadSafeAllocator) Allocator {
14 return .{
15 .ptr = self,
16 .vtable = &.{
17 .alloc = alloc,
18 .resize = resize,
19 .remap = remap,
20 .free = free,
21 },
22 };
23}
24
25fn alloc(ctx: *anyopaque, n: usize, alignment: std.mem.Alignment, ra: usize) ?[*]u8 {
26 const self: *ThreadSafeAllocator = @ptrCast(@alignCast(ctx));
27 const io = self.io;
28 self.mutex.lockUncancelable(io);
29 defer self.mutex.unlock(io);
30
31 return self.child_allocator.rawAlloc(n, alignment, ra);
32}
33
34fn resize(ctx: *anyopaque, buf: []u8, alignment: std.mem.Alignment, new_len: usize, ret_addr: usize) bool {
35 const self: *ThreadSafeAllocator = @ptrCast(@alignCast(ctx));
36 const io = self.io;
37
38 self.mutex.lockUncancelable(io);
39 defer self.mutex.unlock(io);
40
41 return self.child_allocator.rawResize(buf, alignment, new_len, ret_addr);
42}
43
44fn remap(context: *anyopaque, memory: []u8, alignment: std.mem.Alignment, new_len: usize, return_address: usize) ?[*]u8 {
45 const self: *ThreadSafeAllocator = @ptrCast(@alignCast(context));
46 const io = self.io;
47
48 self.mutex.lockUncancelable(io);
49 defer self.mutex.unlock(io);
50
51 return self.child_allocator.rawRemap(memory, alignment, new_len, return_address);
52}
53
54fn free(ctx: *anyopaque, buf: []u8, alignment: std.mem.Alignment, ret_addr: usize) void {
55 const self: *ThreadSafeAllocator = @ptrCast(@alignCast(ctx));
56 const io = self.io;
57
58 self.mutex.lockUncancelable(io);
59 defer self.mutex.unlock(io);
60
61 return self.child_allocator.rawFree(buf, alignment, ret_addr);
62}