Home | History | Annotate | Download | only in fio

Lines Matching defs:fifo

2  * A simple kernel FIFO implementation.
26 #include "fifo.h"
28 struct fifo *fifo_alloc(unsigned int size)
30 struct fifo *fifo;
32 fifo = malloc(sizeof(struct fifo));
33 if (!fifo)
36 fifo->buffer = malloc(size);
37 fifo->size = size;
38 fifo->in = fifo->out = 0;
40 return fifo;
43 void fifo_free(struct fifo *fifo)
45 free(fifo->buffer);
46 free(fifo);
49 unsigned int fifo_put(struct fifo *fifo, void *buffer, unsigned int len)
53 len = min(len, fifo_room(fifo));
55 /* first put the data starting from fifo->in to buffer end */
56 l = min(len, fifo->size - (fifo->in & (fifo->size - 1)));
57 memcpy(fifo->buffer + (fifo->in & (fifo->size - 1)), buffer, l);
60 memcpy(fifo->buffer, buffer + l, len - l);
63 * Ensure that we add the bytes to the fifo -before-
64 * we update the fifo->in index.
67 fifo->in += len;
72 unsigned int fifo_get(struct fifo *fifo, void *buf, unsigned int len)
74 len = min(len, fifo->in - fifo->out);
80 * first get the data from fifo->out until the end of the buffer
82 l = min(len, fifo->size - (fifo->out & (fifo->size - 1)));
83 memcpy(buf, fifo->buffer + (fifo->out & (fifo->size - 1)), l);
88 memcpy(buf + l, fifo->buffer, len - l);
91 fifo->out += len;
93 if (fifo->in == fifo->out)
94 fifo->in = fifo->out = 0;