From 3b6bc1a7dc5871aef2c47426f87bb409a622de29 Mon Sep 17 00:00:00 2001 From: Henrik Rydberg Date: Fri, 6 Aug 2010 14:32:50 +0200 Subject: Remove thread code The primary usecase of grail involves using it together with the xserver, which is not threaded. Revert the touch-dev code back to the state prior to adding the threaded processing. Deferred event handling can be implemented by other means when needed. Signed-off-by: Henrik Rydberg --- include/grail-touch.h | 3 +-- src/Makefile.am | 2 +- src/grail-api.c | 70 ++------------------------------------------------- src/touch-dev.c | 35 ++------------------------ test/grail-gesture.c | 4 +-- test/grail-touch.c | 6 ++--- 6 files changed, 9 insertions(+), 111 deletions(-) diff --git a/include/grail-touch.h b/include/grail-touch.h index 5bf0034..5c2fab0 100644 --- a/include/grail-touch.h +++ b/include/grail-touch.h @@ -92,8 +92,7 @@ struct touch_engine { int touch_dev_open(struct touch_dev *dev, int fd); int touch_dev_idle(struct touch_dev *dev, int fd, int ms); -int touch_dev_fetch(struct touch_dev *dev, int fd); -int touch_dev_process(struct touch_dev *dev); +int touch_dev_pull(struct touch_dev *dev, int fd); void touch_dev_close(struct touch_dev *dev, int fd); void touch_engine_init(struct touch_engine *engine, diff --git a/src/Makefile.am b/src/Makefile.am index 932c8ae..3b001b2 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -23,7 +23,7 @@ libgrail_la_SOURCES = \ grail-recognizer.h \ grail-api.c -AM_CFLAGS = $(CWARNFLAGS) -pthread +AM_CFLAGS = $(CWARNFLAGS) INCLUDES = -I$(top_srcdir)/include/ diff --git a/src/grail-api.c b/src/grail-api.c index 2c6c438..9ceb1e7 100644 --- a/src/grail-api.c +++ b/src/grail-api.c @@ -1,8 +1,6 @@ #include "grail-inserter.h" #include "grail-recognizer.h" #include -#include -#include #include #include #include @@ -11,48 +9,12 @@ #include #include "evbuf.h" -static const pthread_mutex_t c_mutex = PTHREAD_MUTEX_INITIALIZER; -static const pthread_cond_t c_wait = PTHREAD_COND_INITIALIZER; - struct grail_impl { struct touch_dev dev; struct touch_engine engine; struct evbuf evbuf; - int fd; - int pull, finished; - pthread_mutex_t mutex; - pthread_cond_t wait; - pthread_t thread; }; -/* - * While not finished, lock, wait for condition, extract the running - * state, unlock, then process the event queue. - * - * The processing may in principle take seconds to complete without - * locking up the writer side. - */ -static void *grail_thread(void *priv) -{ - struct grail_impl *x = priv; - int pull, finished = 0; - sigset_t block; - sigemptyset(&block); - sigaddset(&block, SIGIO); - pthread_sigmask(SIG_BLOCK, &block, NULL); - while (!finished) { - pthread_mutex_lock(&x->mutex); - pthread_cond_wait(&x->wait, &x->mutex); - pull = x->pull; - finished = x->finished; - x->pull = 0; - if (!finished && pull) - touch_dev_process(&x->dev); - pthread_mutex_unlock(&x->mutex); - } - pthread_exit(NULL); -} - static void tp_event(struct touch_engine *engine, const struct input_event *ev) { @@ -105,17 +67,9 @@ int grail_open(struct grail *ge, int fd) ret = gru_init(ge); if (ret) goto freedev; - x->fd = fd; - x->mutex = c_mutex; - x->wait = c_wait; - ret = pthread_create(&x->thread, NULL, grail_thread, x); - if (ret) - goto freegru; touch_engine_init(&x->engine, tp_event, tp_sync, ge); touch_engine_attach(&x->engine, &x->dev); return 0; - freegru: - gru_destroy(ge); freedev: touch_dev_close(&x->dev, fd); freegin: @@ -130,10 +84,6 @@ void grail_close(struct grail *ge, int fd) { struct grail_impl *x = ge->impl; void *status; - pthread_mutex_lock(&x->mutex); - x->finished = 1; - pthread_cond_signal (&x->wait); - pthread_mutex_unlock(&x->mutex); touch_engine_detach(&x->engine, &x->dev); gru_destroy(ge); touch_dev_close(&x->dev, fd); @@ -145,29 +95,13 @@ void grail_close(struct grail *ge, int fd) int grail_idle(struct grail *ge, int fd, int ms) { struct grail_impl *x = ge->impl; - int ret; - pthread_mutex_lock(&x->mutex); - ret = touch_dev_idle(&x->dev, fd, ms); - pthread_mutex_unlock(&x->mutex); - return ret; + return touch_dev_idle(&x->dev, fd, ms); } -/* - * First extract all input events to a lockless circular buffer, then, - * under lock, signal the worker thread. - * - * This function only blocks temporarily while signalling the worker - * thread. - */ int grail_pull(struct grail *ge, int fd) { struct grail_impl *x = ge->impl; - pthread_mutex_lock(&x->mutex); - x->pull = 1; - x->finished = touch_dev_fetch(&x->dev, fd) < 0; - pthread_cond_signal(&x->wait); - pthread_mutex_unlock(&x->mutex); - return 1; + return touch_dev_pull(&x->dev, fd); } void grail_get_units(struct grail_coord *min, struct grail_coord *max, diff --git a/src/touch-dev.c b/src/touch-dev.c index b327266..4cc8d55 100644 --- a/src/touch-dev.c +++ b/src/touch-dev.c @@ -26,7 +26,6 @@ #include #include #include -#include "evbuf.h" /* from mtdev-mapping.h */ #define MT_TOUCH_MAJOR 0 @@ -50,7 +49,6 @@ struct touch_dev_impl { int status; grail_mask_t mask[DIM_TOUCH_BYTES]; touch_prop_t prop[DIM_TOUCH_PROP]; - struct evbuf evbuf; struct mtdev mtdev; }; @@ -82,23 +80,6 @@ static void set_caps(struct touch_dev_caps *caps, set_info(caps, TP_PRESSURE, &mtcaps->abs[MT_PRESSURE]); } -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 void set_prop(struct touch_dev_impl *x, int code, int value) { grail_mask_set(x->mask, code); @@ -207,24 +188,12 @@ int touch_dev_idle(struct touch_dev *dev, int fd, int ms) return mtdev_idle(&dev->impl->mtdev, fd, ms); } -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) +int touch_dev_pull(struct touch_dev *dev, int fd) { struct touch_dev_impl *x = dev->impl; struct input_event ev; int ret, count = 0, consumed; - while ((ret = touch_get_fetched(x, &ev, 1)) > 0) { + while ((ret = mtdev_get(&x->mtdev, fd, &ev, 1)) > 0) { consumed = 0; if (ev.type == EV_SYN) { if (ev.code == SYN_REPORT) diff --git a/test/grail-gesture.c b/test/grail-gesture.c index 18c50c3..16b33ac 100644 --- a/test/grail-gesture.c +++ b/test/grail-gesture.c @@ -64,10 +64,8 @@ static void tp_gesture(struct grail *ge, const struct grail_event *ev) static void loop_device(struct grail *ge, int fd) { - while (!grail_idle(ge, fd, 5000)) { + while (!grail_idle(ge, fd, 5000)) grail_pull(ge, fd); - fprintf(stderr, "\r"); - } } int main(int argc, char *argv[]) diff --git a/test/grail-touch.c b/test/grail-touch.c index 8893c0d..bed31c3 100644 --- a/test/grail-touch.c +++ b/test/grail-touch.c @@ -54,10 +54,8 @@ static void loop_device(struct touch_dev *dev, int fd) struct touch_engine engine; touch_engine_init(&engine, tp_event, tp_sync, 0); touch_engine_attach(&engine, dev); - while (!touch_dev_idle(dev, fd, 5000)) { - touch_dev_fetch(dev, fd); - touch_dev_process(dev); - } + while (!touch_dev_idle(dev, fd, 5000)) + touch_dev_pull(dev, fd); touch_engine_detach(&engine, dev); } -- cgit v1.2.3