10 #define _WIN32_WINNT 0x0400
11 #define WIN32_LEAN_AND_MEAN
18 static thread_local cothread_t co_active_ = 0;
20 static void __stdcall co_thunk(void *coentry)
22 ((void (*)(void))coentry)();
25 cothread_t co_active(void)
29 #if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP)
30 ConvertThreadToFiberEx(0, FIBER_FLAG_FLOAT_SWITCH);
32 ConvertThreadToFiber(0);
34 co_active_ = GetCurrentFiber();
39 cothread_t co_create(unsigned int heapsize, void (*coentry)(void))
43 #if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP)
44 ConvertThreadToFiberEx(0, FIBER_FLAG_FLOAT_SWITCH);
46 ConvertThreadToFiber(0);
48 co_active_ = GetCurrentFiber();
51 #if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP)
52 return (cothread_t)CreateFiberEx(heapsize, heapsize, FIBER_FLAG_FLOAT_SWITCH, co_thunk, (void*)coentry);
54 return (cothread_t)CreateFiber(heapsize, co_thunk, (void*)coentry);
58 void co_delete(cothread_t cothread)
60 DeleteFiber(cothread);
63 void co_switch(cothread_t cothread)
65 co_active_ = cothread;
66 SwitchToFiber(cothread);