Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
A few Sonar smells.
[simgrid.git] / include / simgrid / s4u / Barrier.hpp
1 /* Copyright (c) 2018-2022. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #ifndef SIMGRID_S4U_BARRIER_HPP
7 #define SIMGRID_S4U_BARRIER_HPP
8
9 #include <simgrid/barrier.h>
10 #include <simgrid/chrono.hpp>
11 #include <simgrid/forward.h>
12 #include <simgrid/s4u/ConditionVariable.hpp>
13 #include <simgrid/s4u/Mutex.hpp>
14
15 #include <atomic>
16 #include <future>
17
18 namespace simgrid {
19 namespace s4u {
20
21 class XBT_PUBLIC Barrier {
22   kernel::activity::BarrierImpl* pimpl_;
23   friend kernel::activity::BarrierImpl;
24
25   explicit Barrier(kernel::activity::BarrierImpl* pimpl) : pimpl_(pimpl) {}
26
27 public:
28 #ifndef DOXYGEN
29   Barrier(Barrier const&) = delete;
30   Barrier& operator=(Barrier const&) = delete;
31 #endif
32
33   /** Creates a barrier for the given amount of actors */
34   static BarrierPtr create(unsigned int expected_actors);
35   /** Blocks into the barrier. Every waiting actors will be unlocked once the expected amount of actors reaches the barrier */
36   int wait();
37   /** Returns some debug information about the barrier */
38   std::string to_string() const;
39
40 #ifndef DOXYGEN
41   /* refcounting */
42   friend XBT_PUBLIC void intrusive_ptr_add_ref(Barrier* barrier);
43   friend XBT_PUBLIC void intrusive_ptr_release(Barrier* barrier);
44 #endif
45 };
46 } // namespace s4u
47 } // namespace simgrid
48
49 #endif