| ... | @@ -273,6 +273,20 @@ pub fn LinearFifo( | ... | @@ -273,6 +273,20 @@ pub fn LinearFifo( |
| 273 | } | 273 | } |
| 274 | } | 274 | } |
| 275 | | 275 | |
| | 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 | |
| 276 | /// Appends the data in `src` to the fifo. | 290 | /// Appends the data in `src` to the fifo. |
| 277 | /// Allocates more memory as necessary | 291 | /// Allocates more memory as necessary |
| 278 | pub fn write(self: *Self, src: []const T) !void { | 292 | pub fn write(self: *Self, src: []const T) !void { |