From 342a43e7b2ceec1dd200bffa24b052fec33f5bdc Mon Sep 17 00:00:00 2001 From: Henrik Rydberg Date: Fri, 30 Jul 2010 15:29:38 +0200 Subject: Introduce threading In order to enable deferred events from grail, but the event processing in a separate thread, and have the calling thread return as quickly as possible. Signed-off-by: Henrik Rydberg --- src/touch-dev.c | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) (limited to 'src/touch-dev.c') diff --git a/src/touch-dev.c b/src/touch-dev.c index dc23baa..b7efb35 100644 --- a/src/touch-dev.c +++ b/src/touch-dev.c @@ -26,6 +26,8 @@ #include #include #include +#include "evbuf.h" +#include "mtdev-plumbing.h" #define DIM_TOUCH 32 @@ -35,9 +37,27 @@ struct touch_dev_impl { int status; touch_prop_mask_t mask[1]; touch_prop_t prop[DIM_TOUCH_PROP]; + struct evbuf evbuf; struct mtdev mtdev; }; +static int touch_get_fetched(struct touch_dev_impl *x, + struct input_event* ev, int ev_max) +{ + struct input_event kev; + int count = 0; + while (count < ev_max) { + while (mtdev_empty(&x->mtdev)) { + if (evbuf_empty(&x->evbuf)) + return count; + evbuf_get(&x->evbuf, &kev); + mtdev_put_event(&x->mtdev, &kev); + } + mtdev_get_event(&x->mtdev, &ev[count++]); + } + return count; +} + static inline int has_any_prop(const touch_prop_mask_t *mask) { return mask[0] != 0; @@ -149,12 +169,24 @@ int touch_dev_idle(struct touch_dev *dev, int fd, int ms) return mtdev_idle(&dev->impl->mtdev, fd, ms); } -int touch_dev_pull(struct touch_dev *dev, int fd) +int touch_dev_fetch(struct touch_dev *dev, int fd) +{ + struct touch_dev_impl *x = dev->impl; + struct input_event ev; + int ret, count = 0; + while ((ret = mtdev_fetch_event(&x->mtdev, fd, &ev)) > 0) { + evbuf_put(&x->evbuf, &ev); + count++; + } + return count > 0 ? count : ret; +} + +int touch_dev_process(struct touch_dev *dev) { struct touch_dev_impl *x = dev->impl; struct input_event ev; int ret, count = 0, consumed; - while ((ret = mtdev_get(&x->mtdev, fd, &ev, 1)) > 0) { + while ((ret = touch_get_fetched(x, &ev, 1)) > 0) { consumed = 0; if (ev.type == EV_SYN) { if (ev.code == SYN_REPORT) -- cgit v1.2.3