diff options
author | Mattias Andrée <maandree@operamail.com> | 2015-04-26 23:09:47 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2015-04-26 23:09:47 +0200 |
commit | f55736973fe53a0f7cf139887235998521adf67e (patch) | |
tree | 78c122a80903498fcf7f2ae2a3e7642c1aeb52b6 | |
parent | man pages: edit bugs section (diff) | |
download | bus-f55736973fe53a0f7cf139887235998521adf67e.tar.gz bus-f55736973fe53a0f7cf139887235998521adf67e.tar.bz2 bus-f55736973fe53a0f7cf139887235998521adf67e.tar.xz |
add polling functions
Signed-off-by: Mattias Andrée <maandree@operamail.com>
-rw-r--r-- | src/bus.c | 39 | ||||
-rw-r--r-- | src/bus.h | 6 |
2 files changed, 45 insertions, 0 deletions
@@ -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; +} + @@ -173,6 +173,12 @@ int bus_write(const bus_t *bus, const char *message); int bus_read(const bus_t *bus, int (*callback)(const char *message, void *user_data), void *user_data); +int bus_poll_start(const bus_t *bus); +int bus_poll_stop(const bus_t *bus); +int bus_poll_continue(const bus_t *bus); +const char *bus_poll(const bus_t *bus); + + #endif |