Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of framagit.org:simgrid/simgrid
[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 namespace simgrid {
18 namespace s4u {
19
20 class XBT_PUBLIC Barrier {
21 private:
22   MutexPtr mutex_;
23   ConditionVariablePtr cond_;
24   unsigned int expected_processes_;
25   unsigned int arrived_processes_ = 0;
26
27   /* refcounting */
28   std::atomic_int_fast32_t refcount_{0};
29
30 public:
31   explicit Barrier(unsigned int count);
32   ~Barrier()              = default;
33   Barrier(Barrier const&) = delete;
34   Barrier& operator=(Barrier const&) = delete;
35
36   /** Constructs a new barrier */
37   static BarrierPtr create(unsigned int expected_processes);
38
39   int wait();
40
41   /* refcounting */
42   friend XBT_PUBLIC void intrusive_ptr_add_ref(Barrier* barrier);
43   friend XBT_PUBLIC void intrusive_ptr_release(Barrier* barrier);
44 };
45 }
46 } // namespace simgrid::s4u
47
48 #endif