]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/interprocess/sync/spin/interprocess_barrier.hpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / boost / interprocess / sync / spin / interprocess_barrier.hpp
1 //////////////////////////////////////////////////////////////////////////////
2 //
3 // (C) Copyright Ion Gaztanaga 2006. Distributed under the Boost
4 // Software License, Version 1.0. (See accompanying file
5 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 //
7 // See http://www.boost.org/libs/interprocess for documentation.
8 //
9 //////////////////////////////////////////////////////////////////////////////
10
11 #include<boost/interprocess/exceptions.hpp>
12 #include <boost/interprocess/sync/scoped_lock.hpp>
13
14 #ifndef BOOST_CONFIG_HPP
15 # include <boost/config.hpp>
16 #endif
17 #
18 #if defined(BOOST_HAS_PRAGMA_ONCE)
19 # pragma once
20 #endif
21
22 namespace boost {
23 namespace interprocess {
24
25 inline barrier::barrier(unsigned int count)
26 : m_threshold(count), m_count(count), m_generation(0)
27 {
28 if (count == 0)
29 throw std::invalid_argument("count cannot be zero.");
30 }
31
32 inline barrier::~barrier(){}
33
34 inline bool barrier::wait()
35 {
36 scoped_lock<interprocess_mutex> lock(m_mutex);
37 unsigned int gen = m_generation;
38
39 if (--m_count == 0){
40 m_generation++;
41 m_count = m_threshold;
42 m_cond.notify_all();
43 return true;
44 }
45
46 while (gen == m_generation){
47 m_cond.wait(lock);
48 }
49 return false;
50 }
51
52 } //namespace interprocess {
53 } //namespace boost {