Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix misc sonar issues.
[simgrid.git] / src / bindings / python / simgrid_python.cpp
index 3603e0d..eded4f1 100644 (file)
@@ -26,6 +26,7 @@
 #include "simgrid/kernel/routing/NetPoint.hpp"
 #include <simgrid/Exception.hpp>
 #include <simgrid/s4u/Actor.hpp>
+#include <simgrid/s4u/Barrier.hpp>
 #include <simgrid/s4u/Comm.hpp>
 #include <simgrid/s4u/Disk.hpp>
 #include <simgrid/s4u/Engine.hpp>
@@ -45,6 +46,8 @@
 namespace py = pybind11;
 using simgrid::s4u::Actor;
 using simgrid::s4u::ActorPtr;
+using simgrid::s4u::Barrier;
+using simgrid::s4u::BarrierPtr;
 using simgrid::s4u::Engine;
 using simgrid::s4u::Host;
 using simgrid::s4u::Link;
@@ -788,9 +791,17 @@ PYBIND11_MODULE(simgrid, m)
       .def("unlock", &Mutex::unlock, py::call_guard<py::gil_scoped_release>(), "Release the mutex")
       // Allow mutexes to be automatically acquired/released with a context manager: `with mutex: ...`
       .def("__enter__", [](Mutex* self){ self->lock(); }, py::call_guard<py::gil_scoped_release>())
-      .def("__exit__", [](Mutex* self, py::object&, py::object&, py::object&){ self->unlock(); },
+      .def("__exit__", [](Mutex* self, const py::object&, const py::object&, const py::object&) { self->unlock(); },
           py::call_guard<py::gil_scoped_release>());
 
+  /* Class Barrier */
+  py::class_<Barrier, BarrierPtr>(m, "Barrier",
+                                  "A classical barrier, but blocking in the simulation world.")
+      .def(py::init<>(&Barrier::create), py::call_guard<py::gil_scoped_release>(), py::arg("expected_actors"))
+      .def("wait", &Barrier::wait, py::call_guard<py::gil_scoped_release>(),
+           "Blocks into the barrier. Every waiting actors will be unlocked once the expected amount of actors reaches "
+           "the barrier");
+
   /* Class Actor */
   py::class_<simgrid::s4u::Actor, ActorPtr>(m, "Actor",
                                             "An actor is an independent stream of execution in your distributed "