[RFC 3/8] media: Support polling for completed requests

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Implement poll for events. POLLPRI is used to notify the user an event is
complete.

Signed-off-by: Sakari Ailus <sakari.ailus@xxxxxxxxxxxxxxx>
---
 drivers/media/media-device.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
index 41ec5ac..a4d3884 100644
--- a/drivers/media/media-device.c
+++ b/drivers/media/media-device.c
@@ -84,6 +84,34 @@ void media_device_request_put(struct media_device_request *req)
 }
 EXPORT_SYMBOL_GPL(media_device_request_put);
 
+static unsigned int media_device_request_poll(struct file *filp,
+					      struct poll_table_struct *wait)
+{
+	struct media_device_request *req = filp->private_data;
+	struct media_device *mdev = req->mdev;
+	unsigned int poll_events = poll_requested_events(wait);
+	int ret = 0;
+
+	if (poll_events & (POLLIN | POLLOUT))
+		return POLLERR;
+
+	if (poll_events & POLLPRI) {
+		unsigned long flags;
+		bool complete;
+
+		spin_lock_irqsave(&mdev->req_lock, flags);
+		complete = req->state == MEDIA_DEVICE_REQUEST_STATE_COMPLETE;
+		spin_unlock_irqrestore(&mdev->req_lock, flags);
+
+		if (complete)
+			poll_wait(filp, &req->poll_wait, wait);
+		else
+			ret |= POLLPRI;
+	}
+
+	return ret;
+}
+
 static int media_device_request_close(struct inode *inode, struct file *filp)
 {
 	struct media_device_request *req = filp->private_data;
@@ -95,6 +123,7 @@ static int media_device_request_close(struct inode *inode, struct file *filp)
 
 static const struct file_operations request_fops = {
 	.owner = THIS_MODULE,
+	.poll = media_device_request_poll,
 	.release = media_device_request_close,
 };
 
-- 
2.7.4




[Index of Archives]     [Linux Input]     [Video for Linux]     [Gstreamer Embedded]     [Mplayer Users]     [Linux USB Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux