diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2023-05-08 16:27:08 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2023-05-08 16:27:08 +0000 |
commit | 81581f9719bc56f01d5aa08952671d65fda9867a (patch) | |
tree | 0f5c6b6138bf169c23c9d24b1fc0a3521385cb18 /ml/Queue.h | |
parent | Releasing debian version 1.38.1-1. (diff) | |
download | netdata-81581f9719bc56f01d5aa08952671d65fda9867a.tar.xz netdata-81581f9719bc56f01d5aa08952671d65fda9867a.zip |
Merging upstream version 1.39.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'ml/Queue.h')
-rw-r--r-- | ml/Queue.h | 66 |
1 files changed, 0 insertions, 66 deletions
diff --git a/ml/Queue.h b/ml/Queue.h deleted file mode 100644 index 37a74bd07..000000000 --- a/ml/Queue.h +++ /dev/null @@ -1,66 +0,0 @@ -#ifndef QUEUE_H -#define QUEUE_H - -#include "ml-private.h" -#include "Mutex.h" -#include <queue> -#include <mutex> -#include <condition_variable> - -template<typename T> -class Queue { -public: - Queue(void) : Q(), M() { - pthread_cond_init(&CV, nullptr); - Exit = false; - } - - ~Queue() { - pthread_cond_destroy(&CV); - } - - void push(T t) { - std::lock_guard<Mutex> L(M); - - Q.push(t); - pthread_cond_signal(&CV); - } - - std::pair<T, size_t> pop(void) { - std::lock_guard<Mutex> L(M); - - while (Q.empty()) { - pthread_cond_wait(&CV, M.inner()); - - if (Exit) { - // This should happen only when we are destroying a host. - // Callers should use a flag dedicated to checking if we - // are about to delete the host or exit the agent. The original - // implementation would call pthread_exit which would cause - // the queue's mutex to be destroyed twice (and fail on the - // 2nd time) - return { T(), 0 }; - } - } - - T V = Q.front(); - size_t Size = Q.size(); - Q.pop(); - - return { V, Size }; - } - - void signal() { - std::lock_guard<Mutex> L(M); - Exit = true; - pthread_cond_signal(&CV); - } - -private: - std::queue<T> Q; - Mutex M; - pthread_cond_t CV; - std::atomic<bool> Exit; -}; - -#endif /* QUEUE_H */ |