Chris@16: ////////////////////////////////////////////////////////////////////////////// Chris@16: // Chris@16: // (C) Copyright Ion Gaztanaga 2006. Distributed under the Boost Chris@16: // Software License, Version 1.0. (See accompanying file Chris@16: // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) Chris@16: // Chris@16: // See http://www.boost.org/libs/interprocess for documentation. Chris@16: // Chris@16: ////////////////////////////////////////////////////////////////////////////// Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@101: #ifndef BOOST_CONFIG_HPP Chris@101: # include Chris@101: #endif Chris@101: # Chris@101: #if defined(BOOST_HAS_PRAGMA_ONCE) Chris@101: # pragma once Chris@101: #endif Chris@101: Chris@16: namespace boost { Chris@16: namespace interprocess { Chris@16: Chris@16: inline barrier::barrier(unsigned int count) Chris@16: : m_threshold(count), m_count(count), m_generation(0) Chris@16: { Chris@16: if (count == 0) Chris@16: throw std::invalid_argument("count cannot be zero."); Chris@16: } Chris@16: Chris@16: inline barrier::~barrier(){} Chris@16: Chris@16: inline bool barrier::wait() Chris@16: { Chris@16: scoped_lock lock(m_mutex); Chris@16: unsigned int gen = m_generation; Chris@16: Chris@16: if (--m_count == 0){ Chris@16: m_generation++; Chris@16: m_count = m_threshold; Chris@16: m_cond.notify_all(); Chris@16: return true; Chris@16: } Chris@16: Chris@16: while (gen == m_generation){ Chris@16: m_cond.wait(lock); Chris@16: } Chris@16: return false; Chris@16: } Chris@16: Chris@16: } //namespace interprocess { Chris@16: } //namespace boost {