authorgravatar for quae@daurnimator.comdaurnimator <quae@daurnimator.com> 2019-11-16 22:15:06+11:00
committergravatar for quae@daurnimator.comdaurnimator <quae@daurnimator.com> 2019-11-25 09:26:33+11:00
log3062e0e9320a3ce9447e4611919cbe93296a1ce1
tree2244505e21a7264105e82d66a3c2f8cd96270b2e
parentc393969a2013fc64f1e1c65157164dfdfbafb08a
signaturelock-open Commit is signed but in an unrecognized format.

std: add fifo.writeItem


1 files changed, 14 insertions(+), 0 deletions(-)

lib/std/fifo.zig+14
......@@ -273,6 +273,20 @@ pub fn LinearFifo(
273273 }
274274 }
275275
276 /// Write a single item to the fifo
277 pub fn writeItem(self: *Self, item: T) !void {
278 try self.ensureUnusedCapacity(1);
279
280 var tail = self.head + self.count;
281 if (powers_of_two) {
282 tail &= self.buf.len - 1;
283 } else {
284 tail %= self.buf.len;
285 }
286 self.buf[tail] = byte;
287 self.update(1);
288 }
289
276290 /// Appends the data in `src` to the fifo.
277291 /// Allocates more memory as necessary
278292 pub fn write(self: *Self, src: []const T) !void {