diff options
author | Sander Vrijders <sander.vrijders@intec.ugent.be> | 2016-08-30 14:28:40 +0200 |
---|---|---|
committer | Sander Vrijders <sander.vrijders@intec.ugent.be> | 2016-08-30 14:28:40 +0200 |
commit | 52db4952d80a10aae464274acdd7401267818b28 (patch) | |
tree | 303d3d61717d4d3018b8025a9825ff799da01c08 /src/lib/shm_ap_rbuff.c | |
parent | caeefb4d96331d24b38e845c99d0517913a71671 (diff) | |
parent | 2cc89f6da424ab503af563e0cc92dda43b8f8432 (diff) | |
download | ouroboros-52db4952d80a10aae464274acdd7401267818b28.tar.gz ouroboros-52db4952d80a10aae464274acdd7401267818b28.zip |
Merged in dstaesse/ouroboros/be-refactor-rdrbuff (pull request #229)
lib: Refactor shm_du_map to shm_rdrbuff
Diffstat (limited to 'src/lib/shm_ap_rbuff.c')
-rw-r--r-- | src/lib/shm_ap_rbuff.c | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/src/lib/shm_ap_rbuff.c b/src/lib/shm_ap_rbuff.c index 4ca29636..f21b1e86 100644 --- a/src/lib/shm_ap_rbuff.c +++ b/src/lib/shm_ap_rbuff.c @@ -285,8 +285,32 @@ int shm_ap_rbuff_write(struct shm_ap_rbuff * rb, struct rb_entry * e) return 0; } -int shm_ap_rbuff_peek(struct shm_ap_rbuff * rb, - const struct timespec * timeout) +int shm_ap_rbuff_peek_idx(struct shm_ap_rbuff * rb) +{ + int ret = 0; + + if (rb == NULL) + return -EINVAL; + + if (pthread_mutex_lock(rb->lock) == EOWNERDEAD) { + LOG_DBG("Recovering dead mutex."); + pthread_mutex_consistent(rb->lock); + } + + if (shm_rbuff_empty(rb)) { + pthread_mutex_unlock(rb->lock); + return -1; + } + + ret = (rb->shm_base + *rb->ptr_tail)->index; + + pthread_mutex_unlock(rb->lock); + + return ret; +} + +int shm_ap_rbuff_peek_b(struct shm_ap_rbuff * rb, + const struct timespec * timeout) { struct timespec abstime; int ret = 0; |