13#include <condition_variable>
15#ifndef ALPAKA_THREAD_BARRIER_DISABLE_SPINLOCK
25 template<
typename TIdx>
40#ifdef ALPAKA_THREAD_BARRIER_DISABLE_SPINLOCK
41 std::unique_lock<std::mutex>
lock(m_mtxBarrier);
43 if(--m_curThreadCount == 0)
45 m_curThreadCount = m_threadCount;
47#ifdef ALPAKA_THREAD_BARRIER_DISABLE_SPINLOCK
48 m_cvAllThreadsReachedBarrier.notify_all();
53#ifdef ALPAKA_THREAD_BARRIER_DISABLE_SPINLOCK
54 m_cvAllThreadsReachedBarrier.wait(
60 std::this_thread::yield();
67#ifdef ALPAKA_THREAD_BARRIER_DISABLE_SPINLOCK
68 std::mutex m_mtxBarrier;
69 std::condition_variable m_cvAllThreadsReachedBarrier;
71 const TIdx m_threadCount;
72#ifdef ALPAKA_THREAD_BARRIER_DISABLE_SPINLOCK
73 TIdx m_curThreadCount;
76 std::atomic<TIdx> m_curThreadCount;
77 std::atomic<TIdx> m_generation;
83 template<
typename TOp>
89 void operator()(std::atomic<int>& result,
bool value)
91 result +=
static_cast<int>(value);
98 void operator()(std::atomic<int>& result,
bool value)
100 result &=
static_cast<int>(value);
107 void operator()(std::atomic<int>& result,
bool value)
109 result |=
static_cast<int>(value);
115 template<
typename TIdx>
127 template<
typename TOp>
131 std::unique_lock<std::mutex>
lock(m_mtxBarrier);
134 if(m_curThreadCount == m_threadCount)
144 if(--m_curThreadCount == 0)
146 m_curThreadCount = m_threadCount;
148 m_cvAllThreadsReachedBarrier.notify_all();
152 m_cvAllThreadsReachedBarrier.wait(
160 std::mutex m_mtxBarrier;
161 std::condition_variable m_cvAllThreadsReachedBarrier;
162 const TIdx m_threadCount;
163 TIdx m_curThreadCount;
165 std::atomic<int> m_result[2];
A self-resetting barrier with barrier.
BarrierThreadWithPredicate(TIdx const &threadCount)
ALPAKA_FN_HOST auto wait(int predicate) -> int
Waits for all the other threads to reach the barrier.
A self-resetting barrier.
BarrierThread(TIdx const &threadCount)
auto wait() -> void
Waits for all the other threads to reach the barrier.
auto clipCast(V const &val) -> T
The logical and function object.
The counting function object.
The logical or function object.