aboutsummaryrefslogtreecommitdiff
path: root/src/hive_array.zig
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2022-11-12 18:30:12 -0800
committerGravatar GitHub <noreply@github.com> 2022-11-12 18:30:12 -0800
commit21bf3ddaf23c842dc12a1d76dbd3b48daf08f349 (patch)
tree06706104877984e9f083fed7c3278c9d007193cc /src/hive_array.zig
parent514f2a8eddf1a1d35a33cc096ed7403a79afe36f (diff)
downloadbun-21bf3ddaf23c842dc12a1d76dbd3b48daf08f349.tar.gz
bun-21bf3ddaf23c842dc12a1d76dbd3b48daf08f349.tar.zst
bun-21bf3ddaf23c842dc12a1d76dbd3b48daf08f349.zip
Redo how we poll pipes (#1496)
* Fix pipe * Handle unregistered * Fix failing test
Diffstat (limited to 'src/hive_array.zig')
-rw-r--r--src/hive_array.zig28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/hive_array.zig b/src/hive_array.zig
index eb9220e19..39f10d324 100644
--- a/src/hive_array.zig
+++ b/src/hive_array.zig
@@ -64,6 +64,34 @@ pub fn HiveArray(comptime T: type, comptime capacity: u16) type {
self.available.set(index);
return true;
}
+
+ pub const Fallback = struct {
+ hive: HiveArray(T, capacity),
+ allocator: std.mem.Allocator,
+
+ pub const This = @This();
+
+ pub fn init(allocator: std.mem.Allocator) This {
+ return .{
+ .allocator = allocator,
+ .hive = HiveArray(T, capacity).init(),
+ };
+ }
+
+ pub fn get(self: *This) *T {
+ if (self.hive.get()) |value| {
+ return value;
+ }
+
+ return self.allocator.create(T) catch unreachable;
+ }
+
+ pub fn put(self: *This, value: *T) void {
+ if (self.hive.put(value)) return;
+
+ self.allocator.destroy(value);
+ }
+ };
};
}