aboutsummaryrefslogtreecommitdiff
path: root/zencore/include
diff options
context:
space:
mode:
Diffstat (limited to 'zencore/include')
-rw-r--r--zencore/include/zencore/thread.h35
1 files changed, 33 insertions, 2 deletions
diff --git a/zencore/include/zencore/thread.h b/zencore/include/zencore/thread.h
index 16d0e9dee..3c1821a62 100644
--- a/zencore/include/zencore/thread.h
+++ b/zencore/include/zencore/thread.h
@@ -4,9 +4,9 @@
#include "zencore.h"
-#include <shared_mutex>
-
+#include <atomic>
#include <filesystem>
+#include <shared_mutex>
#include <string_view>
#include <vector>
@@ -144,6 +144,37 @@ private:
void* m_MutexHandle = nullptr;
};
+/**
+ * Downward counter of type std::ptrdiff_t which can be used to synchronize threads
+ */
+class Latch
+{
+public:
+ Latch(std::ptrdiff_t Count) : Counter(Count) {}
+
+ void CountDown()
+ {
+ std::ptrdiff_t Old = Counter.fetch_sub(1);
+ if (Old == 1)
+ {
+ Complete.Set();
+ }
+ }
+
+ void Wait()
+ {
+ std::ptrdiff_t Old = Counter.load();
+ if (Old != 0)
+ {
+ Complete.Wait();
+ }
+ }
+
+private:
+ std::atomic_ptrdiff_t Counter;
+ Event Complete;
+};
+
/** Basic process abstraction
*/
class ProcessHandle