提交 a5b9e2c1 编写于 作者: A Andi Kleen 提交者: Linus Torvalds

kfifo: add kfifo_out_peek

In some upcoming code it's useful to peek into a FIFO without permanentely
removing data.  This patch implements a new kfifo_out_peek() to do this.
Signed-off-by: NAndi Kleen <ak@linux.intel.com>
Acked-by: NStefani Seibold <stefani@seibold.net>
Cc: Roland Dreier <rdreier@cisco.com>
Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: Andy Walls <awalls@radix.net>
Cc: Vikram Dhillon <dhillonv10@gmail.com>
Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
上级 64ce1037
...@@ -113,6 +113,9 @@ extern unsigned int kfifo_in(struct kfifo *fifo, ...@@ -113,6 +113,9 @@ extern unsigned int kfifo_in(struct kfifo *fifo,
const void *from, unsigned int len); const void *from, unsigned int len);
extern __must_check unsigned int kfifo_out(struct kfifo *fifo, extern __must_check unsigned int kfifo_out(struct kfifo *fifo,
void *to, unsigned int len); void *to, unsigned int len);
extern __must_check unsigned int kfifo_out_peek(struct kfifo *fifo,
void *to, unsigned int len, unsigned offset);
/** /**
* kfifo_reset - removes the entire FIFO contents * kfifo_reset - removes the entire FIFO contents
......
...@@ -302,6 +302,27 @@ unsigned int kfifo_out(struct kfifo *fifo, void *to, unsigned int len) ...@@ -302,6 +302,27 @@ unsigned int kfifo_out(struct kfifo *fifo, void *to, unsigned int len)
} }
EXPORT_SYMBOL(kfifo_out); EXPORT_SYMBOL(kfifo_out);
/**
* kfifo_out_peek - copy some data from the FIFO, but do not remove it
* @fifo: the fifo to be used.
* @to: where the data must be copied.
* @len: the size of the destination buffer.
* @offset: offset into the fifo
*
* This function copies at most @len bytes at @offset from the FIFO
* into the @to buffer and returns the number of copied bytes.
* The data is not removed from the FIFO.
*/
unsigned int kfifo_out_peek(struct kfifo *fifo, void *to, unsigned int len,
unsigned offset)
{
len = min(kfifo_len(fifo), len + offset);
__kfifo_out_data(fifo, to, len, offset);
return len;
}
EXPORT_SYMBOL(kfifo_out_peek);
unsigned int __kfifo_out_generic(struct kfifo *fifo, unsigned int __kfifo_out_generic(struct kfifo *fifo,
void *to, unsigned int len, unsigned int recsize, void *to, unsigned int len, unsigned int recsize,
unsigned int *total) unsigned int *total)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册