kfifo: add kfifo_skip, kfifo_from_user and kfifo_to_user

Add kfifo_reset_out() for save lockless discard the fifo output
 Add kfifo_skip() to skip a number of output bytes
 Add kfifo_from_user() to copy user space data into the fifo
 Add kfifo_to_user() to copy fifo data to user space

Signed-off-by: Stefani Seibold <stefani@seibold.net>
Acked-by: Greg Kroah-Hartman <gregkh@suse.de>
Acked-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Acked-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
Stefani Seibold 2009-12-21 14:37:31 -08:00 committed by Linus Torvalds
parent 37bdfbbfaa
commit a121f24acc
2 changed files with 174 additions and 20 deletions

View file

@ -124,6 +124,16 @@ static inline void kfifo_reset(struct kfifo *fifo)
fifo->in = fifo->out = 0;
}
/**
* kfifo_reset_out - skip FIFO contents
* @fifo: the fifo to be emptied.
*/
static inline void kfifo_reset_out(struct kfifo *fifo)
{
smp_mb();
fifo->out = fifo->in;
}
/**
* kfifo_size - returns the size of the fifo in bytes
* @fifo: the fifo to be used.
@ -231,4 +241,41 @@ static inline __must_check unsigned int kfifo_out_locked(struct kfifo *fifo,
return ret;
}
extern void kfifo_skip(struct kfifo *fifo, unsigned int len);
extern __must_check unsigned int kfifo_from_user(struct kfifo *fifo,
const void __user *from, unsigned int n);
extern __must_check unsigned int kfifo_to_user(struct kfifo *fifo,
void __user *to, unsigned int n);
/**
* __kfifo_add_out internal helper function for updating the out offset
*/
static inline void __kfifo_add_out(struct kfifo *fifo,
unsigned int off)
{
smp_mb();
fifo->out += off;
}
/**
* __kfifo_add_in internal helper function for updating the in offset
*/
static inline void __kfifo_add_in(struct kfifo *fifo,
unsigned int off)
{
smp_wmb();
fifo->in += off;
}
/**
* __kfifo_off internal helper function for calculating the index of a
* given offeset
*/
static inline unsigned int __kfifo_off(struct kfifo *fifo, unsigned int off)
{
return off & (fifo->size - 1);
}
#endif