aboutsummaryrefslogtreecommitdiffstats
path: root/src/bus.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2015-04-28 12:57:30 +0200
committerMattias Andrée <maandree@operamail.com>2015-04-28 12:57:30 +0200
commit110027ec9f78941fcf8cc5f36b7055e17a206af6 (patch)
tree7de5440a73953d399b4f9bc986346592efb030df /src/bus.c
parentm readme (diff)
downloadbus-110027ec9f78941fcf8cc5f36b7055e17a206af6.tar.gz
bus-110027ec9f78941fcf8cc5f36b7055e17a206af6.tar.bz2
bus-110027ec9f78941fcf8cc5f36b7055e17a206af6.tar.xz
add BUS_SEMAPHORES_ARE_SYNCHRONOUS + explain some syntax in doc/protocol
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to '')
-rw-r--r--src/bus.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/bus.c b/src/bus.c
index 614f7ad..5737fd7 100644
--- a/src/bus.c
+++ b/src/bus.c
@@ -623,22 +623,31 @@ fail:
int
bus_write(const bus_t *bus, const char *message, int flags /* TODO document in man page */)
{
- int state = 0, saved_errno;
+ int saved_errno;
+#ifndef BUS_SEMAPHORES_ARE_SYNCHRONOUS
+ int state = 0;
+#endif
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);
+#ifndef BUS_SEMAPHORES_ARE_SYNCHRONOUS
t(release_semaphore(bus, N, SEM_UNDO)); state++;
+#endif
t(write_semaphore(bus, Q, 0));
t(zero_semaphore(bus, S, 0));
+#ifndef BUS_SEMAPHORES_ARE_SYNCHRONOUS
t(acquire_semaphore(bus, N, SEM_UNDO)); state--;
+#endif
t(release_semaphore(bus, X, SEM_UNDO));
return 0;
fail:
saved_errno = errno;
+#ifndef BUS_SEMAPHORES_ARE_SYNCHRONOUS
if (state > 0)
acquire_semaphore(bus, N, SEM_UNDO);
+#endif
release_semaphore(bus, X, SEM_UNDO);
errno = saved_errno;
return -1;