Compare commits
3 Commits
d5e66caf21
...
72349459ec
| Author | SHA1 | Date | |
|---|---|---|---|
| 72349459ec | |||
| c1388c7318 | |||
| d794a57b4e |
11
build.zig
11
build.zig
@@ -27,18 +27,21 @@ pub fn build(b: *std.Build) void {
|
||||
// This declares intent for the library to be installed into the standard
|
||||
// location when the user invokes the "install" step (the default step when
|
||||
// running `zig build`).
|
||||
lib.install();
|
||||
b.installArtifact(lib);
|
||||
|
||||
// Creates a step for unit testing.
|
||||
// Creates a step for unit testing. This only builds the test executable
|
||||
// but does not run it.
|
||||
const main_tests = b.addTest(.{
|
||||
.root_source_file = .{ .path = "src/main.zig" },
|
||||
.root_source_file = .{ .path = "src/lib.zig" },
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
});
|
||||
|
||||
const run_main_tests = b.addRunArtifact(main_tests);
|
||||
|
||||
// This creates a build step. It will be visible in the `zig build --help` menu,
|
||||
// and can be selected like this: `zig build test`
|
||||
// This will evaluate the `test` step rather than the default, which is "install".
|
||||
const test_step = b.step("test", "Run library tests");
|
||||
test_step.dependOn(&main_tests.step);
|
||||
test_step.dependOn(&run_main_tests.step);
|
||||
}
|
||||
|
||||
12
src/lib.zig
12
src/lib.zig
@@ -78,6 +78,16 @@ fn Channel(comptime T: type) type {
|
||||
return value;
|
||||
}
|
||||
|
||||
pub fn peek(self: *const Self) ?T {
|
||||
const read_idx = self.read.load(.Acquire);
|
||||
const write_idx = self.write.load(.Acquire);
|
||||
|
||||
if (read_idx == write_idx) return null;
|
||||
|
||||
std.atomic.fence(.Acquire);
|
||||
return self.buf[self.mask(read_idx)];
|
||||
}
|
||||
|
||||
pub fn len(self: *const Self) Index {
|
||||
const read_idx = self.read.load(.Acquire);
|
||||
const write_idx = self.write.load(.Acquire);
|
||||
@@ -109,7 +119,7 @@ pub fn RingBuffer(comptime T: type) type {
|
||||
std.debug.assert(std.math.isPowerOfTwo(buf.len)); // capacity must be a power of two
|
||||
std.debug.assert(buf.len <= max_capacity);
|
||||
|
||||
std.mem.set(T, buf, 0);
|
||||
@memset(buf, 0);
|
||||
|
||||
return .{ .read = 0, .write = 0, .buf = buf };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user