17 #ifndef _TBB_co_context_H 18 #define _TBB_co_context_H 24 typedef LPVOID coroutine_type;
31 #pragma warning(disable:1478) 33 #pragma clang diagnostic push 34 #pragma clang diagnostic ignored "-Wdeprecated-declarations" 49 #define MAP_ANONYMOUS MAP_ANON 69 void swap_coroutine(coroutine_type& prev_coroutine, coroutine_type& new_coroutine);
135 c = IsThreadAFiber() ? GetCurrentFiber() :
136 ConvertThreadToFiberEx(nullptr, FIBER_FLAG_FLOAT_SWITCH);
140 inline void swap_coroutine(coroutine_type& prev_coroutine, coroutine_type& new_coroutine) {
143 prev_coroutine = GetCurrentFiber();
145 SwitchToFiber(new_coroutine);
156 const size_t page_aligned_stack_size = (stack_size + (REG_PAGE_SIZE - 1)) & ~(REG_PAGE_SIZE - 1);
157 const size_t protected_stack_size = page_aligned_stack_size + 2 * REG_PAGE_SIZE;
160 uintptr_t stack_ptr = (uintptr_t)mmap(NULL, protected_stack_size, PROT_NONE, MAP_PRIVATE |
MAP_ANONYMOUS |
MAP_STACK, -1, 0);
164 int err = mprotect((
void*)(stack_ptr + REG_PAGE_SIZE), page_aligned_stack_size, PROT_READ | PROT_WRITE);
168 c.
my_stack = (
void*)(stack_ptr + REG_PAGE_SIZE);
180 typedef void(*coroutine_func_t)();
205 #pragma warning(pop) // 1478 warning 207 #pragma clang diagnostic pop // "-Wdeprecated-declarations" void co_local_wait_for_all(void *)
void destroy_coroutine(coroutine_type &c)
co_context(size_t stack_size, void *arg)
coroutine_type my_coroutine
void swap_coroutine(coroutine_type &prev_coroutine, coroutine_type &new_coroutine)
#define __TBB_ASSERT_EX(predicate, comment)
"Extended" version is useful to suppress warnings if a variable is only used with an assert
void create_coroutine(coroutine_type &c, size_t stack_size, void *arg)
static size_t default_page_size()
void current_coroutine(coroutine_type &c)
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
void resume(co_context &target)