Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Barrier.h
Go to the documentation of this file.
1 
32 #pragma once
33 
34 #include <ogdf/basic/basic.h>
35 
36 #include <condition_variable>
37 #include <mutex>
38 
39 namespace ogdf {
40 
42 
49 class Barrier {
50  std::condition_variable m_allThreadsReachedSync;
52 
53  uint32_t m_threadCount;
55  uint32_t m_syncNumber;
56 
57 public:
59  explicit Barrier(uint32_t numThreads) : m_threadCount(numThreads) {
61  m_syncNumber = 0;
62  }
63 
65 
69  void threadSync() {
70  std::unique_lock<std::mutex> lk(m_numThreadsReachedSyncLock);
71 
72  uint32_t syncNr = m_syncNumber;
75  m_syncNumber++;
76  m_allThreadsReachedSync.notify_all();
78 
79  } else {
80  m_allThreadsReachedSync.wait(lk, [syncNr, this] { return syncNr != m_syncNumber; });
81  }
82  }
83 };
84 
85 }
ogdf
The namespace for all OGDF objects.
Definition: AugmentationModule.h:36
ogdf::Barrier::m_syncNumber
uint32_t m_syncNumber
number of current synchronization point.
Definition: Barrier.h:55
ogdf::Barrier::m_allThreadsReachedSync
std::condition_variable m_allThreadsReachedSync
Definition: Barrier.h:50
ogdf::Barrier::m_threadCount
uint32_t m_threadCount
the number of threads in the group.
Definition: Barrier.h:53
ogdf::Barrier::Barrier
Barrier(uint32_t numThreads)
Creates a barrier for a group of numThreads threads.
Definition: Barrier.h:59
ogdf::Barrier::m_numThreadsReachedSync
uint32_t m_numThreadsReachedSync
number of htreads that reached current synchronization point.
Definition: Barrier.h:54
ogdf::Barrier::threadSync
void threadSync()
Synchronizes the threads in the group.
Definition: Barrier.h:69
ogdf::Barrier
Representation of a barrier.
Definition: Barrier.h:49
basic.h
Basic declarations, included by all source files.
ogdf::Barrier::m_numThreadsReachedSyncLock
std::mutex m_numThreadsReachedSyncLock
Definition: Barrier.h:51