Re: [PATCH] [4/6] kfifo: add kfifo_out_peek

From: Stefani Seibold
Date: Sun Dec 27 2009 - 16:49:59 EST


Am Sonntag, den 27.12.2009, 22:03 +0100 schrieb Andi Kleen:
> 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.
>

Yes this function can be useful. I will implement it in the macro
version of the kfifo.

> Signed-off-by: Andi Kleen <ak@xxxxxxxxxxxxxxx>
>
> ---
> include/linux/kfifo.h | 3 +++
> kernel/kfifo.c | 21 +++++++++++++++++++++
> 2 files changed, 24 insertions(+)
>
> Index: linux/include/linux/kfifo.h
> ===================================================================
> --- linux.orig/include/linux/kfifo.h
> +++ linux/include/linux/kfifo.h
> @@ -114,6 +114,9 @@ extern unsigned int kfifo_in(struct kfif
> const void *from, unsigned int len);
> extern __must_check unsigned int kfifo_out(struct kfifo *fifo,
> 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
> Index: linux/kernel/kfifo.c
> ===================================================================
> --- linux.orig/kernel/kfifo.c
> +++ linux/kernel/kfifo.c
> @@ -301,6 +301,27 @@ unsigned int kfifo_out(struct kfifo *fif
> }
> 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,
> void *to, unsigned int len, unsigned int recsize,
> unsigned int *total)


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/