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 --- src/grail-api.c | 70 ++------------------------------------------------------- 1 file changed, 2 insertions(+), 68 deletions(-) (limited to 'src/grail-api.c') 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, -- cgit v1.2.3