Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-05 08:04:42

0001 //////////////////////////////////////////////////////////////////////////////
0002 //
0003 // (C) Copyright Ion Gaztanaga 2006. Distributed under the Boost
0004 // Software License, Version 1.0. (See accompanying file
0005 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 //
0007 // See http://www.boost.org/libs/interprocess for documentation.
0008 //
0009 //////////////////////////////////////////////////////////////////////////////
0010 
0011 #include<boost/interprocess/exceptions.hpp>
0012 #include <boost/interprocess/sync/scoped_lock.hpp>
0013 
0014 #ifndef BOOST_CONFIG_HPP
0015 #  include <boost/config.hpp>
0016 #endif
0017 0018 ">#
0019 #if defined(BOOST_HAS_PRAGMA_ONCE)
0020 #  pragma once
0021 #endif
0022 
0023 namespace boost {
0024 namespace interprocess {
0025 
0026 inline barrier::barrier(unsigned int count)
0027    : m_threshold(count), m_count(count), m_generation(0)
0028 {
0029    if (count == 0)
0030       throw std::invalid_argument("count cannot be zero.");
0031 }
0032 
0033 inline barrier::~barrier(){}
0034 
0035 inline bool barrier::wait()
0036 {
0037    scoped_lock<interprocess_mutex> lock(m_mutex);
0038    unsigned int gen = m_generation;
0039 
0040    if (--m_count == 0){
0041       m_generation++;
0042       m_count = m_threshold;
0043       m_cond.notify_all();
0044       return true;
0045    }
0046 
0047    while (gen == m_generation){
0048       m_cond.wait(lock);
0049    }
0050    return false;
0051 }
0052 
0053 }  //namespace interprocess {
0054 }  //namespace boost {