Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
add specifying handling of timeout for MessImpl (none for now). Fix a bug on incomple...
[simgrid.git] / include / simgrid / s4u / Semaphore.hpp
index f0c8916..4c16f7a 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2006-2021. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2006-2023. 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. */
@@ -7,10 +7,8 @@
 #define SIMGRID_S4U_SEMAPHORE_HPP
 
 #include <simgrid/forward.h>
-#include <simgrid/simix.h>
 
-namespace simgrid {
-namespace s4u {
+namespace simgrid::s4u {
 
 /** @brief A classical semaphore, but blocking in the simulation world
  *
@@ -29,32 +27,35 @@ namespace s4u {
  *
  */
 class XBT_PUBLIC Semaphore {
-  kernel::activity::SemaphoreImpl* const pimpl_;
-  std::atomic_int_fast32_t refcount_{0};
+#ifndef DOXYGEN
+  friend kernel::activity::SemaphoreImpl;
+  friend XBT_PUBLIC void kernel::activity::intrusive_ptr_release(kernel::activity::SemaphoreImpl* sem);
+#endif
 
-  friend void intrusive_ptr_add_ref(Semaphore* sem);
-  friend void intrusive_ptr_release(Semaphore* sem);
+  kernel::activity::SemaphoreImpl* const pimpl_;
 
-public:
-  explicit Semaphore(unsigned int initial_capacity);
-  ~Semaphore();
+  friend XBT_PUBLIC void intrusive_ptr_add_ref(const Semaphore* sem);
+  friend XBT_PUBLIC void intrusive_ptr_release(const Semaphore* sem);
 
+  explicit Semaphore(kernel::activity::SemaphoreImpl* sem) : pimpl_(sem) {}
+  ~Semaphore() = default;
 #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 */
+public:
+  /** \static Constructs a new semaphore */
   static SemaphorePtr create(unsigned int initial_capacity);
 
   void acquire();
-  int acquire_timeout(double timeout);
+  /** Returns true if there was a timeout */
+  bool acquire_timeout(double timeout);
   void release();
   int get_capacity() const;
-  int would_block() const;
+  bool would_block() const;
 };
 
-} // namespace s4u
-} // namespace simgrid
+} // namespace simgrid::s4u
 
 #endif /* SIMGRID_S4U_SEMAPHORE_HPP */