5 #include <libcopp/utils/config/libcopp_build_features.h>
19 #if defined(LIBCOPP_MACRO_ENABLE_STD_EXCEPTION_PTR) && LIBCOPP_MACRO_ENABLE_STD_EXCEPTION_PTR
26 LIBCOPP_COPP_NAMESPACE_BEGIN
29 template <
size_t N1,
size_t N2,
bool BIGGER_THAN_16>
32 template <
size_t N1,
size_t N2>
34 static constexpr
const size_t value = N1;
37 template <
size_t N1,
size_t N2>
39 static constexpr
const size_t value = N2;
42 template <
size_t N,
size_t COMPARE_TO>
44 static constexpr
const size_t value = align_helper_inner<N, COMPARE_TO, N >= COMPARE_TO>::value;
48 #if (defined(__cplusplus) && __cplusplus >= 201103L) || (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) || \
49 (defined(_MSC_VER) && _MSC_VER >= 1900)
50 # define COROUTINE_CONTEXT_BASE_ALIGN_UNIT_SIZE \
51 LIBCOPP_COPP_NAMESPACE_ID::details::align_helper<sizeof(max_align_t), 16>::value
53 # define COROUTINE_CONTEXT_BASE_ALIGN_UNIT_SIZE \
54 LIBCOPP_COPP_NAMESPACE_ID::details::align_helper<2 * sizeof(size_t), 16>::value
60 #define COROUTINE_CONTEXT_STACK_ALIGN_UNIT_SIZE \
61 LIBCOPP_COPP_NAMESPACE_ID::details::align_helper<COROUTINE_CONTEXT_BASE_ALIGN_UNIT_SIZE, 64>::value
64 "COROUTINE_CONTEXT_BASE_ALIGN_UNIT_SIZE");
66 "COROUTINE_CONTEXT_STACK_ALIGN_UNIT_SIZE");
92 EN_CFT_FINISHED = 0x01,
93 EN_CFT_IS_FIBER = 0x02,
110 #if defined(LIBCOPP_DISABLE_ATOMIC_LOCK) && LIBCOPP_DISABLE_ATOMIC_LOCK
111 LIBCOPP_COPP_NAMESPACE_ID::util::lock::atomic_int_type<LIBCOPP_COPP_NAMESPACE_ID::util::lock::unsafe_int_type<int> >
114 LIBCOPP_COPP_NAMESPACE_ID::util::lock::atomic_int_type<int>
status_;
117 #if defined(LIBCOPP_MACRO_ENABLE_STD_EXCEPTION_PTR) && LIBCOPP_MACRO_ENABLE_STD_EXCEPTION_PTR
118 std::exception_ptr unhandle_exception_;
140 LIBCOPP_COPP_API
bool set_flags(
int flags) LIBCOPP_MACRO_NOEXCEPT;
147 LIBCOPP_COPP_API
bool unset_flags(
int flags) LIBCOPP_MACRO_NOEXCEPT;
235 #if defined(LIBCOPP_MACRO_ENABLE_STD_EXCEPTION_PTR) && LIBCOPP_MACRO_ENABLE_STD_EXCEPTION_PTR
236 static inline void maybe_rethrow(std::exception_ptr &inout) {
238 std::exception_ptr eptr;
240 std::rethrow_exception(eptr);
244 UTIL_FORCEINLINE void maybe_rethrow() { maybe_rethrow(unhandle_exception_); }
261 LIBCOPP_COPP_NAMESPACE_END
atomic wrapper fo integers Licensed under the MIT licenses.
base type of all coroutine context
UTIL_FORCEINLINE int get_ret_code() const LIBCOPP_MACRO_NOEXCEPT
get runner return code
UTIL_FORCEINLINE void * get_private_buffer() const LIBCOPP_MACRO_NOEXCEPT
get private buffer(raw pointer)
UTIL_FORCEINLINE void run_and_recv_retcode(void *priv_data)
coroutine entrance function
LIBCOPP_COPP_API bool set_flags(int flags) LIBCOPP_MACRO_NOEXCEPT
set all flags to true
UTIL_FORCEINLINE const std::function< int(void *)> & get_runner() const LIBCOPP_MACRO_NOEXCEPT
LIBCOPP_COPP_API int set_runner(callback_type &&runner)
set runner
static LIBCOPP_COPP_API void set_this_coroutine_base(coroutine_context_base *ctx) LIBCOPP_MACRO_NOEXCEPT
set current coroutine
static UTIL_FORCEINLINE size_t align_private_data_size(size_t sz)
static size_t align_address_size(size_t sz)
static LIBCOPP_COPP_API coroutine_context_base * get_this_coroutine_base() LIBCOPP_MACRO_NOEXCEPT
get current coroutine
static size_t align_stack_size(size_t sz)
size_t private_buffer_size_
LIBCOPP_COPP_API bool check_flags(int flags) const LIBCOPP_MACRO_NOEXCEPT
check flags
UTIL_FORCEINLINE size_t get_private_buffer_size() const LIBCOPP_MACRO_NOEXCEPT
get private buffer size
LIBCOPP_COPP_API coroutine_context_base() LIBCOPP_MACRO_NOEXCEPT
LIBCOPP_COPP_NAMESPACE_ID::util::lock::atomic_int_type< int > status_
LIBCOPP_COPP_API bool is_finished() const LIBCOPP_MACRO_NOEXCEPT
get runner return code
LIBCOPP_COPP_API bool unset_flags(int flags) LIBCOPP_MACRO_NOEXCEPT
set all flags to false
std::function< int(void *)> callback_type
#define COROUTINE_CONTEXT_BASE_ALIGN_UNIT_SIZE
#define COROUTINE_CONTEXT_STACK_ALIGN_UNIT_SIZE
#define COPP_UNLIKELY_IF(...)
struct LIBCOPP_COPP_API_HEAD_ONLY align_helper_inner
void swap(intrusive_ptr< T > &lhs, intrusive_ptr< T > &rhs)
status of safe coroutine context base
@ EN_CRS_READY
EN_CRS_READY.
@ EN_CRS_FINISHED
EN_CRS_FINISHED.
@ EN_CRS_EXITED
EN_CRS_EXITED.
@ EN_CRS_RUNNING
EN_CRS_RUNNING.