5 #include <libcopp/utils/config/libcopp_build_features.h>
20 LIBCOPP_COPP_NAMESPACE_BEGIN
25 template <
typename TALLOC>
32 using ptr_type = LIBCOPP_COPP_NAMESPACE_ID::util::intrusive_ptr<this_type>;
72 size_t private_buffer_size = 0,
size_t coroutine_size = 0) LIBCOPP_MACRO_NOEXCEPT {
81 coroutine_size += this_align_size;
84 if (stack_sz <= coroutine_size + private_buffer_size) {
89 alloc.allocate(callee_stack, stack_sz);
91 if (
nullptr == callee_stack.
sp) {
96 unsigned char *this_addr =
reinterpret_cast<unsigned char *
>(callee_stack.
sp);
98 this_addr -= private_buffer_size + this_align_size;
99 ret.
reset(
new (
reinterpret_cast<void *
>(this_addr))
this_type(std::move(alloc)));
103 ret->callee_stack_ = std::move(callee_stack);
105 alloc.deallocate(callee_stack);
111 private_buffer_size) < 0) {
118 template <
class TRunner>
120 size_t private_buffer_size = 0,
size_t coroutine_size = 0) LIBCOPP_MACRO_NOEXCEPT {
121 if (
nullptr == runner) {
125 return create([runner](
void *private_data) {
return (*runner)(private_data); }, alloc, stack_size,
126 private_buffer_size, coroutine_size);
130 size_t private_buffer_size = 0,
size_t coroutine_size = 0) LIBCOPP_MACRO_NOEXCEPT {
139 size_t coroutine_size = 0) LIBCOPP_MACRO_NOEXCEPT {
141 return create(std::move(runner), alloc, stack_size, private_buffer_size, coroutine_size);
144 template <
class TRunner>
145 static inline ptr_type create(TRunner *runner,
size_t stack_size = 0,
size_t private_buffer_size = 0,
146 size_t coroutine_size = 0) LIBCOPP_MACRO_NOEXCEPT {
147 return create([runner](
void *private_data) {
return (*runner)(private_data); }, stack_size, private_buffer_size,
151 static inline ptr_type create(
int (*fn)(
void *),
size_t stack_size = 0,
size_t private_buffer_size = 0,
152 size_t coroutine_size = 0) LIBCOPP_MACRO_NOEXCEPT {
184 copy_alloc.deallocate(copy_stack);
190 #if defined(LIBCOPP_DISABLE_ATOMIC_LOCK) && LIBCOPP_DISABLE_ATOMIC_LOCK
191 LIBCOPP_COPP_NAMESPACE_ID::util::lock::atomic_int_type<
192 LIBCOPP_COPP_NAMESPACE_ID::util::lock::unsafe_int_type<size_t> >
195 LIBCOPP_COPP_NAMESPACE_ID::util::lock::atomic_int_type<size_t>
ref_count_;
200 LIBCOPP_COPP_NAMESPACE_END
static UTIL_FORCEINLINE size_t align_private_data_size(size_t sz)
static size_t align_address_size(size_t sz)
coroutine container contain stack context, stack allocator and runtime fcontext
coroutine_context::callback_type callback_type
const allocator_type & get_allocator() const LIBCOPP_MACRO_NOEXCEPT
get stack allocator
static ptr_type create(int(*fn)(void *), allocator_type &alloc, size_t stack_size=0, size_t private_buffer_size=0, size_t coroutine_size=0) LIBCOPP_MACRO_NOEXCEPT
LIBCOPP_COPP_NAMESPACE_ID::util::lock::atomic_int_type< size_t > ref_count_
coroutine_context_container(const coroutine_context_container &)=delete
static ptr_type create(callback_type &&runner, allocator_type &alloc, size_t stack_sz=0, size_t private_buffer_size=0, size_t coroutine_size=0) LIBCOPP_MACRO_NOEXCEPT
create and init coroutine with specify runner and specify stack size
allocator_type & get_allocator() LIBCOPP_MACRO_NOEXCEPT
get stack allocator
friend void intrusive_ptr_add_ref(this_type *p)
static ptr_type create(callback_type &&runner, size_t stack_size=0, size_t private_buffer_size=0, size_t coroutine_size=0) LIBCOPP_MACRO_NOEXCEPT
coroutine_context_container(const allocator_type &alloc) LIBCOPP_MACRO_NOEXCEPT
coroutine_context_container< allocator_type > this_type
static ptr_type create(TRunner *runner, allocator_type &alloc, size_t stack_size=0, size_t private_buffer_size=0, size_t coroutine_size=0) LIBCOPP_MACRO_NOEXCEPT
size_t use_count() const LIBCOPP_MACRO_NOEXCEPT
~coroutine_context_container()
static ptr_type create(TRunner *runner, size_t stack_size=0, size_t private_buffer_size=0, size_t coroutine_size=0) LIBCOPP_MACRO_NOEXCEPT
LIBCOPP_COPP_NAMESPACE_ID::util::intrusive_ptr< this_type > ptr_type
friend void intrusive_ptr_release(this_type *p)
static ptr_type create(int(*fn)(void *), size_t stack_size=0, size_t private_buffer_size=0, size_t coroutine_size=0) LIBCOPP_MACRO_NOEXCEPT
coroutine_context_container(allocator_type &&alloc) LIBCOPP_MACRO_NOEXCEPT
base type of all stackful coroutine context
LIBCOPP_COPP_API coroutine_context() LIBCOPP_MACRO_NOEXCEPT
stack_context callee_stack_
LIBCOPP_COPP_NAMESPACE_ID::util::intrusive_ptr< coroutine_context > ptr_type
coroutine_context_base::callback_type callback_type
static LIBCOPP_COPP_API int create(coroutine_context *p, callback_type &&runner, const stack_context &callee_stack, size_t coroutine_size, size_t private_buffer_size) LIBCOPP_MACRO_NOEXCEPT
create coroutine context at stack context callee_
#define COROUTINE_CONTEXT_BASE_USING_BASE(base_type)
void reset() LIBCOPP_MACRO_NOEXCEPT
static LIBCOPP_COPP_API std::size_t default_size() LIBCOPP_MACRO_NOEXCEPT