| ... | ... | @@ -9,35 +9,45 @@ pub fn allocator(self: *ThreadSafeAllocator) Allocator { |
| 9 | 9 | .vtable = &.{ |
| 10 | 10 | .alloc = alloc, |
| 11 | 11 | .resize = resize, |
| 12 | .remap = remap, |
| 12 | 13 | .free = free, |
| 13 | 14 | }, |
| 14 | 15 | }; |
| 15 | 16 | } |
| 16 | 17 | |
| 17 | | fn alloc(ctx: *anyopaque, n: usize, log2_ptr_align: u8, ra: usize) ?[*]u8 { |
| 18 | fn alloc(ctx: *anyopaque, n: usize, alignment: std.mem.Alignment, ra: usize) ?[*]u8 { |
| 18 | 19 | const self: *ThreadSafeAllocator = @ptrCast(@alignCast(ctx)); |
| 19 | 20 | self.mutex.lock(); |
| 20 | 21 | defer self.mutex.unlock(); |
| 21 | 22 | |
| 22 | | return self.child_allocator.rawAlloc(n, log2_ptr_align, ra); |
| 23 | return self.child_allocator.rawAlloc(n, alignment, ra); |
| 23 | 24 | } |
| 24 | 25 | |
| 25 | | fn resize(ctx: *anyopaque, buf: []u8, log2_buf_align: u8, new_len: usize, ret_addr: usize) bool { |
| 26 | fn resize(ctx: *anyopaque, buf: []u8, alignment: std.mem.Alignment, new_len: usize, ret_addr: usize) bool { |
| 26 | 27 | const self: *ThreadSafeAllocator = @ptrCast(@alignCast(ctx)); |
| 27 | 28 | |
| 28 | 29 | self.mutex.lock(); |
| 29 | 30 | defer self.mutex.unlock(); |
| 30 | 31 | |
| 31 | | return self.child_allocator.rawResize(buf, log2_buf_align, new_len, ret_addr); |
| 32 | return self.child_allocator.rawResize(buf, alignment, new_len, ret_addr); |
| 32 | 33 | } |
| 33 | 34 | |
| 34 | | fn free(ctx: *anyopaque, buf: []u8, log2_buf_align: u8, ret_addr: usize) void { |
| 35 | fn remap(context: *anyopaque, memory: []u8, alignment: std.mem.Alignment, new_len: usize, return_address: usize) ?[*]u8 { |
| 36 | const self: *ThreadSafeAllocator = @ptrCast(@alignCast(context)); |
| 37 | |
| 38 | self.mutex.lock(); |
| 39 | defer self.mutex.unlock(); |
| 40 | |
| 41 | return self.child_allocator.rawRemap(memory, alignment, new_len, return_address); |
| 42 | } |
| 43 | |
| 44 | fn free(ctx: *anyopaque, buf: []u8, alignment: std.mem.Alignment, ret_addr: usize) void { |
| 35 | 45 | const self: *ThreadSafeAllocator = @ptrCast(@alignCast(ctx)); |
| 36 | 46 | |
| 37 | 47 | self.mutex.lock(); |
| 38 | 48 | defer self.mutex.unlock(); |
| 39 | 49 | |
| 40 | | return self.child_allocator.rawFree(buf, log2_buf_align, ret_addr); |
| 50 | return self.child_allocator.rawFree(buf, alignment, ret_addr); |
| 41 | 51 | } |
| 42 | 52 | |
| 43 | 53 | const std = @import("../std.zig"); |