]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/interprocess/sync/spin/interprocess_barrier.hpp
update sources to v12.2.3
[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/detail/posix_time_types_wrk.hpp>
13 #include <boost/interprocess/sync/scoped_lock.hpp>
14
15 #ifndef BOOST_CONFIG_HPP
16 # include <boost/config.hpp>
17 #endif
18 #
19 #if defined(BOOST_HAS_PRAGMA_ONCE)
20 # pragma once
21 #endif
22
23 namespace boost {
24 namespace interprocess {
25
26 inline barrier::barrier(unsigned int count)
27 : m_threshold(count), m_count(count), m_generation(0)
28 {
29 if (count == 0)
30 throw std::invalid_argument("count cannot be zero.");
31 }
32
33 inline barrier::~barrier(){}
34
35 inline bool barrier::wait()
36 {
37 scoped_lock<interprocess_mutex> lock(m_mutex);
38 unsigned int gen = m_generation;
39
40 if (--m_count == 0){
41 m_generation++;
42 m_count = m_threshold;
43 m_cond.notify_all();
44 return true;
45 }
46
47 while (gen == m_generation){
48 m_cond.wait(lock);
49 }
50 return false;
51 }
52
53 } //namespace interprocess {
54 } //namespace boost {