summaryrefslogtreecommitdiffstats
path: root/libglusterfs/src/bounded-queue.h
diff options
context:
space:
mode:
authorKevin Vigor <kvigor@fb.com>2016-08-18 08:14:02 -0700
committerShreyas Siravara <sshreyas@fb.com>2017-09-03 15:45:26 +0000
commit493746d10f0a8dcc270fae0a43d5e77beb7a2bd5 (patch)
treea0dc9ce92b3d6d7180615af1ceb8c89a9699b073 /libglusterfs/src/bounded-queue.h
parent26776c3d21e70806237dcc02ac4bd78883416718 (diff)
Add a bounded queue implementation.
Summary: - This queue will be used to hold the set of directory crawl / file migrate operations in the multi-threaded rebalance. - This is a port of D3712047 to 3.8 Test Plan: Unit test included. Reviewed By: sshreyas Change-Id: I25497a64beba744430807b3512eaee5d90f089c4 Reviewed-on: https://review.gluster.org/18197 Reviewed-by: Shreyas Siravara <sshreyas@fb.com> CentOS-regression: Gluster Build System <jenkins@build.gluster.org> Smoke: Gluster Build System <jenkins@build.gluster.org>
Diffstat (limited to 'libglusterfs/src/bounded-queue.h')
-rw-r--r--libglusterfs/src/bounded-queue.h32
1 files changed, 32 insertions, 0 deletions
diff --git a/libglusterfs/src/bounded-queue.h b/libglusterfs/src/bounded-queue.h
new file mode 100644
index 00000000000..9de62ab5447
--- /dev/null
+++ b/libglusterfs/src/bounded-queue.h
@@ -0,0 +1,32 @@
+#pragma once
+
+#include <stdint.h>
+#include <pthread.h>
+
+struct queue_entry {
+ struct queue_entry *next;
+};
+
+/// @brief a FIFO queue that holds a limited number of elements.
+///
+/// The queue is blocking, i.e. any attempt to push to a full
+/// queue or read from an empty one will block indefinitely.
+///
+/// When tearing down the queue, blocked processes may be
+/// unblocked by calling bounded_queue_kill(), which will
+/// cause all blocked processes to return with error status.
+struct bounded_queue {
+ struct queue_entry *head;
+ struct queue_entry *tail;
+ uint32_t count;
+ uint32_t limit;
+ int killed;
+ pthread_mutex_t mutex;
+ pthread_cond_t cond;
+};
+
+int bounded_queue_init (struct bounded_queue *q, uint32_t limit);
+int bounded_queue_push (struct bounded_queue *q, struct queue_entry *e);
+struct queue_entry *bounded_queue_pop (struct bounded_queue *q);
+int bounded_queue_kill (struct bounded_queue *q);
+