]> git.proxmox.com Git - ceph.git/blob - ceph/src/rgw/rgw_boost_asio_coroutine.h
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / rgw / rgw_boost_asio_coroutine.h
1 //
2 // copy of needed class and macors from coroutine.hpp
3 //
4 // Copyright (c) 2003-2013 Christopher M. Kohlhoff (chris at kohlhoff dot com)
5 //
6 // Distributed under the Boost Software License, Version 1.0. (See accompanying
7 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
8 //
9
10 #ifndef RGW_BOOST_ASIO_COROUTINE_H
11 #define RGW_BOOST_ASIO_COROUTINE_H
12
13 #ifndef HAVE_BOOST_ASIO_COROUTINE
14
15 namespace boost {
16 namespace asio {
17 namespace detail {
18
19 class coroutine_ref;
20
21 } // namespace detail
22
23 class coroutine
24 {
25 public:
26 /// Constructs a coroutine in its initial state.
27 coroutine() : value_(0) {}
28
29 /// Returns true if the coroutine is the child of a fork.
30 bool is_child() const { return value_ < 0; }
31
32 /// Returns true if the coroutine is the parent of a fork.
33 bool is_parent() const { return !is_child(); }
34
35 /// Returns true if the coroutine has reached its terminal state.
36 bool is_complete() const { return value_ == -1; }
37
38 private:
39 friend class detail::coroutine_ref;
40 int value_;
41 };
42
43
44 namespace detail {
45
46 class coroutine_ref
47 {
48 public:
49 coroutine_ref(coroutine& c) : value_(c.value_), modified_(false) {}
50 coroutine_ref(coroutine* c) : value_(c->value_), modified_(false) {}
51 ~coroutine_ref() { if (!modified_) value_ = -1; }
52 operator int() const { return value_; }
53 int& operator=(int v) { modified_ = true; return value_ = v; }
54 private:
55 void operator=(const coroutine_ref&);
56 int& value_;
57 bool modified_;
58 };
59
60 } // namespace detail
61 } // namespace asio
62 } // namespace boost
63
64 #endif // HAVE_BOOST_ASIO_COROUTINE
65
66 #endif // RGW_BOOST_ASIO_COROUTINE_H
67