Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
document Mutex and Semaphores in the new way
authorMartin Quinson <martin.quinson@ens-rennes.fr>
Sat, 4 Jan 2020 18:15:53 +0000 (19:15 +0100)
committerMartin Quinson <martin.quinson@ens-rennes.fr>
Sat, 4 Jan 2020 18:18:57 +0000 (19:18 +0100)
docs/find-missing.py
docs/source/app_s4u.rst
include/simgrid/s4u/Mutex.hpp
include/simgrid/s4u/Semaphore.hpp

index 4546b37..2043dcc 100755 (executable)
@@ -42,8 +42,18 @@ xml_files = [
     'build/xml/classsimgrid_1_1s4u_1_1Semaphore.xml',
     'build/xml/classsimgrid_1_1s4u_1_1VirtualMachine.xml',
     'build/xml/actor_8h.xml',
+    'build/xml/barrier_8h.xml',
+    'build/xml/cond_8h.xml',
     'build/xml/engine_8h.xml',
-    'build/xml/vm_8h.xml'
+    'build/xml/forward_8h.xml',
+    'build/xml/host_8h.xml',
+    'build/xml/link_8h.xml',
+    'build/xml/mailbox_8h.xml',
+    'build/xml/msg_8h.xml',
+    'build/xml/mutex_8h.xml',
+    'build/xml/semaphore_8h.xml',
+    'build/xml/vm_8h.xml',
+    'build/xml/zone_8h.xml'
 ]
 
 python_modules = [
index fac7ad0..2944e11 100644 (file)
@@ -931,6 +931,62 @@ Activities lifecycle
 Synchronization Objects
 =======================
 
+.. _API_s4u_Mutex:
+
+==============
+⁣  Mutex
+==============
+
+.. autodoxyclass:: simgrid::s4u::Mutex
+
+Basic management
+----------------
+
+   .. tabs::
+
+      .. group-tab:: C++
+
+         .. code-block:: C++
+
+            #include <simgrid/s4u/Mutex.hpp>
+
+         .. doxygentypedef:: MutexPtr
+
+         .. autodoxymethod:: simgrid::s4u::Mutex::Mutex(kernel::activity::MutexImpl *mutex)
+         .. autodoxymethod:: simgrid::s4u::Mutex::create()
+         .. autodoxymethod:: simgrid::s4u::Mutex::~Mutex()
+
+      .. group-tab:: C
+
+         .. code-block:: C
+
+            #include <simgrid/mutex.h>
+
+         .. doxygentypedef:: sg_mutex_t
+         .. cpp:type:: const s4u_Mutex* const_sg_mutex_t
+
+            Constant pointer to a SimGrid mutex object.
+
+         .. autodoxymethod:: sg_mutex_init()
+         .. autodoxymethod:: sg_mutex_destroy(const_sg_mutex_t mutex)
+
+Locking
+-------
+
+   .. tabs::
+
+      .. group-tab:: C++
+
+         .. autodoxymethod:: simgrid::s4u::Mutex::lock()
+         .. autodoxymethod:: simgrid::s4u::Mutex::try_lock()
+         .. autodoxymethod:: simgrid::s4u::Mutex::unlock()
+
+      .. group-tab:: C
+
+         .. autodoxymethod:: sg_mutex_lock(sg_mutex_t mutex)
+         .. autodoxymethod:: sg_mutex_try_lock(sg_mutex_t mutex)
+         .. autodoxymethod:: sg_mutex_unlock(sg_mutex_t mutex)
+
 .. _API_s4u_Barrier:
 
 ================
@@ -1030,31 +1086,65 @@ Waiting and notifying
          .. doxygenfunction:: sg_cond_wait
          .. doxygenfunction:: sg_cond_wait_for
 
-.. _API_s4u_Mutex:
+.. _API_s4u_Semaphore:
 
-==============
-⁣  class Mutex
-==============
+==================
+⁣  Semaphore
+==================
 
-.. doxygentypedef:: MutexPtr
+.. autodoxyclass:: simgrid::s4u::Semaphore
 
-.. doxygenclass:: simgrid::s4u::Mutex
-   :members:
-   :protected-members:
-   :undoc-members:
 
-.. _API_s4u_Semaphore:
+Basic management
+----------------
 
-==================
-⁣  class Semaphore
-==================
+   .. tabs::
 
-.. doxygentypedef:: SemaphorePtr
+      .. group-tab:: C++
 
-.. doxygenclass:: simgrid::s4u::Semaphore
-   :members:
-   :protected-members:
-   :undoc-members:
+         .. code-block:: C++
+
+            #include <simgrid/s4u/Semaphore.hpp>
+
+         .. doxygentypedef:: SemaphorePtr
+         .. autodoxymethod:: simgrid::s4u::Semaphore::Semaphore(unsigned int initial_capacity)
+         .. autodoxymethod:: simgrid::s4u::Semaphore::~Semaphore()
+         .. autodoxymethod:: simgrid::s4u::Semaphore::create(unsigned int initial_capacity)
+
+      .. group-tab:: C
+
+         .. code-block:: C
+
+            #include <simgrid/semaphore.h>
+
+         .. doxygentypedef:: sg_sem_t
+         .. cpp:type:: const s4u_Semaphore* const_sg_sem_t
+
+            Constant pointer to a SimGrid semaphore object.
+
+         .. autodoxymethod:: sg_sem_init(int initial_value)
+         .. autodoxymethod:: sg_sem_destroy(const_sg_sem_t sem)
+
+Locking
+-------
+
+   .. tabs::
+
+      .. group-tab:: C++
+
+         .. autodoxymethod:: simgrid::s4u::Semaphore::acquire()
+         .. autodoxymethod:: simgrid::s4u::Semaphore::acquire_timeout(double timeout)
+         .. autodoxymethod:: simgrid::s4u::Semaphore::get_capacity()
+         .. autodoxymethod:: simgrid::s4u::Semaphore::release()
+         .. autodoxymethod:: simgrid::s4u::Semaphore::would_block()
+
+      .. group-tab:: C
+
+         .. autodoxymethod:: sg_sem_acquire(sg_sem_t sem)
+         .. autodoxymethod:: sg_sem_acquire_timeout(sg_sem_t sem, double timeout)
+         .. autodoxymethod:: sg_sem_get_capacity(sg_sem_t sem)
+         .. autodoxymethod:: sg_sem_release(sg_sem_t sem)
+         .. autodoxymethod:: sg_sem_would_block(sg_sem_t sem)
 
 Python API Reference
 ********************
index e28f58a..8cf22d6 100644 (file)
 namespace simgrid {
 namespace s4u {
 
-/** @brief A classical mutex, but blocking in the simulation world
- *  @ingroup s4u_api
+/** @brief A classical mutex, but blocking in the simulation world.
  *
+ * @rst
  * It is strictly impossible to use a real mutex, such as
- * <a href="http://en.cppreference.com/w/cpp/thread/mutex">std::mutex</a>
- * or <a href="http://pubs.opengroup.org/onlinepubs/007908775/xsh/pthread_mutex_lock.html">pthread_mutex_t</a>,
+ * `std::mutex <http://en.cppreference.com/w/cpp/thread/mutex>`_
+ * or `pthread_mutex_t <http://pubs.opengroup.org/onlinepubs/007908775/xsh/pthread_mutex_lock.html>`_,
  * because it would block the whole simulation.
- * Instead, you should use the present class, that is a drop-in replacement of
- * <a href="http://en.cppreference.com/w/cpp/thread/mutex">std::mutex</a>.
+ * Instead, you should use the present class, that is a drop-in replacement of these mechanisms.
  *
- * @beginrst
- * As for any S4U object, Mutexes are using the :ref:`RAII idiom <s4u_raii>` for memory management.
+ * An example is available in Section :ref:`s4u_ex_IPC`.
+ *
+ * As for any S4U object, you can use the :ref:`RAII idiom <s4u_raii>` for memory management of Mutexes.
  * Use :cpp:func:`create() <simgrid::s4u::Mutex::create()>` to get a :cpp:type:`simgrid::s4u::MutexPtr` to a newly
  * created mutex, and only manipulate :cpp:type:`simgrid::s4u::MutexPtr`.
  * @endrst
- *
  */
 class XBT_PUBLIC Mutex {
   friend ConditionVariable;
@@ -39,9 +38,9 @@ class XBT_PUBLIC Mutex {
   friend XBT_PUBLIC void intrusive_ptr_release(const Mutex* mutex);
 
 public:
-#ifndef DOXYGEN
   explicit Mutex(kernel::activity::MutexImpl* mutex) : pimpl_(mutex) {}
   ~Mutex();
+#ifndef DOXYGEN
   Mutex(Mutex const&) = delete;            // No copy constructor; Use MutexPtr instead
   Mutex& operator=(Mutex const&) = delete; // No direct assignment either. Use MutexPtr instead
 #endif
index 50a3c36..602553d 100644 (file)
@@ -13,16 +13,19 @@ namespace simgrid {
 namespace s4u {
 
 /** @brief A classical semaphore, but blocking in the simulation world
- *  @ingroup s4u_api
  *
+ * @rst
  * It is strictly impossible to use a real semaphore, such as
- * <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/sem_init.html">sem_init</a>,
+ * `sem_init <http://pubs.opengroup.org/onlinepubs/9699919799/functions/sem_init.html>`_,
  * because it would block the whole simulation.
  * Instead, you should use the present class, that offers a very similar interface.
  *
- * As for any S4U object, Semaphores are using the @ref s4u_raii "RAII idiom" for memory management.
- * Use #create() to get a simgrid::s4u::SemaphorePtr to a newly created semaphore
- * and only manipulate simgrid::s4u::SemaphorePtr.
+ * An example is available in Section :ref:`s4u_ex_IPC`.
+ *
+ * As for any S4U object, you can use the :ref:`RAII idiom <s4u_raii>` for memory management of semaphores.
+ * Use :cpp:func:`create() <simgrid::s4u::Mutex::create()>` to get a :cpp:type:`simgrid::s4u::SemaphorePtr` to a newly
+ * created semaphore, that will get automatically freed when the variable goes out of scope.
+ * @endrst
  *
  */
 class XBT_PUBLIC Semaphore {
@@ -36,11 +39,10 @@ public:
   explicit Semaphore(unsigned int initial_capacity);
   ~Semaphore();
 
-  // No copy:
-  /** You cannot create a new semaphore by copying an existing one. Use SemaphorePtr instead */
-  Semaphore(Semaphore const&) = delete;
-  /** You cannot create a new semaphore by value assignment either. Use SemaphorePtr instead */
-  Semaphore& operator=(Semaphore const&) = delete;
+#ifndef DOXYGEN
+  Semaphore(Semaphore const&) = delete;            // No copy constructor. Use SemaphorePtr instead
+  Semaphore& operator=(Semaphore const&) = delete; // No direct assignment either. Use SemaphorePtr instead
+#endif
 
   /** Constructs a new semaphore */
   static SemaphorePtr create(unsigned int initial_capacity);