aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2015-04-27 01:23:38 +0200
committerMattias Andrée <maandree@operamail.com>2015-04-27 01:23:38 +0200
commitd775b3388f82b16068111ddbf3f4fe1c0b1cedb3 (patch)
tree8499e75c6e7f89d2908e1c9e11c4f619fcd99c95 /src
parentadd nowait option to bus_write (diff)
downloadbus-d775b3388f82b16068111ddbf3f4fe1c0b1cedb3.tar.gz
bus-d775b3388f82b16068111ddbf3f4fe1c0b1cedb3.tar.bz2
bus-d775b3388f82b16068111ddbf3f4fe1c0b1cedb3.tar.xz
add nowait option to bus_poll
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to '')
-rw-r--r--src/bus.c7
-rw-r--r--src/bus.h5
2 files changed, 8 insertions, 4 deletions
diff --git a/src/bus.c b/src/bus.c
index 0c121a6..614f7ad 100644
--- a/src/bus.c
+++ b/src/bus.c
@@ -723,7 +723,7 @@ const char *
bus_poll(bus_t *bus, int flags)
{
int state = 0, saved_errno;
- (void) flags; /* TODO nonblocking */
+ (void) flags;
if (!bus->first_poll) {
t(release_semaphore(bus, W, SEM_UNDO)); state++;
t(acquire_semaphore(bus, S, SEM_UNDO)); state++;
@@ -734,8 +734,9 @@ bus_poll(bus_t *bus, int flags)
} else {
bus->first_poll = 0;
}
+ state--;
t(release_semaphore(bus, Q, 0));
- t(zero_semaphore(bus, Q, 0));
+ t(zero_semaphore(bus, Q, F(BUS_NOWAIT, IPC_NOWAIT)));
return bus->message;
fail:
@@ -744,6 +745,8 @@ fail:
release_semaphore(bus, S, SEM_UNDO);
if (state > 0)
acquire_semaphore(bus, W, SEM_UNDO);
+ if (state < 0)
+ bus->first_poll = 1;
errno = saved_errno;
return NULL;
}
diff --git a/src/bus.h b/src/bus.h
index ed1c5de..ac03106 100644
--- a/src/bus.h
+++ b/src/bus.h
@@ -101,7 +101,8 @@ typedef struct bus
/**
* Non-zero if and only if `bus_poll` has not been
- * called since the last `bus_poll_start`
+ * called since the last `bus_poll_start`, or
+ * if `bus_poll` failed during reading
*/
int first_poll;
} bus_t;
@@ -190,7 +191,7 @@ int bus_read(const bus_t *bus, int (*callback)(const char *message, void *user_d
int bus_poll_start(bus_t *bus);
int bus_poll_stop(const bus_t *bus);
-const char *bus_poll(bus_t *bus, int falgs);
+const char *bus_poll(bus_t *bus, int flags);