summaryrefslogtreecommitdiff
path: root/src/touch-dev.c
diff options
context:
space:
mode:
authorHenrik Rydberg <rydberg@bitmath.org>2010-07-30 15:29:38 +0200
committerHenrik Rydberg <rydberg@euromail.se>2010-08-05 22:48:38 +0200
commit342a43e7b2ceec1dd200bffa24b052fec33f5bdc (patch)
tree291938b98037efe6e0def19e7457b9a947c484f1 /src/touch-dev.c
parente0eb1015bf30fd0913db571b000ba6a83ea22660 (diff)
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 <rydberg@bitmath.org>
Diffstat (limited to 'src/touch-dev.c')
-rw-r--r--src/touch-dev.c36
1 files changed, 34 insertions, 2 deletions
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 @@
26#include <malloc.h> 26#include <malloc.h>
27#include <string.h> 27#include <string.h>
28#include <errno.h> 28#include <errno.h>
29#include "evbuf.h"
30#include "mtdev-plumbing.h"
29 31
30#define DIM_TOUCH 32 32#define DIM_TOUCH 32
31 33
@@ -35,9 +37,27 @@ struct touch_dev_impl {
35 int status; 37 int status;
36 touch_prop_mask_t mask[1]; 38 touch_prop_mask_t mask[1];
37 touch_prop_t prop[DIM_TOUCH_PROP]; 39 touch_prop_t prop[DIM_TOUCH_PROP];
40 struct evbuf evbuf;
38 struct mtdev mtdev; 41 struct mtdev mtdev;
39}; 42};
40 43
44static int touch_get_fetched(struct touch_dev_impl *x,
45 struct input_event* ev, int ev_max)
46{
47 struct input_event kev;
48 int count = 0;
49 while (count < ev_max) {
50 while (mtdev_empty(&x->mtdev)) {
51 if (evbuf_empty(&x->evbuf))
52 return count;
53 evbuf_get(&x->evbuf, &kev);
54 mtdev_put_event(&x->mtdev, &kev);
55 }
56 mtdev_get_event(&x->mtdev, &ev[count++]);
57 }
58 return count;
59}
60
41static inline int has_any_prop(const touch_prop_mask_t *mask) 61static inline int has_any_prop(const touch_prop_mask_t *mask)
42{ 62{
43 return mask[0] != 0; 63 return mask[0] != 0;
@@ -149,12 +169,24 @@ int touch_dev_idle(struct touch_dev *dev, int fd, int ms)
149 return mtdev_idle(&dev->impl->mtdev, fd, ms); 169 return mtdev_idle(&dev->impl->mtdev, fd, ms);
150} 170}
151 171
152int touch_dev_pull(struct touch_dev *dev, int fd) 172int touch_dev_fetch(struct touch_dev *dev, int fd)
173{
174 struct touch_dev_impl *x = dev->impl;
175 struct input_event ev;
176 int ret, count = 0;
177 while ((ret = mtdev_fetch_event(&x->mtdev, fd, &ev)) > 0) {
178 evbuf_put(&x->evbuf, &ev);
179 count++;
180 }
181 return count > 0 ? count : ret;
182}
183
184int touch_dev_process(struct touch_dev *dev)
153{ 185{
154 struct touch_dev_impl *x = dev->impl; 186 struct touch_dev_impl *x = dev->impl;
155 struct input_event ev; 187 struct input_event ev;
156 int ret, count = 0, consumed; 188 int ret, count = 0, consumed;
157 while ((ret = mtdev_get(&x->mtdev, fd, &ev, 1)) > 0) { 189 while ((ret = touch_get_fetched(x, &ev, 1)) > 0) {
158 consumed = 0; 190 consumed = 0;
159 if (ev.type == EV_SYN) { 191 if (ev.type == EV_SYN) {
160 if (ev.code == SYN_REPORT) 192 if (ev.code == SYN_REPORT)