const std = @import("std"); const os = std.os; const mem = std.mem; const meta = std.meta; const atomic = std.atomic; const builtin = std.builtin; const testing = std.testing; const assert = std.debug.assert; const mpsc = @This(); pub const cache_line_length = switch (@import("builtin").target.cpu.arch) { .x86_64, .aarch64, .powerpc64 => 128, .arm, .mips, .mips64, .riscv64 => 32, .s390x => 256, else => 64, }; pub fn UnboundedQueue(comptime T: type, comptime next_field: meta.FieldEnum(T)) type { const next_name = meta.fieldInfo(T, next_field).name; return struct { const Self = @This(); pub const Batch = struct { pub const Iterator = struct { batch: Self.Batch, pub fn next(self: *Self.Batch.Iterator) ?*T { if (self.batch.count == 0) return null; const front = self.batch.front orelse unreachable; self.batch.front = @field(front, next_name); self.batch.count -= 1; return front; } }; front: ?*T = null, last: ?*T = null, count: usize = 0, pub fn iterator(self: Self.Batch) Self.Batch.Iterator { return .{ .batch = self }; } }; const next = next_name; pub const queue_padding_length = cache_line_length / 2; back: ?*T align(queue_padding_length) = null, count: usize = 0, front: T align(queue_padding_length) = init: { var stub: T = undefined; @field(stub, next) = null; break :init stub; }, pub fn push(self: *Self, src: *T) void { assert(@atomicRmw(usize, &self.count, .Add, 1, .Release) >= 0); @field(src, next) = null; const old_back = @atomicRmw(?*T, &self.back, .Xchg, src, .AcqRel) orelse &self.front; @field(old_back, next) = src; } pub fn pushBatch(self: *Self, first: *T, last: *T, count: usize) void { assert(@atomicRmw(usize, &self.count, .Add, count, .Release) >= 0); @field(last, next) = null; const old_back = @atomicRmw(?*T, &self.back, .Xchg, last, .AcqRel) orelse &self.front; @field(old_back, next) = first; } pub fn pop(self: *Self) ?*T { const first = @atomicLoad(?*T, &@field(self.front, next), .Acquire) orelse return null; if (@atomicLoad(?*T, &@field(first, next), .Acquire)) |next_item| { @atomicStore(?*T, &@field(self.front, next), next_item, .Monotonic); assert(@atomicRmw(usize, &self.count, .Sub, 1, .Monotonic) >= 1); return first; } const last = @atomicLoad(?*T, &self.back, .Acquire) orelse &self.front; if (first != last) return null; @atomicStore(?*T, &@field(self.front, next), null, .Monotonic); if (@cmpxchgStrong(?*T, &self.back, last, &self.front, .AcqRel, .Acquire) == null) { assert(@atomicRmw(usize, &self.count, .Sub, 1, .Monotonic) >= 1); return first; } var next_item = @atomicLoad(?*T, &@field(first, next), .Acquire); while (next_item == null) : (atomic.spinLoopHint()) { next_item = @atomicLoad(?*T, &@field(first, next), .Acquire); } @atomicStore(?*T, &@field(self.front, next), next_item, .Monotonic); assert(@atomicRmw(usize, &self.count, .Sub, 1, .Monotonic) >= 1); return first; } pub fn popBatch(self: *Self) Self.Batch { var batch: Self.Batch = .{}; var front = @atomicLoad(?*T, &@field(self.front, next), .Acquire) orelse return batch; batch.front = front; var next_item = @atomicLoad(?*T, &@field(front, next), .Acquire); while (next_item) |next_node| : (next_item = @atomicLoad(?*T, &@field(next_node, next), .Acquire)) { batch.count += 1; batch.last = front; front = next_node; } const last = @atomicLoad(?*T, &self.back, .Acquire) orelse &self.front; if (front != last) { @atomicStore(?*T, &@field(self.front, next), front, .Release); assert(@atomicRmw(usize, &self.count, .Sub, batch.count, .Monotonic) >= batch.count); return batch; } @atomicStore(?*T, &@field(self.front, next), null, .Monotonic); if (@cmpxchgStrong(?*T, &self.back, last, &self.front, .AcqRel, .Acquire) == null) { batch.count += 1; batch.last = front; assert(@atomicRmw(usize, &self.count, .Sub, batch.count, .Monotonic) >= batch.count); return batch; } next_item = @atomicLoad(?*T, &@field(front, next), .Acquire); while (next_item == null) : (atomic.spinLoopHint()) { next_item = @atomicLoad(?*T, &@field(front, next), .Acquire); } batch.count += 1; @atomicStore(?*T, &@field(self.front, next), next_item, .Monotonic); batch.last = front; assert(@atomicRmw(usize, &self.count, .Sub, batch.count, .Monotonic) >= batch.count); return batch; } pub fn peek(self: *Self) usize { const count = @atomicLoad(usize, &self.count, .Acquire); assert(count >= 0); return count; } pub fn isEmpty(self: *Self) bool { return self.peek() == 0; } }; } tion> Unnamed repository; edit this file 'description' to name the repository.
aboutsummaryrefslogtreecommitdiff
path: root/packages/astro/test/fixtures/astro-external-files (unfollow)
AgeCommit message (Expand)AuthorFilesLines
2024-02-27Improve the message of `MiddlewareCantBeLoaded` for clarity (#10239)Gravatar Ming-jun Lu 2-1/+6
2024-02-26[ci] formatGravatar Martin Trapp 1-1/+3
2024-02-26Warn when view transitions run on a prefer-reduced-motion device (#10222)Gravatar Martin Trapp 2-0/+8
2024-02-26[ci] release (#10218)astro@4.4.5@astrojs/vercel@7.3.4@astrojs/svelte@5.1.0@astrojs/db@0.4.1Gravatar Houston (Bot) 46-114/+100
2024-02-26fix: better assetsInlineLimit runtime type checking (#10154)Gravatar James Ross 2-9/+13
2024-02-26fix: correct remote url (#10223)Gravatar Ben Holmes 2-2/+8
2024-02-26fix(toolbar): Make it so every built-in app can be closed by outside clicks (...Gravatar Erika 8-51/+63
2024-02-26Fix an issue where Vercel adapter may create functions for prerendered routes...Gravatar Ming-jun Lu 4-2/+26
2024-02-26[ci] formatGravatar Matthew Phillips 1-1/+1
2024-02-26Fix hydration scripts missing from dynamic slot usage (#10219)Gravatar Matthew Phillips 6-1/+69
2024-02-26[ci] formatGravatar Matthew Phillips 1-5/+5
2024-02-26Prevent errors in rendering from crashing server (#10221)Gravatar Matthew Phillips 7-14/+78
2024-02-26fix: svelte 5 mount/hydrate api change. (#10224)Gravatar 前端子鱼 3-5/+12
2024-02-24[ci] formatGravatar Arsh 1-9/+30
2024-02-24prevent warning: `Astro.request.headers` is not available in "static" output ...Gravatar Arsh 2-27/+30
2024-02-23Improved error logging from config (#10207)Gravatar Ben Holmes 4-36/+67
2024-02-23[ci] formatGravatar Arsh 3-3/+3
2024-02-23fix(dev): remove params for prerendered pages (#10199)Gravatar Arsh 9-13/+78
2024-02-23[ci] release (#10213)astro@4.4.4@astrojs/vercel@7.3.3@astrojs/node@8.2.1@astrojs/db@0.4.0Gravatar Houston (Bot) 41-177/+95
2024-02-23Fixes edge middleware calling nested routes (#10215)Gravatar Matthew Phillips 2-1/+6
2024-02-23Adds an error message for non-string transition:name values (#10205)Gravatar Martin Trapp 2-0/+8
2024-02-23[ci] formatGravatar Furkan Erdem 1-1/+1
2024-02-23Fix(node): Custom headers are not present in responses from standalone Node s...Gravatar Furkan Erdem 8-0/+163