aboutsummaryrefslogtreecommitdiffstats
path: root/src/bus.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2015-04-27 01:17:21 +0200
committerMattias Andrée <maandree@operamail.com>2015-04-27 01:17:24 +0200
commitdc61596aabe1d74718ba999f1002e0d7d88a944e (patch)
tree791c63a21524240a918d3f25fcee7e801461cad8 /src/bus.c
parentm whitespace (diff)
downloadbus-dc61596aabe1d74718ba999f1002e0d7d88a944e.tar.gz
bus-dc61596aabe1d74718ba999f1002e0d7d88a944e.tar.bz2
bus-dc61596aabe1d74718ba999f1002e0d7d88a944e.tar.xz
add nowait option to bus_write
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to '')
-rw-r--r--src/bus.c22
1 files changed, 17 insertions, 5 deletions
diff --git a/src/bus.c b/src/bus.c
index ff2abeb..0c121a6 100644
--- a/src/bus.c
+++ b/src/bus.c
@@ -126,6 +126,14 @@
(memcpy((bus)->message, msg, (strlen(msg) + 1) * sizeof(char)))
+/**
+ * If `flags & (bus_flag)`, this macro evalutes to `sys_flag`,
+ * otherwise this macro evalutes to 0.
+ */
+#define F(bus_flag, sys_flag) \
+ ((flags & (bus_flag)) ? sys_flag : 0)
+
+
/**
* Statement wrapper that goes to `fail` on failure
@@ -607,13 +615,16 @@ fail:
* @param bus Bus information
* @param message The message to write, may not be longer than
* `BUS_MEMORY_SIZE` including the NUL-termination
+ * @param flags `BUS_NOWAIT` if this function shall fail if
+ * another process is currently running this
+ * procedure
* @return 0 on success, -1 on error
*/
-int /* TODO nonblocking */
-bus_write(const bus_t *bus, const char *message)
+int
+bus_write(const bus_t *bus, const char *message, int flags /* TODO document in man page */)
{
int state = 0, saved_errno;
- if (acquire_semaphore(bus, X, SEM_UNDO) == -1)
+ if (acquire_semaphore(bus, X, SEM_UNDO | F(BUS_NOWAIT, IPC_NOWAIT)) == -1)
return -1;
t(zero_semaphore(bus, W, 0));
write_shared_memory(bus, message);
@@ -708,10 +719,11 @@ bus_poll_stop(const bus_t *bus)
}
-const char * /* TODO nonblocking */
-bus_poll(bus_t *bus)
+const char *
+bus_poll(bus_t *bus, int flags)
{
int state = 0, saved_errno;
+ (void) flags; /* TODO nonblocking */
if (!bus->first_poll) {
t(release_semaphore(bus, W, SEM_UNDO)); state++;
t(acquire_semaphore(bus, S, SEM_UNDO)); state++;