Skip to content

Commit 50ccf42

Browse files
committed
Change go() to use a more efficient, move-friendly implementation.
1 parent 9dbad85 commit 50ccf42

File tree

2 files changed

+204
-151
lines changed

2 files changed

+204
-151
lines changed

asio/include/asio/go.hpp

+5-91
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,18 @@
1717

1818
#include "asio/detail/config.hpp"
1919
#include "asio/coroutine.hpp"
20-
#include "asio/detail/shared_ptr.hpp"
2120
#include "asio/detail/wrapped_handler.hpp"
2221
#include "asio/io_service.hpp"
2322
#include "asio/strand.hpp"
2423

2524
#include "asio/detail/push_options.hpp"
2625

2726
namespace asio {
27+
namespace detail {
28+
29+
template <typename Handler> class stackless_impl_base;
2830

29-
namespace detail { template <typename Handler> class stackless_impl_base; }
31+
} // namespace detail
3032

3133
/// Context object the represents the currently executing coroutine.
3234
/**
@@ -53,26 +55,6 @@ template <typename Handler>
5355
class basic_stackless_context
5456
{
5557
public:
56-
/// Construct a coroutine context to represent the specified coroutine.
57-
/**
58-
* Most applications do not need to use this constructor. Instead, the go()
59-
* function passes a coroutine context as an argument to the coroutine
60-
* function.
61-
*/
62-
basic_stackless_context(
63-
const detail::shared_ptr<
64-
detail::stackless_impl_base<Handler> >& stackless_impl,
65-
Handler& handler, coroutine* coro,
66-
asio::error_code* throw_ec, void** result)
67-
: stackless_impl_(stackless_impl),
68-
handler_(handler),
69-
coroutine_(coro),
70-
throw_ec_(throw_ec),
71-
async_result_(result),
72-
ec_(throw_ec)
73-
{
74-
}
75-
7658
/// Return a coroutine context that sets the specified error_code.
7759
/**
7860
* By default, when a coroutine context is used with an asynchronous operation, a
@@ -102,78 +84,10 @@ class basic_stackless_context
10284
return tmp;
10385
}
10486

105-
/// Returns true if the coroutine is the child of a fork.
106-
bool is_child() const
107-
{
108-
return coroutine_->is_child();
109-
}
110-
111-
/// Returns true if the coroutine is the parent of a fork.
112-
bool is_parent() const
113-
{
114-
return !is_child();
115-
}
116-
117-
/// Returns true if the coroutine has reached its terminal state.
118-
bool is_complete() const
119-
{
120-
return coroutine_->is_complete();
121-
}
122-
123-
/// Used by the @c reenter pseudo-keyword to obtain the coroutine state.
124-
friend coroutine& get_coroutine(basic_stackless_context& c)
125-
{
126-
return *c.coroutine_;
127-
}
128-
129-
/// Used by the @c reenter pseudo-keyword to obtain the coroutine state.
130-
friend coroutine& get_coroutine(basic_stackless_context* c)
131-
{
132-
return *c->coroutine_;
133-
}
134-
135-
/// Used by the @c reenter pseudo-keyword to obtain the error code resulting
136-
/// from the previous operation. If set, an exception will be thrown
137-
/// immediately following the resumption point.
138-
friend const asio::error_code* get_coroutine_error(
139-
basic_stackless_context& c)
140-
{
141-
return c.throw_ec_;
142-
}
143-
144-
/// Used by the @c reenter pseudo-keyword to obtain the error code resulting
145-
/// from the previous operation. If set, an exception will be thrown
146-
/// immediately following the resumption point.
147-
friend const asio::error_code* get_coroutine_error(
148-
basic_stackless_context* c)
149-
{
150-
return c->throw_ec_;
151-
}
152-
153-
/// Called by the @c let and @c await pseudo-keywords to obtain the pointer
154-
/// used to refer to any variables that should be set from the result of an
155-
/// asynchronous operation.
156-
friend void** get_coroutine_async_result(basic_stackless_context& c)
157-
{
158-
return c.async_result_;
159-
}
160-
161-
/// Called by the @c let and @c await pseudo-keywords to obtain the pointer
162-
/// used to refer to any variables that should be set from the result of an
163-
/// asynchronous operation.
164-
friend void** get_coroutine_async_result(basic_stackless_context* c)
165-
{
166-
return c->async_result_;
167-
}
168-
16987
#if defined(GENERATING_DOCUMENTATION)
17088
private:
17189
#endif // defined(GENERATING_DOCUMENTATION)
172-
detail::shared_ptr<detail::stackless_impl_base<Handler> > stackless_impl_;
173-
Handler& handler_;
174-
coroutine* coroutine_;
175-
const asio::error_code* const throw_ec_;
176-
void** const async_result_;
90+
detail::stackless_impl_base<Handler>** impl_;
17791
asio::error_code* ec_;
17892
};
17993

0 commit comments

Comments
 (0)