class ConditionVariable
==========================
-.. doxygentypedef:: ConditionVariablePtr
+.. autodoxyclass:: simgrid::s4u::ConditionVariable
-.. doxygenclass:: simgrid::s4u::ConditionVariable
- :members:
- :protected-members:
- :undoc-members:
+Basic management
+----------------
+
+ .. tabs::
+
+ .. group-tab:: C++
+
+ .. code-block:: C
+
+ #include <simgrid/s4u/ConditionVariable.hpp>
+
+ .. doxygentypedef:: ConditionVariablePtr
+
+ .. autodoxymethod:: simgrid::s4u::ConditionVariable::create()
+
+ .. group-tab:: C
+
+ .. code-block:: C
+
+ #include <simgrid/cond.h>
+
+ .. doxygentypedef:: sg_cond_t
+ .. doxygenfunction:: sg_cond_init
+ .. doxygenfunction:: sg_cond_destroy
+
+Waiting and notifying
+---------------------
+
+ .. tabs::
+
+ .. group-tab:: C++
+
+ .. autodoxymethod:: simgrid::s4u::ConditionVariable::notify_all()
+ .. autodoxymethod:: simgrid::s4u::ConditionVariable::notify_one()
+ .. autodoxymethod:: simgrid::s4u::ConditionVariable::wait(MutexPtr lock)
+ .. autodoxymethod:: simgrid::s4u::ConditionVariable::wait(const std::unique_lock< Mutex > &lock)
+ .. autodoxymethod:: simgrid::s4u::ConditionVariable::wait(const std::unique_lock< Mutex > &lock, P pred)
+ .. autodoxymethod:: simgrid::s4u::ConditionVariable::wait_for(const std::unique_lock< Mutex > &lock, double duration)
+ .. autodoxymethod:: simgrid::s4u::ConditionVariable::wait_for(const std::unique_lock< Mutex > &lock, double duration, P pred)
+ .. autodoxymethod:: simgrid::s4u::ConditionVariable::wait_for(const std::unique_lock< Mutex > &lock, std::chrono::duration< Rep, Period > duration)
+ .. autodoxymethod:: simgrid::s4u::ConditionVariable::wait_for(const std::unique_lock< Mutex > &lock, std::chrono::duration< Rep, Period > duration, P pred)
+ .. autodoxymethod:: simgrid::s4u::ConditionVariable::wait_until(const std::unique_lock< Mutex > &lock, const SimulationTimePoint< Duration > &timeout_time)
+ .. autodoxymethod:: simgrid::s4u::ConditionVariable::wait_until(const std::unique_lock< Mutex > &lock, const SimulationTimePoint< Duration > &timeout_time, P pred)
+ .. autodoxymethod:: simgrid::s4u::ConditionVariable::wait_until(const std::unique_lock< Mutex > &lock, double timeout_time)
+ .. autodoxymethod:: simgrid::s4u::ConditionVariable::wait_until(const std::unique_lock< Mutex > &lock, double timeout_time, P pred)
+
+ .. group-tab:: C
+
+ .. doxygenfunction:: sg_cond_notify_all
+ .. doxygenfunction:: sg_cond_notify_one
+ .. doxygenfunction:: sg_cond_wait
+ .. doxygenfunction:: sg_cond_wait_for
.. _API_s4u_Mutex:
:protected-members:
:undoc-members:
-
-C API Reference
-***************
-
-==================
-Condition Variable
-==================
-
-See also the :ref:`C++ API <API_s4u_ConditionVariable>`.
-
-.. doxygenfunction:: sg_cond_init
-.. doxygenfunction:: sg_cond_notify_all
-.. doxygenfunction:: sg_cond_notify_one
-.. doxygenfunction:: sg_cond_wait
-.. doxygenfunction:: sg_cond_wait_for
-
Python API Reference
********************
.. automodule:: simgrid.this_actor
:members:
-===========
-Class Actor
-===========
-
-.. autoclass:: simgrid.Actor
- :members:
-
==========
Class Comm
==========
.. autoclass:: simgrid.Comm
:members:
-============
-Class Engine
-============
-
-.. autoclass:: simgrid.Engine
- :members:
-
==========
Class Exec
==========
/** @brief Blocks onto the given condition variable, but only for the given amount of time.
* @return 0 on success, 1 on timeout */
XBT_PUBLIC int sg_cond_wait_for(sg_cond_t cond, sg_mutex_t mutex, double delay);
-/** @brief Signals the given mutex variable */
+/** @brief Signals the given condition variable */
XBT_PUBLIC void sg_cond_notify_one(sg_cond_t cond);
-/** @brief Broadcasts the given mutex variable */
+/** @brief Broadcasts the given condition variable */
XBT_PUBLIC void sg_cond_notify_all(sg_cond_t cond);
-/** @brief Destroys the given mutex variable */
+/** @brief Destroys the given condition variable */
XBT_PUBLIC void sg_cond_destroy(const_sg_cond_t cond);
SG_END_DECL
namespace simgrid {
namespace s4u {
-/** @brief A condition variable
- * @ingroup s4u_api
- *
- * This is a drop-in replacement of `std::condition_variable` and should respect the same
- * semantic. But we currently use (only) double for both durations and
- * timestamp timeouts.
+/**
+ * @rst
+ * SimGrid's Condition Variables are meant to be drop-in replacements of
+ * `std::condition_variable <https://en.cppreference.com/w/cpp/thread/condition_variable>`_
+ * and should respect the same semantic.
+ * @endrst
*/
class XBT_PUBLIC ConditionVariable {
private:
kernel::activity::ConditionVariableImpl* const cond_;
public:
+#ifndef DOXYGEN
explicit ConditionVariable(kernel::activity::ConditionVariableImpl* cond) : cond_(cond) {}
-#ifndef DOXYGEN
ConditionVariable(ConditionVariable const&) = delete;
ConditionVariable& operator=(ConditionVariable const&) = delete;
friend XBT_PUBLIC void intrusive_ptr_release(const ConditionVariable* cond);
#endif
+ /** Create a new condition variable and return a smart pointer
+ *
+ * @rst
+ * You should only manipulate :cpp:type:`simgrid::s4u::ConditionVariablePtr`, as created by this function (see also :ref:`s4u_raii`).
+ * @endrst
+ */
static ConditionVariablePtr create();
// Wait functions without time: