Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'rename-operation-task' into 'master'
[simgrid.git] / include / simgrid / s4u / Barrier.hpp
1 /* Copyright (c) 2018-2023. 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::s4u {
19
20 class XBT_PUBLIC Barrier {
21   kernel::activity::BarrierImpl* pimpl_;
22   friend kernel::activity::BarrierImpl;
23
24   explicit Barrier(kernel::activity::BarrierImpl* pimpl) : pimpl_(pimpl) {}
25
26 public:
27 #ifndef DOXYGEN
28   Barrier(Barrier const&) = delete;
29   Barrier& operator=(Barrier const&) = delete;
30 #endif
31
32   /** \static Creates a barrier for the given amount of actors */
33   static BarrierPtr create(unsigned int expected_actors);
34   /** Blocks into the barrier. Every waiting actors will be unlocked once the expected amount of actors reaches the barrier */
35   int wait();
36   /** Returns some debug information about the barrier */
37   std::string to_string() const;
38
39 #ifndef DOXYGEN
40   /* refcounting */
41   friend XBT_PUBLIC void intrusive_ptr_add_ref(Barrier* barrier);
42   friend XBT_PUBLIC void intrusive_ptr_release(Barrier* barrier);
43 #endif
44 };
45 } // namespace simgrid::s4u
46
47 #endif