diff options
author | Mattias Andrée <maandree@operamail.com> | 2015-04-25 19:59:32 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2015-04-25 19:59:32 +0200 |
commit | 76fdcece687af8d82e7b5a6c065988ab80c914cb (patch) | |
tree | 361310df8206e56a60c3e9b891787d0d137ab18b /src/bus.c | |
parent | patch memory leak (diff) | |
download | bus-76fdcece687af8d82e7b5a6c065988ab80c914cb.tar.gz bus-76fdcece687af8d82e7b5a6c065988ab80c914cb.tar.bz2 bus-76fdcece687af8d82e7b5a6c065988ab80c914cb.tar.xz |
bus_read invokes callback with null message to notify that it is listening on the bus
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to '')
-rw-r--r-- | src/bus.c | 11 |
1 files changed, 11 insertions, 0 deletions
@@ -629,6 +629,12 @@ fail: * * 0: stop listening * * 1: continue listening * * -1: an error has occurred + * However, the function [`bus_read`] will invoke + * `callback` with `message` one time directly after + * it has started listening on the bus. This is to + * the the program now it can safely continue with + * any action that requires that the programs is + * listening on the port. * @return 0 on success, -1 on error */ int @@ -636,6 +642,11 @@ bus_read(const bus_t *bus, int (*callback)(const char *message, void *user_data) { int r; t(release_semaphore(bus, S, SEM_UNDO)); + t(r = callback(NULL, user_data)); + if (!r) { + t(acquire_semaphore(bus, S, SEM_UNDO)); + return 0; + } for (;;) { t(release_semaphore(bus, Q, 0)); t(zero_semaphore(bus, Q)); |