summaryrefslogtreecommitdiff
path: root/src/lib/shm_rbuff.c
diff options
context:
space:
mode:
authordimitri staessens <[email protected]>2017-03-21 15:21:52 +0100
committerdimitri staessens <[email protected]>2017-03-21 15:21:52 +0100
commit0c8d8e419f7c9052d88bb9765bf43b01187977d0 (patch)
tree75f499a09782dd03b9d61e69166b659f9d09f698 /src/lib/shm_rbuff.c
parent55c8721cd2682a360c3eaeb6c51ef3455c320416 (diff)
downloadouroboros-0c8d8e419f7c9052d88bb9765bf43b01187977d0.tar.gz
ouroboros-0c8d8e419f7c9052d88bb9765bf43b01187977d0.zip
lib: Add queued SDUs when adding fd to flow_set
This solves some race conditions where packets arrive on a flow before it is added to a flow_set.
Diffstat (limited to 'src/lib/shm_rbuff.c')
-rw-r--r--src/lib/shm_rbuff.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/lib/shm_rbuff.c b/src/lib/shm_rbuff.c
index a206a019..b8db7c19 100644
--- a/src/lib/shm_rbuff.c
+++ b/src/lib/shm_rbuff.c
@@ -384,3 +384,23 @@ void shm_rbuff_fini(struct shm_rbuff * rb)
#endif
pthread_cleanup_pop(true);
}
+
+size_t shm_rbuff_queued(struct shm_rbuff * rb)
+{
+ size_t ret;
+
+ assert(rb);
+
+#ifdef __APPLE__
+ pthread_mutex_lock(rb->lock);
+#else
+ if (pthread_mutex_lock(rb->lock) == EOWNERDEAD)
+ pthread_mutex_consistent(rb->lock);
+#endif
+
+ ret = shm_rbuff_used(rb);
+
+ pthread_mutex_unlock(rb->lock);
+
+ return ret;
+}