@@ -55,15 +55,19 @@ static void evdev_pass_event(struct evdev_client *client,
{
/*
* Interrupts are disabled, just acquire the lock.
- * Make sure we don't leave with the client buffer
- * "empty" by having client->head == client->tail.
*/
spin_lock(&client->buffer_lock);
- do {
- client->buffer[client->head++] = *event;
- client->head &= client->bufsize - 1;
- } while (client->head == client->tail);
- spin_unlock(&client->buffer_lock);
+ client->buffer[client->head++] = *event;
+ client->head &= client->bufsize - 1;
+
+ /*
+ * If we overflow the buffer, consume the oldest
+ * event to make room for the one that just arrived
+ */
+ if (unlikely(client->head == client->tail)) {
+ client->tail++;
+ client->tail &= client->bufsize - 1;
+ }
if (event->type == EV_SYN)
kill_fasync(&client->fasync, SIGIO, POLL_IN);