Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
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
39namespace ogdf {
40
42
49class Barrier {
50 std::condition_variable m_allThreadsReachedSync;
52
56
57public:
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
76 m_allThreadsReachedSync.notify_all();
78
79 } else {
80 m_allThreadsReachedSync.wait(lk, [syncNr, this] { return syncNr != m_syncNumber; });
81 }
82 }
83};
84
85}
Basic declarations, included by all source files.
Representation of a barrier.
Definition Barrier.h:49
Barrier(uint32_t numThreads)
Creates a barrier for a group of numThreads threads.
Definition Barrier.h:59
std::mutex m_numThreadsReachedSyncLock
Definition Barrier.h:51
uint32_t m_threadCount
the number of threads in the group.
Definition Barrier.h:53
uint32_t m_numThreadsReachedSync
number of htreads that reached current synchronization point.
Definition Barrier.h:54
uint32_t m_syncNumber
number of current synchronization point.
Definition Barrier.h:55
void threadSync()
Synchronizes the threads in the group.
Definition Barrier.h:69
std::condition_variable m_allThreadsReachedSync
Definition Barrier.h:50
static MultilevelBuilder * getDoubleFactoredZeroAdjustedMerger()
The namespace for all OGDF objects.