Mercurial > hg > vamp-build-and-test
annotate DEPENDENCIES/generic/include/boost/interprocess/sync/spin/interprocess_barrier.hpp @ 125:34e428693f5d vext
Vext -> Repoint
author | Chris Cannam |
---|---|
date | Thu, 14 Jun 2018 11:15:39 +0100 |
parents | c530137014c0 |
children |
rev | line source |
---|---|
Chris@16 | 1 ////////////////////////////////////////////////////////////////////////////// |
Chris@16 | 2 // |
Chris@16 | 3 // (C) Copyright Ion Gaztanaga 2006. Distributed under the Boost |
Chris@16 | 4 // Software License, Version 1.0. (See accompanying file |
Chris@16 | 5 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
Chris@16 | 6 // |
Chris@16 | 7 // See http://www.boost.org/libs/interprocess for documentation. |
Chris@16 | 8 // |
Chris@16 | 9 ////////////////////////////////////////////////////////////////////////////// |
Chris@16 | 10 |
Chris@16 | 11 #include<boost/interprocess/exceptions.hpp> |
Chris@16 | 12 #include <boost/interprocess/detail/posix_time_types_wrk.hpp> |
Chris@16 | 13 #include <boost/interprocess/sync/scoped_lock.hpp> |
Chris@16 | 14 |
Chris@101 | 15 #ifndef BOOST_CONFIG_HPP |
Chris@101 | 16 # include <boost/config.hpp> |
Chris@101 | 17 #endif |
Chris@101 | 18 # |
Chris@101 | 19 #if defined(BOOST_HAS_PRAGMA_ONCE) |
Chris@101 | 20 # pragma once |
Chris@101 | 21 #endif |
Chris@101 | 22 |
Chris@16 | 23 namespace boost { |
Chris@16 | 24 namespace interprocess { |
Chris@16 | 25 |
Chris@16 | 26 inline barrier::barrier(unsigned int count) |
Chris@16 | 27 : m_threshold(count), m_count(count), m_generation(0) |
Chris@16 | 28 { |
Chris@16 | 29 if (count == 0) |
Chris@16 | 30 throw std::invalid_argument("count cannot be zero."); |
Chris@16 | 31 } |
Chris@16 | 32 |
Chris@16 | 33 inline barrier::~barrier(){} |
Chris@16 | 34 |
Chris@16 | 35 inline bool barrier::wait() |
Chris@16 | 36 { |
Chris@16 | 37 scoped_lock<interprocess_mutex> lock(m_mutex); |
Chris@16 | 38 unsigned int gen = m_generation; |
Chris@16 | 39 |
Chris@16 | 40 if (--m_count == 0){ |
Chris@16 | 41 m_generation++; |
Chris@16 | 42 m_count = m_threshold; |
Chris@16 | 43 m_cond.notify_all(); |
Chris@16 | 44 return true; |
Chris@16 | 45 } |
Chris@16 | 46 |
Chris@16 | 47 while (gen == m_generation){ |
Chris@16 | 48 m_cond.wait(lock); |
Chris@16 | 49 } |
Chris@16 | 50 return false; |
Chris@16 | 51 } |
Chris@16 | 52 |
Chris@16 | 53 } //namespace interprocess { |
Chris@16 | 54 } //namespace boost { |