Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Barrier.h
Go to the documentation of this file.
1 
32 #pragma once
33 
34 #include <condition_variable>
35 #include <cstdint>
36 #include <mutex>
37 
38 namespace ogdf {
39 
41 
48 class Barrier {
49  std::condition_variable m_allThreadsReachedSync;
51 
52  uint32_t m_threadCount;
54  uint32_t m_syncNumber;
55 
56 public:
58  explicit Barrier(uint32_t numThreads) : m_threadCount(numThreads) {
60  m_syncNumber = 0;
61  }
62 
64 
68  void threadSync() {
69  std::unique_lock<std::mutex> lk(m_numThreadsReachedSyncLock);
70 
71  uint32_t syncNr = m_syncNumber;
74  m_syncNumber++;
75  m_allThreadsReachedSync.notify_all();
77 
78  } else {
79  m_allThreadsReachedSync.wait(lk, [syncNr, this] { return syncNr != m_syncNumber; });
80  }
81  }
82 };
83 
84 }
ogdf
The namespace for all OGDF objects.
Definition: multilevelmixer.cpp:39
ogdf::Barrier::m_syncNumber
uint32_t m_syncNumber
number of current synchronization point.
Definition: Barrier.h:54
ogdf::Barrier::m_allThreadsReachedSync
std::condition_variable m_allThreadsReachedSync
Definition: Barrier.h:49
ogdf::Barrier::m_threadCount
uint32_t m_threadCount
the number of threads in the group.
Definition: Barrier.h:52
ogdf::Barrier::Barrier
Barrier(uint32_t numThreads)
Creates a barrier for a group of numThreads threads.
Definition: Barrier.h:58
ogdf::Barrier::m_numThreadsReachedSync
uint32_t m_numThreadsReachedSync
number of htreads that reached current synchronization point.
Definition: Barrier.h:53
ogdf::Barrier::threadSync
void threadSync()
Synchronizes the threads in the group.
Definition: Barrier.h:68
ogdf::Barrier
Representation of a barrier.
Definition: Barrier.h:48
ogdf::Barrier::m_numThreadsReachedSyncLock
std::mutex m_numThreadsReachedSyncLock
Definition: Barrier.h:50