summaryrefslogtreecommitdiffstats
path: root/ml/Mutex.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2023-02-06 16:11:30 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2023-02-06 16:11:30 +0000
commitaa2fe8ccbfcb117efa207d10229eeeac5d0f97c7 (patch)
tree941cbdd387b41c1a81587c20a6df9f0e5e0ff7ab /ml/Mutex.h
parentAdding upstream version 1.37.1. (diff)
downloadnetdata-upstream/1.38.0.tar.xz
netdata-upstream/1.38.0.zip
Adding upstream version 1.38.0.upstream/1.38.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--ml/Mutex.h36
1 files changed, 36 insertions, 0 deletions
diff --git a/ml/Mutex.h b/ml/Mutex.h
new file mode 100644
index 000000000..fcdb75313
--- /dev/null
+++ b/ml/Mutex.h
@@ -0,0 +1,36 @@
+#ifndef ML_MUTEX_H
+#define ML_MUTEX_H
+
+#include "ml-private.h"
+
+class Mutex {
+public:
+ Mutex() {
+ netdata_mutex_init(&M);
+ }
+
+ void lock() {
+ netdata_mutex_lock(&M);
+ }
+
+ void unlock() {
+ netdata_mutex_unlock(&M);
+ }
+
+ bool try_lock() {
+ return netdata_mutex_trylock(&M) == 0;
+ }
+
+ netdata_mutex_t *inner() {
+ return &M;
+ }
+
+ ~Mutex() {
+ netdata_mutex_destroy(&M);
+ }
+
+private:
+ netdata_mutex_t M;
+};
+
+#endif /* ML_MUTEX_H */