Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/libsnes/bsnes/libco/fiber.c
2 views
1
/*
2
libco.win (2008-01-28)
3
authors: Nach, byuu
4
license: public domain
5
*/
6
7
#define LIBCO_C
8
#include "libco.h"
9
#define WINVER 0x0400
10
#define _WIN32_WINNT 0x0400
11
#define WIN32_LEAN_AND_MEAN
12
#include <windows.h>
13
14
#ifdef __cplusplus
15
extern "C" {
16
#endif
17
18
static thread_local cothread_t co_active_ = 0;
19
20
static void __stdcall co_thunk(void *coentry) {
21
((void (*)(void))coentry)();
22
}
23
24
cothread_t co_active() {
25
if(!co_active_) {
26
ConvertThreadToFiber(0);
27
co_active_ = GetCurrentFiber();
28
}
29
return co_active_;
30
}
31
32
cothread_t co_create(unsigned int heapsize, void (*coentry)(void)) {
33
if(!co_active_) {
34
ConvertThreadToFiber(0);
35
co_active_ = GetCurrentFiber();
36
}
37
return (cothread_t)CreateFiber(heapsize, co_thunk, (void*)coentry);
38
}
39
40
void co_delete(cothread_t cothread) {
41
DeleteFiber(cothread);
42
}
43
44
void co_switch(cothread_t cothread) {
45
co_active_ = cothread;
46
SwitchToFiber(cothread);
47
}
48
49
#ifdef __cplusplus
50
}
51
#endif
52
53