]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/compute/async/future.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / boost / compute / async / future.hpp
1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2013 Kyle Lutz <kyle.r.lutz@gmail.com>
3 //
4 // Distributed under the Boost Software License, Version 1.0
5 // See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt
7 //
8 // See http://boostorg.github.com/compute for more information.
9 //---------------------------------------------------------------------------//
10
11 #ifndef BOOST_COMPUTE_ASYNC_FUTURE_HPP
12 #define BOOST_COMPUTE_ASYNC_FUTURE_HPP
13
14 #include <boost/compute/event.hpp>
15
16 namespace boost {
17 namespace compute {
18
19 /// \class future
20 /// \brief Holds the result of an asynchronous computation.
21 ///
22 /// \see event, wait_list
23 template<class T>
24 class future
25 {
26 public:
27 future()
28 : m_event(0)
29 {
30 }
31
32 future(const T &result, const event &event)
33 : m_result(result),
34 m_event(event)
35 {
36 }
37
38 future(const future<T> &other)
39 : m_result(other.m_result),
40 m_event(other.m_event)
41 {
42 }
43
44 future& operator=(const future<T> &other)
45 {
46 if(this != &other){
47 m_result = other.m_result;
48 m_event = other.m_event;
49 }
50
51 return *this;
52 }
53
54 ~future()
55 {
56 }
57
58 /// Returns the result of the computation. This will block until
59 /// the result is ready.
60 T get()
61 {
62 wait();
63
64 return m_result;
65 }
66
67 /// Returns \c true if the future is valid.
68 bool valid() const
69 {
70 return m_event != 0;
71 }
72
73 /// Blocks until the computation is complete.
74 void wait() const
75 {
76 m_event.wait();
77 }
78
79 /// Returns the underlying event object.
80 event get_event() const
81 {
82 return m_event;
83 }
84
85 private:
86 T m_result;
87 event m_event;
88 };
89
90 /// \internal_
91 template<>
92 class future<void>
93 {
94 public:
95 future()
96 : m_event(0)
97 {
98 }
99
100 template<class T>
101 future(const future<T> &other)
102 : m_event(other.get_event())
103 {
104 }
105
106 explicit future(const event &event)
107 : m_event(event)
108 {
109 }
110
111 template<class T>
112 future<void> &operator=(const future<T> &other)
113 {
114 m_event = other.get_event();
115
116 return *this;
117 }
118
119 future<void> &operator=(const future<void> &other)
120 {
121 if(this != &other){
122 m_event = other.m_event;
123 }
124
125 return *this;
126 }
127
128 ~future()
129 {
130 }
131
132 void get()
133 {
134 wait();
135 }
136
137 bool valid() const
138 {
139 return m_event != 0;
140 }
141
142 void wait() const
143 {
144 m_event.wait();
145 }
146
147 event get_event() const
148 {
149 return m_event;
150 }
151
152 private:
153 event m_event;
154 };
155
156 /// \internal_
157 template<class Result>
158 inline future<Result> make_future(const Result &result, const event &event)
159 {
160 return future<Result>(result, event);
161 }
162
163 } // end compute namespace
164 } // end boost namespace
165
166 #endif // BOOST_COMPUTE_ASYNC_FUTURE_HPP