Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Attempt to move msg_bar_t to S4U
[simgrid.git] / include / simgrid / s4u / Barrier.hpp
diff --git a/include/simgrid/s4u/Barrier.hpp b/include/simgrid/s4u/Barrier.hpp
new file mode 100644 (file)
index 0000000..b3c6e65
--- /dev/null
@@ -0,0 +1,36 @@
+/* Copyright (c) 2018. The SimGrid Team. All rights reserved.          */
+
+/* This program is free software; you can redistribute it and/or modify it
+ * under the terms of the license (GNU LGPL) which comes with this package. */
+
+#ifndef SIMGRID_S4U_BARRIERHPP
+#define SIMGRID_S4U_BARRIER_HPP
+
+#include "simgrid/s4u/ConditionVariable.hpp"
+#include <simgrid/chrono.hpp>
+#include <simgrid/s4u/Mutex.hpp>
+
+#include <future>
+
+namespace simgrid {
+namespace s4u {
+
+class XBT_PUBLIC Barrier {
+private:
+  MutexPtr mutex_;
+  ConditionVariablePtr cond_;
+  unsigned int expected_processes_;
+  unsigned int arrived_processes_ = 0;
+
+public:
+  explicit Barrier(unsigned int count);
+  ~Barrier()              = default;
+  Barrier(Barrier const&) = delete;
+  Barrier& operator=(Barrier const&) = delete;
+
+  int wait();
+};
+}
+} // namespace simgrid::s4u
+
+#endif