X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/b4a423f5085cf79b6c539eae25549bb66e8e3033..768866d55ef9d86790049e605bc2f6c62f59199c:/src/bindings/python/simgrid_python.cpp diff --git a/src/bindings/python/simgrid_python.cpp b/src/bindings/python/simgrid_python.cpp index eded4f1cd5..c7762da72c 100644 --- a/src/bindings/python/simgrid_python.cpp +++ b/src/bindings/python/simgrid_python.cpp @@ -36,6 +36,7 @@ #include #include #include +#include #include #include @@ -54,6 +55,8 @@ using simgrid::s4u::Link; using simgrid::s4u::Mailbox; using simgrid::s4u::Mutex; using simgrid::s4u::MutexPtr; +using simgrid::s4u::Semaphore; +using simgrid::s4u::SemaphorePtr; XBT_LOG_NEW_DEFAULT_CATEGORY(python, "python"); @@ -716,9 +719,8 @@ PYBIND11_MODULE(simgrid, m) py::return_value_policy::reference_internal, py::call_guard(), "Start the comm, and ignore its result. It can be completely forgotten after that.") - // use py::overload_cast for wait_all/wait_any, until the overload marked XBT_ATTRIB_DEPRECATED_v332 is removed .def_static( - "wait_all", py::overload_cast&>(&simgrid::s4u::Comm::wait_all), + "wait_all", &simgrid::s4u::Comm::wait_all, py::arg("comms"), py::call_guard(), "Block until the completion of all communications in the list.") @@ -728,13 +730,13 @@ PYBIND11_MODULE(simgrid, m) "Block until the completion of all communications in the list, or raises TimeoutException after " "the specified timeout.") .def_static( - "wait_any", py::overload_cast&>(&simgrid::s4u::Comm::wait_any), + "wait_any", &simgrid::s4u::Comm::wait_any, py::arg("comms"), py::call_guard(), "Block until the completion of any communication in the list and return the index of the terminated one.") .def_static( "wait_any_for", - py::overload_cast&, double>(&simgrid::s4u::Comm::wait_any_for), + &simgrid::s4u::Comm::wait_any_for, py::arg("comms"), py::arg("timeout"), py::call_guard(), "Block until the completion of any communication in the list and return the index of the terminated " @@ -780,15 +782,37 @@ PYBIND11_MODULE(simgrid, m) .def("wait", &simgrid::s4u::Exec::wait, py::call_guard(), "Block until the completion of that execution."); + /* Class Semaphore */ + py::class_(m, "Semaphore", + "A classical semaphore, but blocking in the simulation world. See the C++ " + "documentation for details.") + .def(py::init<>(&Semaphore::create), py::call_guard(), py::arg("capacity"), + "Semaphore constructor.") + .def("acquire", &Semaphore::acquire, py::call_guard(), + "Acquire on the semaphore object with no timeout. Blocks until the semaphore is acquired.") + .def("acquire_timeout", &Semaphore::acquire_timeout, py::call_guard(), py::arg("timeout"), + "Acquire on the semaphore object with no timeout. Blocks until the semaphore is acquired or return " + "true if it has not been acquired after the specified timeout.") + .def("release", &Semaphore::release, py::call_guard(), + "Release the semaphore.") + .def_property_readonly("capacity", &Semaphore::get_capacity, py::call_guard(), + "Get the semaphore capacity.") + .def_property_readonly("would_block", &Semaphore::would_block, py::call_guard(), + "Check whether trying to acquire the semaphore would block (in other word, checks whether " + "this semaphore has capacity).") + // Allow semaphores to be automatically acquired/released with a context manager: `with semaphore: ...` + .def("__enter__", [](Semaphore* self){ self->acquire(); }, py::call_guard()) + .def("__exit__", [](Semaphore* self){ self->release(); }, py::call_guard()); + /* Class Mutex */ py::class_(m, "Mutex", "A classical mutex, but blocking in the simulation world." "See the C++ documentation for details.") - .def(py::init<>(&Mutex::create)) + .def(py::init<>(&Mutex::create), py::call_guard(), "Mutex constructor.") .def("lock", &Mutex::lock, py::call_guard(), "Block until the mutex is acquired.") .def("try_lock", &Mutex::try_lock, py::call_guard(), "Try to acquire the mutex. Return true if the mutex was acquired, false otherwise.") - .def("unlock", &Mutex::unlock, py::call_guard(), "Release the mutex") + .def("unlock", &Mutex::unlock, py::call_guard(), "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()) .def("__exit__", [](Mutex* self, const py::object&, const py::object&, const py::object&) { self->unlock(); }, @@ -797,10 +821,11 @@ PYBIND11_MODULE(simgrid, m) /* Class Barrier */ py::class_(m, "Barrier", "A classical barrier, but blocking in the simulation world.") - .def(py::init<>(&Barrier::create), py::call_guard(), py::arg("expected_actors")) + .def(py::init<>(&Barrier::create), py::call_guard(), py::arg("expected_actors"), + "Barrier constructor.") .def("wait", &Barrier::wait, py::call_guard(), "Blocks into the barrier. Every waiting actors will be unlocked once the expected amount of actors reaches " - "the barrier"); + "the barrier."); /* Class Actor */ py::class_(m, "Actor",