From f55736973fe53a0f7cf139887235998521adf67e Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sun, 26 Apr 2015 23:09:47 +0200 Subject: add polling functions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/bus.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'src/bus.c') diff --git a/src/bus.c b/src/bus.c index db16894..b17d897 100644 --- a/src/bus.c +++ b/src/bus.c @@ -665,3 +665,42 @@ fail: return -1; } + +int +bus_poll_start(const bus_t *bus) +{ + return release_semaphore(bus, S, SEM_UNDO); +} + + +int +bus_poll_stop(const bus_t *bus) +{ + return acquire_semaphore(bus, S, SEM_UNDO); +} + + +int +bus_poll_continue(const bus_t *bus) +{ + t(release_semaphore(bus, W, SEM_UNDO)); + t(acquire_semaphore(bus, S, SEM_UNDO)); + t(zero_semaphore(bus, S)); + t(release_semaphore(bus, S, SEM_UNDO)); + t(acquire_semaphore(bus, W, SEM_UNDO)); + return 0; +fail: + return -1; +} + + +const char * +bus_poll(const bus_t *bus) +{ + t(release_semaphore(bus, Q, 0)); + t(zero_semaphore(bus, Q)); + return bus->message; +fail: + return NULL; +} + -- cgit v1.2.3-70-g09d2