]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - include/linux/kfifo.h
Merge current mainline tree into linux-omap tree
[linux-2.6-omap-h63xx.git] / include / linux / kfifo.h
index 29f62e1733ff4e23c61e4f25c75d6e5498e4ab93..17065f7681a036cd27494cef8f94be05137dc23e 100644 (file)
@@ -41,6 +41,9 @@ extern unsigned int __kfifo_put(struct kfifo *fifo,
                                unsigned char *buffer, unsigned int len);
 extern unsigned int __kfifo_get(struct kfifo *fifo,
                                unsigned char *buffer, unsigned int len);
+extern unsigned int __kfifo_get_to_user(struct kfifo *fifo,
+                                       unsigned char __user *buffer,
+                                       unsigned int len);
 
 /**
  * __kfifo_reset - removes the entire FIFO contents, no locking version
@@ -149,4 +152,36 @@ static inline unsigned int kfifo_len(struct kfifo *fifo)
        return ret;
 }
 
+/**
+ * kfifo_get_to_user - gets some data from the FIFO
+ * @fifo: the fifo to be used.
+ * @buffer: where the data must be copied. user buffer
+ * @len: the size of the destination buffer.
+ *
+ * This function copies at most @len bytes from the FIFO into the
+ * user @buffer and returns the number of copied bytes.
+ */
+static inline unsigned int kfifo_get_to_user(struct kfifo *fifo,
+                                            unsigned char __user *buffer,
+                                            unsigned int len)
+{
+       unsigned long flags;
+       unsigned int ret;
+
+       spin_lock_irqsave(fifo->lock, flags);
+
+       ret = __kfifo_get_to_user(fifo, buffer, len);
+
+       /*
+        * optimization: if the FIFO is empty, set the indices to 0
+        * so we don't wrap the next time
+        */
+       if (fifo->in == fifo->out)
+               fifo->in = fifo->out = 0;
+
+       spin_unlock_irqrestore(fifo->lock, flags);
+
+       return ret;
+}
+
 #endif