5 #include <libcopp/utils/config/libcopp_build_features.h>
17 #if defined(LIBCOPP_MACRO_ENABLE_WIN_FIBER) && LIBCOPP_MACRO_ENABLE_WIN_FIBER
19 # ifndef WIN32_LEAN_AND_MEAN
20 # define WIN32_LEAN_AND_MEAN
25 LIBCOPP_COPP_NAMESPACE_BEGIN
31 using ptr_type = LIBCOPP_COPP_NAMESPACE_ID::util::intrusive_ptr<coroutine_context_fiber>;
38 using ptr_t = ptr_type;
40 using status_t = status_type;
41 using flag_t = flag_type;
50 # if defined(LIBCOPP_MACRO_ENABLE_STD_EXCEPTION_PTR) && LIBCOPP_MACRO_ENABLE_STD_EXCEPTION_PTR
51 using coroutine_context_base::unhandle_exception_;
54 struct jump_src_data_t {
55 coroutine_context_fiber *from_co;
57 coroutine_context_fiber *to_co;
62 friend struct LIBCOPP_COPP_API_HEAD_ONLY libcopp_fiber_internal_api_set;
63 friend struct LIBCOPP_COPP_API_HEAD_ONLY fiber_context_tls_data_t;
72 LIBCOPP_COPP_API coroutine_context_fiber() LIBCOPP_MACRO_NOEXCEPT;
75 LIBCOPP_COPP_API ~coroutine_context_fiber();
78 coroutine_context_fiber(
const coroutine_context_fiber &) = delete;
79 coroutine_context_fiber &operator=(
const coroutine_context_fiber &) = delete;
80 coroutine_context_fiber(
const coroutine_context_fiber &&) = delete;
81 coroutine_context_fiber &operator=(
const coroutine_context_fiber &&) = delete;
92 static LIBCOPP_COPP_API
int create(coroutine_context_fiber *p, callback_type &&runner,
94 size_t private_buffer_size,
95 size_t stack_reserve_size_of_fiber = 0) LIBCOPP_MACRO_NOEXCEPT;
97 template <typename TRunner>
98 static LIBCOPP_COPP_API_HEAD_ONLY
int create(coroutine_context_fiber *p, TRunner *runner,
100 size_t private_buffer_size,
101 size_t stack_reserve_size_of_fiber = 0) LIBCOPP_MACRO_NOEXCEPT {
103 p, [runner](
void *private_data) {
return (*runner)(private_data); }, callee_stack, coroutine_size,
104 private_buffer_size, stack_reserve_size_of_fiber);
113 LIBCOPP_COPP_API
int start(
void *priv_data =
nullptr);
115 # if defined(LIBCOPP_MACRO_ENABLE_STD_EXCEPTION_PTR) && LIBCOPP_MACRO_ENABLE_STD_EXCEPTION_PTR
122 LIBCOPP_COPP_API
int start(std::exception_ptr &unhandled,
void *priv_data =
nullptr) LIBCOPP_MACRO_NOEXCEPT;
131 LIBCOPP_COPP_API
int resume(
void *priv_data =
nullptr);
133 # if defined(LIBCOPP_MACRO_ENABLE_STD_EXCEPTION_PTR) && LIBCOPP_MACRO_ENABLE_STD_EXCEPTION_PTR
140 LIBCOPP_COPP_API
int resume(std::exception_ptr &unhandled,
void *priv_data =
nullptr) LIBCOPP_MACRO_NOEXCEPT;
148 LIBCOPP_COPP_API
int yield(
void **priv_data =
nullptr) LIBCOPP_MACRO_NOEXCEPT;
151 namespace this_fiber {
157 LIBCOPP_COPP_API coroutine_context_fiber *
get_coroutine() LIBCOPP_MACRO_NOEXCEPT;
165 template <typename Tc>
166 LIBCOPP_COPP_API_HEAD_ONLY Tc *
get() {
175 LIBCOPP_COPP_API
int yield(
void **priv_data =
nullptr) LIBCOPP_MACRO_NOEXCEPT;
177 LIBCOPP_COPP_NAMESPACE_END
base type of all coroutine context
size_t private_buffer_size_
LIBCOPP_COPP_NAMESPACE_ID::util::lock::atomic_int_type< int > status_
std::function< int(void *)> callback_type
LIBCOPP_COPP_API_HEAD_ONLY Tc * get()
get current coroutine and try to convert type
LIBCOPP_COPP_API int yield(void **priv_data=nullptr) LIBCOPP_MACRO_NOEXCEPT
yield current coroutine
LIBCOPP_COPP_API coroutine_context * get_coroutine() LIBCOPP_MACRO_NOEXCEPT
get current coroutine
status of safe coroutine context base