diff options
author | dimitri staessens <[email protected]> | 2016-08-30 21:25:23 +0200 |
---|---|---|
committer | dimitri staessens <[email protected]> | 2016-08-30 21:25:23 +0200 |
commit | 1071824054828b9be36f50416f858c49c9acd701 (patch) | |
tree | 303d3d61717d4d3018b8025a9825ff799da01c08 /src/lib/shm_ap_rbuff.c | |
parent | 11ae1b5669356fbaf3405e77d36f517f8c1894cc (diff) | |
parent | 52db4952d80a10aae464274acdd7401267818b28 (diff) | |
download | ouroboros-1071824054828b9be36f50416f858c49c9acd701.tar.gz ouroboros-1071824054828b9be36f50416f858c49c9acd701.zip |
Merge branch 'be' of bitbucket.org:ouroboros-rina/ouroboros into be
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; |