diff options
author | Sascha Hauer <sha@octopus.labnet.pengutronix.de> | 2007-09-21 21:29:32 +0200 |
---|---|---|
committer | Sascha Hauer <sha@octopus.labnet.pengutronix.de> | 2007-09-21 21:29:32 +0200 |
commit | 90a17da95cc5dc558cee9446e75b2daa84212be3 (patch) | |
tree | ca70b9f1f9ed1358eea7283fcd9661d49df9164d /include/kfifo.h | |
parent | 64caff6c941a46ef4a6fffc9c96dced548994e38 (diff) | |
download | barebox-90a17da95cc5dc558cee9446e75b2daa84212be3.tar.gz barebox-90a17da95cc5dc558cee9446e75b2daa84212be3.tar.xz |
add kernel kfifo implementation
Diffstat (limited to 'include/kfifo.h')
-rw-r--r-- | include/kfifo.h | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/include/kfifo.h b/include/kfifo.h new file mode 100644 index 0000000000..6f8be10f67 --- /dev/null +++ b/include/kfifo.h @@ -0,0 +1,83 @@ +/* + * A simple kernel FIFO implementation. + * + * Copyright (C) 2004 Stelian Pop <stelian@popies.net> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ +#ifndef _LINUX_KFIFO_H +#define _LINUX_KFIFO_H + +struct kfifo { + unsigned char *buffer; /* the buffer holding the data */ + unsigned int size; /* the size of the allocated buffer */ + unsigned int in; /* data is added at offset (in % size) */ + unsigned int out; /* data is extracted from off. (out % size) */ +}; + +struct kfifo *kfifo_init(unsigned char *buffer, unsigned int size); +struct kfifo *kfifo_alloc(unsigned int size); +void kfifo_free(struct kfifo *fifo); + +/** + * kfifo_put - puts some data into the FIFO + * @fifo: the fifo to be used. + * @buffer: the data to be added. + * @len: the length of the data to be added. + * + * This function copies at most @len bytes from the @buffer into + * the FIFO depending on the free space, and returns the number of + * bytes copied. + */ +unsigned int kfifo_put(struct kfifo *fifo, + unsigned char *buffer, unsigned int len); + +/** + * kfifo_get - gets some data from the FIFO + * @fifo: the fifo to be used. + * @buffer: where the data must be copied. + * @len: the size of the destination buffer. + * + * This function copies at most @len bytes from the FIFO into the + * @buffer and returns the number of copied bytes. + */ +unsigned int kfifo_get(struct kfifo *fifo, + unsigned char *buffer, unsigned int len); + +/** + * kfifo_reset - removes the entire FIFO contents + * @fifo: the fifo to be emptied. + */ +static inline void kfifo_reset(struct kfifo *fifo) +{ + fifo->in = fifo->out = 0; +} + + +/** + * kfifo_len - returns the number of bytes available in the FIFO. + * @fifo: the fifo to be used. + */ +static inline unsigned int kfifo_len(struct kfifo *fifo) +{ + return fifo->in - fifo->out; +} + +void kfifo_putc(struct kfifo *fifo, unsigned char c); +unsigned int kfifo_getc(struct kfifo *fifo, unsigned char *c); + +#endif + |