From 4f58962a357191fd382184d06de933b4ebaa97a3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Arve=20Hj=C3=B8nnev=C3=A5g?= Date: Fri, 17 Oct 2008 15:20:55 -0700 Subject: [PATCH] Input: Hold wake lock while event queue is not empty. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Allows userspace code to process input events while the device appears to be asleep. Signed-off-by: Arve Hjønnevåg --- drivers/input/evdev.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/input/evdev.c b/drivers/input/evdev.c index 88d8e4cb419a..5401f47d3d51 100644 --- a/drivers/input/evdev.c +++ b/drivers/input/evdev.c @@ -23,6 +23,7 @@ #include #include #include +#include #include "input-compat.h" struct evdev { @@ -42,6 +43,7 @@ struct evdev_client { unsigned int head; unsigned int tail; spinlock_t buffer_lock; /* protects access to buffer, head and tail */ + struct wake_lock wake_lock; struct fasync_struct *fasync; struct evdev *evdev; struct list_head node; @@ -58,6 +60,7 @@ static void evdev_pass_event(struct evdev_client *client, /* Interrupts are disabled, just acquire the lock. */ spin_lock(&client->buffer_lock); + wake_lock_timeout(&client->wake_lock, 5 * HZ); client->buffer[client->head++] = *event; client->head &= client->bufsize - 1; @@ -251,6 +254,7 @@ static int evdev_release(struct inode *inode, struct file *file) mutex_unlock(&evdev->mutex); evdev_detach_client(evdev, client); + wake_lock_destroy(&client->wake_lock); kfree(client); evdev_close_device(evdev); @@ -302,6 +306,7 @@ static int evdev_open(struct inode *inode, struct file *file) client->bufsize = bufsize; spin_lock_init(&client->buffer_lock); + wake_lock_init(&client->wake_lock, WAKE_LOCK_SUSPEND, "evdev"); client->evdev = evdev; evdev_attach_client(evdev, client); @@ -369,6 +374,8 @@ static int evdev_fetch_next_event(struct evdev_client *client, if (have_event) { *event = client->buffer[client->tail++]; client->tail &= client->bufsize - 1; + if (client->head == client->tail) + wake_unlock(&client->wake_lock); } spin_unlock_irq(&client->buffer_lock); -- 2.11.0