mirror of
https://github.com/ziglang/zig.git
synced 2026-02-20 08:14:48 +00:00
std: add fifo.writeItem
This commit is contained in:
parent
c393969a20
commit
3062e0e932
@ -273,6 +273,20 @@ pub fn LinearFifo(
|
||||
}
|
||||
}
|
||||
|
||||
/// Write a single item to the fifo
|
||||
pub fn writeItem(self: *Self, item: T) !void {
|
||||
try self.ensureUnusedCapacity(1);
|
||||
|
||||
var tail = self.head + self.count;
|
||||
if (powers_of_two) {
|
||||
tail &= self.buf.len - 1;
|
||||
} else {
|
||||
tail %= self.buf.len;
|
||||
}
|
||||
self.buf[tail] = byte;
|
||||
self.update(1);
|
||||
}
|
||||
|
||||
/// Appends the data in `src` to the fifo.
|
||||
/// Allocates more memory as necessary
|
||||
pub fn write(self: *Self, src: []const T) !void {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user