Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:38:32

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 #if defined(BOOST_HAS_PRAGMA_ONCE)
0019 #  pragma once
0020 #endif
0021 
0022 namespace boost {
0023 namespace interprocess {
0024 
0025 inline barrier::barrier(unsigned int count)
0026    : m_threshold(count), m_count(count), m_generation(0)
0027 {
0028    if (count == 0)
0029       throw std::invalid_argument("count cannot be zero.");
0030 }
0031 
0032 inline barrier::~barrier(){}
0033 
0034 inline bool barrier::wait()
0035 {
0036    scoped_lock<interprocess_mutex> lock(m_mutex);
0037    unsigned int gen = m_generation;
0038 
0039    if (--m_count == 0){
0040       m_generation++;
0041       m_count = m_threshold;
0042       m_cond.notify_all();
0043       return true;
0044    }
0045 
0046    while (gen == m_generation){
0047       m_cond.wait(lock);
0048    }
0049    return false;
0050 }
0051 
0052 }  //namespace interprocess {
0053 }  //namespace boost {