]> git.karo-electronics.de Git - linux-beck.git/commitdiff
staging:iio:events: Add poll support
authorLars-Peter Clausen <lars@metafoo.de>
Tue, 3 Jan 2012 13:59:41 +0000 (14:59 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 9 Feb 2012 18:05:06 +0000 (10:05 -0800)
Add poll support to the event queue. This will allow us to check for pending
events in a application's event loop using poll() or similar. Since we already
have support for blocking reads adding poll support as well is trivial.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Acked-by: Jonathan Cameron <jic23@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/iio/industrialio-event.c

index f0c41f1f505a02f7a5bf82afae446dbbe8ed1ae6..800f67d4cce1569b279258d6cc1836b6cf306ba1 100644 (file)
@@ -15,6 +15,7 @@
 #include <linux/kernel.h>
 #include <linux/kfifo.h>
 #include <linux/module.h>
+#include <linux/poll.h>
 #include <linux/sched.h>
 #include <linux/slab.h>
 #include <linux/uaccess.h>
@@ -57,7 +58,7 @@ int iio_push_event(struct iio_dev *indio_dev, u64 ev_code, s64 timestamp)
 
                copied = kfifo_put(&ev_int->det_events, &ev);
                if (copied != 0)
-                       wake_up_locked(&ev_int->wait);
+                       wake_up_locked_poll(&ev_int->wait, POLLIN);
        }
        spin_unlock(&ev_int->wait.lock);
 
@@ -65,6 +66,25 @@ int iio_push_event(struct iio_dev *indio_dev, u64 ev_code, s64 timestamp)
 }
 EXPORT_SYMBOL(iio_push_event);
 
+/**
+ * iio_event_poll() - poll the event queue to find out if it has data
+ */
+static unsigned int iio_event_poll(struct file *filep,
+                            struct poll_table_struct *wait)
+{
+       struct iio_event_interface *ev_int = filep->private_data;
+       unsigned int events = 0;
+
+       poll_wait(filep, &ev_int->wait, wait);
+
+       spin_lock(&ev_int->wait.lock);
+       if (!kfifo_is_empty(&ev_int->det_events))
+               events = POLLIN | POLLRDNORM;
+       spin_unlock(&ev_int->wait.lock);
+
+       return events;
+}
+
 static ssize_t iio_event_chrdev_read(struct file *filep,
                                     char __user *buf,
                                     size_t count,
@@ -118,6 +138,7 @@ static int iio_event_chrdev_release(struct inode *inode, struct file *filep)
 
 static const struct file_operations iio_event_chrdev_fileops = {
        .read =  iio_event_chrdev_read,
+       .poll =  iio_event_poll,
        .release = iio_event_chrdev_release,
        .owner = THIS_MODULE,
        .llseek = noop_llseek,