/* * Barrier * (C) 2016 Joel Low * * Botan is released under the Simplified BSD License (see license.txt) */ #include #if defined(BOTAN_TARGET_OS_HAS_THREADS) namespace Botan { void Barrier::wait(unsigned delta) { lock_guard_type lock(m_mutex); m_value += delta; } void Barrier::sync() { std::unique_lock lock(m_mutex); --m_value; if(m_value > 0) { unsigned current_syncs = m_syncs; m_cond.wait(lock, [this, ¤t_syncs] { return m_syncs != current_syncs; }); } else { m_value = 0; ++m_syncs; m_cond.notify_all(); } } } #endif