| author | |
| committer | |
| log | bbc77df3eb91b9c9dc6b334cd344670f64c4a457 |
| tree | a2a3f8d6145e487a1d0733885b83fe2986286f99 |
| parent | 4e2cec265d37afd5ad320d0430060308de65326f |
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"); | ... | @@ -13,7 +13,6 @@ pub const ArenaAllocator = @import("heap/ArenaAllocator.zig"); |
| 13 | pub const SmpAllocator = @import("heap/SmpAllocator.zig"); | 13 | pub const SmpAllocator = @import("heap/SmpAllocator.zig"); |
| 14 | pub const FixedBufferAllocator = @import("heap/FixedBufferAllocator.zig"); | 14 | pub const FixedBufferAllocator = @import("heap/FixedBufferAllocator.zig"); |
| 15 | pub const PageAllocator = @import("heap/PageAllocator.zig"); | 15 | pub const PageAllocator = @import("heap/PageAllocator.zig"); |
| 16 | pub const ThreadSafeAllocator = @import("heap/ThreadSafeAllocator.zig"); | ||
| 17 | pub const WasmAllocator = if (builtin.single_threaded) BrkAllocator else @compileError("unimplemented"); | 16 | pub const WasmAllocator = if (builtin.single_threaded) BrkAllocator else @compileError("unimplemented"); |
| 18 | pub const BrkAllocator = @import("heap/BrkAllocator.zig"); | 17 | pub const BrkAllocator = @import("heap/BrkAllocator.zig"); |
| 19 | 18 | ||
| ... | @@ -1009,7 +1008,6 @@ test { | ... | @@ -1009,7 +1008,6 @@ test { |
| 1009 | _ = ArenaAllocator; | 1008 | _ = ArenaAllocator; |
| 1010 | _ = GeneralPurposeAllocator; | 1009 | _ = GeneralPurposeAllocator; |
| 1011 | _ = FixedBufferAllocator; | 1010 | _ = FixedBufferAllocator; |
| 1012 | _ = ThreadSafeAllocator; | ||
| 1013 | if (builtin.single_threaded) { | 1011 | if (builtin.single_threaded) { |
| 1014 | if (builtin.cpu.arch.isWasm() or (builtin.os.tag == .linux and !builtin.link_libc)) { | 1012 | if (builtin.cpu.arch.isWasm() or (builtin.os.tag == .linux and !builtin.link_libc)) { |
| 1015 | _ = brk_allocator; | 1013 | _ = 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. | ||
| 3 | const ThreadSafeAllocator = @This(); | ||
| 4 | |||
| 5 | const std = @import("../std.zig"); | ||
| 6 | const Io = std.Io; | ||
| 7 | const Allocator = std.mem.Allocator; | ||
| 8 | |||
| 9 | child_allocator: Allocator, | ||
| 10 | io: Io, | ||
| 11 | mutex: Io.Mutex = .init, | ||
| 12 | |||
| 13 | pub 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 | |||
| 25 | fn 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 | |||
| 34 | fn 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 | |||
| 44 | fn 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 | |||
| 54 | fn 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 | } | ||