Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Introduce SG_BARRIER_SERIAL_THREAD
[simgrid.git] / include / simgrid / s4u / Barrier.hpp
1 /* Copyright (c) 2018-2019. 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/forward.h>
10 #include <simgrid/s4u/ConditionVariable.hpp>
11 #include <simgrid/chrono.hpp>
12 #include <simgrid/s4u/Mutex.hpp>
13
14 #include <atomic>
15 #include <future>
16
17 constexpr int SG_BARRIER_SERIAL_THREAD = -1;
18
19 namespace simgrid {
20 namespace s4u {
21
22 class XBT_PUBLIC Barrier {
23 private:
24   MutexPtr mutex_;
25   ConditionVariablePtr cond_;
26   unsigned int expected_actors_;
27   unsigned int arrived_actors_ = 0;
28
29   /* refcounting */
30   std::atomic_int_fast32_t refcount_{0};
31
32 public:
33   explicit Barrier(unsigned int count);
34   ~Barrier()              = default;
35 #ifndef DOXYGEN
36   Barrier(Barrier const&) = delete;
37   Barrier& operator=(Barrier const&) = delete;
38 #endif
39
40   static BarrierPtr create(unsigned int expected_actors);
41   int wait();
42
43 #ifndef DOXYGEN
44   /* refcounting */
45   friend XBT_PUBLIC void intrusive_ptr_add_ref(Barrier* barrier);
46   friend XBT_PUBLIC void intrusive_ptr_release(Barrier* barrier);
47 #endif
48 };
49 } // namespace s4u
50 } // namespace simgrid
51
52 #endif