]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/fiber/src/barrier.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / fiber / src / barrier.cpp
1
2 // Copyright Oliver Kowalke 2013.
3 // Distributed under the Boost Software License, Version 1.0.
4 // (See accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
6
7 #include "boost/fiber/barrier.hpp"
8
9 #include <mutex>
10 #include <system_error>
11
12 #include "boost/fiber/exceptions.hpp"
13
14 #ifdef BOOST_HAS_ABI_HEADERS
15 # include BOOST_ABI_PREFIX
16 #endif
17
18 namespace boost {
19 namespace fibers {
20
21 barrier::barrier( std::size_t initial) :
22 initial_{ initial },
23 current_{ initial_ } {
24 if ( 0 == initial) {
25 throw fiber_error( std::make_error_code( std::errc::invalid_argument),
26 "boost fiber: zero initial barrier count");
27 }
28 }
29
30 bool
31 barrier::wait() {
32 std::unique_lock< mutex > lk( mtx_);
33 const bool cycle = cycle_;
34 if ( 0 == --current_) {
35 cycle_ = ! cycle_;
36 current_ = initial_;
37 lk.unlock(); // no pessimization
38 cond_.notify_all();
39 return true;
40 } else {
41 cond_.wait( lk, [&](){ return cycle != cycle_; });
42 }
43 return false;
44 }
45
46 }}
47
48 #ifdef BOOST_HAS_ABI_HEADERS
49 # include BOOST_ABI_SUFFIX
50 #endif