19 #include "shared/shared.h"
20 #include "common/fifo.h"
21 #include "common/msg.h"
23 size_t FIFO_Read(fifo_t *fifo,
void *buffer,
size_t len)
25 size_t wrapped,
head = fifo->ay - fifo->ax;
29 memcpy(buffer, fifo->data + fifo->ax, len);
36 if (wrapped > fifo->bs) {
40 memcpy(buffer, fifo->data + fifo->ax,
head);
41 memcpy((
byte *)buffer +
head, fifo->data, wrapped);
47 return head + wrapped;
50 size_t FIFO_Write(fifo_t *fifo,
const void *buffer,
size_t len)
52 size_t tail, wrapped, remaining;
55 remaining = fifo->ax - fifo->bs;
56 if (len > remaining) {
60 memcpy(fifo->data + fifo->bs, buffer, len);
66 tail = fifo->size - fifo->ay;
69 memcpy(fifo->data + fifo->ay, buffer, len);
76 if (wrapped > fifo->ax) {
80 memcpy(fifo->data + fifo->ay, buffer, tail);
81 memcpy(fifo->data, (
byte *)buffer + tail, wrapped);
82 fifo->ay = fifo->size;
86 return tail + wrapped;
94 data = FIFO_Peek(fifo, &len);
104 FIFO_Decommit(fifo, msglen);