diff options
author | dimitri staessens <dimitri.staessens@ugent.be> | 2017-10-07 10:06:22 +0200 |
---|---|---|
committer | dimitri staessens <dimitri.staessens@ugent.be> | 2017-10-07 10:11:00 +0200 |
commit | 15ccd8ac0d1a7bfab2db3929200f3926c1e05db2 (patch) | |
tree | 2a338353303e270ff0f670e3e4c24fc4d4e8fc07 /src/ipcpd/normal | |
parent | 7dcacfbc94386e155650aaaa1a8f56cfb6fc53f9 (diff) | |
download | ouroboros-15ccd8ac0d1a7bfab2db3929200f3926c1e05db2.tar.gz ouroboros-15ccd8ac0d1a7bfab2db3929200f3926c1e05db2.zip |
ipcpd: Handle cancellation while writing LSAs
This adds a cleanup handler to ensure the lock is released in the
event that the thread is cancelled during a write. An alternative
solution could be to make the flow write in a non-blocking way (only
the blocking write contains an execution path that has a cancellation
point).
Fixes #55
Diffstat (limited to 'src/ipcpd/normal')
-rw-r--r-- | src/ipcpd/normal/pol/link_state.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/src/ipcpd/normal/pol/link_state.c b/src/ipcpd/normal/pol/link_state.c index f3af2771..9c41dba3 100644 --- a/src/ipcpd/normal/pol/link_state.c +++ b/src/ipcpd/normal/pol/link_state.c @@ -534,13 +534,16 @@ static void forward_lsm(uint8_t * buf, pthread_rwlock_rdlock(&ls.db_lock); + pthread_cleanup_push((void (*))(void *) pthread_rwlock_unlock, + &ls.db_lock); + list_for_each(p, &ls.nbs) { struct nb * nb = list_entry(p, struct nb, next); if (nb->type == NB_MGMT && nb->fd != in_fd) flow_write(nb->fd, buf, len); } - pthread_rwlock_unlock(&ls.db_lock); + pthread_cleanup_pop(true); } static void * lsreader(void * o) |