aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2015-04-26 23:47:23 +0200
committerMattias Andrée <maandree@operamail.com>2015-04-26 23:47:23 +0200
commit60a10e4dba38d5a800309bcfe9b6ab37f01df7c7 (patch)
tree5297f88a73425aabbebbc21987b4f74f1cee8a7d
parentadd polling functions (diff)
downloadbus-60a10e4dba38d5a800309bcfe9b6ab37f01df7c7.tar.gz
bus-60a10e4dba38d5a800309bcfe9b6ab37f01df7c7.tar.bz2
bus-60a10e4dba38d5a800309bcfe9b6ab37f01df7c7.tar.xz
remove bus_poll_continue, abi breakage
Signed-off-by: Mattias Andrée <maandree@operamail.com>
-rw-r--r--src/bus.c26
-rw-r--r--src/bus.h7
2 files changed, 17 insertions, 16 deletions
diff --git a/src/bus.c b/src/bus.c
index b17d897..c69c492 100644
--- a/src/bus.c
+++ b/src/bus.c
@@ -415,6 +415,7 @@ bus_create(const char *file, int flags, char **out_file)
bus.key_sem = -1;
bus.key_shm = -1;
bus.message = NULL;
+ bus.first_poll = 0;
srand((unsigned int)time(NULL) + (unsigned int)rand());
@@ -667,8 +668,9 @@ fail:
int
-bus_poll_start(const bus_t *bus)
+bus_poll_start(bus_t *bus)
{
+ bus->first_poll = 1;
return release_semaphore(bus, S, SEM_UNDO);
}
@@ -680,23 +682,17 @@ bus_poll_stop(const bus_t *bus)
}
-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)
{
+ if (bus->first_poll) {
+ bus->first_poll = 0;
+ 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));
+ }
t(release_semaphore(bus, Q, 0));
t(zero_semaphore(bus, Q));
return bus->message;
diff --git a/src/bus.h b/src/bus.h
index 64acba7..d30a5d9 100644
--- a/src/bus.h
+++ b/src/bus.h
@@ -92,6 +92,12 @@ typedef struct bus
* The address of the shared memory
*/
char *message;
+
+ /**
+ * Non-zero if and only if `bus_poll` has not been
+ * called since the last `bus_poll_start`
+ */
+ int first_poll;
} bus_t;
@@ -175,7 +181,6 @@ int bus_read(const bus_t *bus, int (*callback)(const char *message, void *user_d
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);