summaryrefslogtreecommitdiffstats
path: root/runtime/lib_ksi_queue.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 16:28:20 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 16:28:20 +0000
commitdcc721a95bef6f0d8e6d8775b8efe33e5aecd562 (patch)
tree66a2774cd0ee294d019efd71d2544c70f42b2842 /runtime/lib_ksi_queue.h
parentInitial commit. (diff)
downloadrsyslog-dcc721a95bef6f0d8e6d8775b8efe33e5aecd562.tar.xz
rsyslog-dcc721a95bef6f0d8e6d8775b8efe33e5aecd562.zip
Adding upstream version 8.2402.0.upstream/8.2402.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--runtime/lib_ksi_queue.h53
1 files changed, 53 insertions, 0 deletions
diff --git a/runtime/lib_ksi_queue.h b/runtime/lib_ksi_queue.h
new file mode 100644
index 0000000..20ad680
--- /dev/null
+++ b/runtime/lib_ksi_queue.h
@@ -0,0 +1,53 @@
+#ifndef INCLUDED_LIBRSKSI_QUEUE_H
+#define INCLUDED_LIBRSKSI_QUEUE_H
+
+#include <stdint.h>
+#include <stdbool.h>
+#include <pthread.h>
+
+#define RB_GROW_FACTOR 2
+
+typedef struct RingBuffer_st {
+ void **buffer;
+ size_t size;
+ size_t count;
+ size_t head;
+ size_t tail;
+} RingBuffer;
+
+RingBuffer* RingBuffer_new(size_t size);
+void RingBuffer_free(RingBuffer* this);
+bool RingBuffer_pushBack(RingBuffer* this, void* item);
+bool RingBuffer_popFront(RingBuffer* this, void** item);
+bool RingBuffer_peekFront(RingBuffer* this, void** item);
+bool RingBuffer_getItem(RingBuffer* this, size_t index, void** item);
+size_t RingBuffer_count(RingBuffer* this);
+
+typedef struct ProtectedQueue_st {
+ bool bStop;
+ RingBuffer *workItems;
+ pthread_mutex_t mutex;
+ pthread_cond_t condition;
+} ProtectedQueue;
+
+ProtectedQueue* ProtectedQueue_new(size_t queueSize);
+void ProtectedQueue_free(ProtectedQueue* this);
+void ProtectedQueue_stop(ProtectedQueue* this);
+bool ProtectedQueue_addItem(ProtectedQueue* this, void* item);
+bool ProtectedQueue_peekFront(ProtectedQueue* this, void** item);
+bool ProtectedQueue_popFront(ProtectedQueue* this, void** item);
+size_t ProtectedQueue_popFrontBatch(ProtectedQueue* this, void** items, size_t bufSize);
+int ProtectedQueue_waitForItem(ProtectedQueue* this, void** item, uint64_t timeout);
+size_t ProtectedQueue_count(ProtectedQueue* this);
+bool ProtectedQueue_getItem(ProtectedQueue* this, size_t index, void** item);
+
+typedef struct WorkerThreadContext_st {
+ bool (*workerFunc)(void*);
+ bool (*timeoutFunc)(void);
+ ProtectedQueue* queue;
+ unsigned timeout;
+} WorkerThreadContext;
+
+void *worker_thread_main(void *arg);
+
+#endif //INCLUDED_LIBRSKSI_QUEUE_H