From 7d392652bae52b76cb5fe907cc1e86e0e0c4ced9 Mon Sep 17 00:00:00 2001 From: Henrik Rydberg Date: Thu, 17 Jun 2010 20:15:44 +0200 Subject: Add idle function This patch adds the mtdev_idle() function, which checks the kernel device for activity. Useful when implementing timing logic. Signed-off-by: Henrik Rydberg --- src/iobuf.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/iobuf.c') diff --git a/src/iobuf.c b/src/iobuf.c index 6d238ec..83e531a 100644 --- a/src/iobuf.c +++ b/src/iobuf.c @@ -28,6 +28,18 @@ #include "iobuf.h" #include "state.h" +#include + +int mtdev_idle(struct mtdev *dev, int fd, int ms) +{ + struct mtdev_state *state = dev->state; + struct mtdev_iobuf *buf = &state->iobuf; + struct pollfd fds = { fd, POLLIN, 0 }; + return evbuf_empty(&state->outbuf) && + evbuf_empty(&state->inbuf) && + buf->head == buf->tail && + poll(&fds, 1, ms) <= 0; +} int mtdev_fetch(struct mtdev *dev, struct input_event *ev, int fd) { -- cgit v1.2.3