From: Lars-Peter Clausen <lars@metafoo.de>
To: Jonathan Cameron <jic23@cam.ac.uk>
Cc: Michael Hennerich <michael.hennerich@analog.com>,
<linux-iio@vger.kernel.org>,
<device-drivers-devel@blackfin.uclinux.org>, <drivers@analog.com>,
Lars-Peter Clausen <lars@metafoo.de>
Subject: [PATCH 4/4] staging:iio:events: Add poll support
Date: Fri, 16 Dec 2011 18:12:22 +0100 [thread overview]
Message-ID: <1324055542-31272-4-git-send-email-lars@metafoo.de> (raw)
In-Reply-To: <1324055542-31272-1-git-send-email-lars@metafoo.de>
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>
---
drivers/staging/iio/industrialio-event.c | 22 +++++++++++++++++++++-
1 files changed, 21 insertions(+), 1 deletions(-)
diff --git a/drivers/staging/iio/industrialio-event.c b/drivers/staging/iio/industrialio-event.c
index ef4943a..2263269 100644
--- a/drivers/staging/iio/industrialio-event.c
+++ b/drivers/staging/iio/industrialio-event.c
@@ -56,7 +56,7 @@ int iio_push_event(struct iio_dev *indio_dev, u64 ev_code, s64 timestamp)
ret = kfifo_put(&ev_int->det_events, &ev);
if (ret != 0)
- wake_up_locked(&ev_int->wait);
+ wake_up_locked_poll(&ev_int->wait, POLLIN);
}
spin_unlock(&ev_int->wait.lock);
@@ -64,6 +64,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,
@@ -112,6 +131,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,
--
1.7.7.3
next prev parent reply other threads:[~2011-12-16 17:12 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-12-16 17:12 [PATCH 1/4] staging:iio: Factor out event handling into its own file Lars-Peter Clausen
2011-12-16 17:12 ` [PATCH 2/4] staging:iio:events: Use kfifo for event queue Lars-Peter Clausen
2011-12-18 21:42 ` Jonathan Cameron
2011-12-18 21:43 ` Jonathan Cameron
2011-12-16 17:12 ` [PATCH 3/4] staging:iio:events: Use waitqueue lock to protect " Lars-Peter Clausen
2011-12-18 21:54 ` Jonathan Cameron
2011-12-19 8:25 ` Lars-Peter Clausen
2011-12-19 8:31 ` J.I. Cameron
2011-12-19 8:54 ` J.I. Cameron
2011-12-16 17:12 ` Lars-Peter Clausen [this message]
2011-12-19 8:46 ` [PATCH 4/4] staging:iio:events: Add poll support jic23
2011-12-18 18:19 ` [PATCH 1/4] staging:iio: Factor out event handling into its own file Jonathan Cameron
2011-12-18 18:24 ` Jonathan Cameron
2011-12-18 19:46 ` Lars-Peter Clausen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1324055542-31272-4-git-send-email-lars@metafoo.de \
--to=lars@metafoo.de \
--cc=device-drivers-devel@blackfin.uclinux.org \
--cc=drivers@analog.com \
--cc=jic23@cam.ac.uk \
--cc=linux-iio@vger.kernel.org \
--cc=michael.hennerich@analog.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).