… | |
… | |
55 | * |
55 | * |
56 | * This flavour uses SUSv'2 setjmp/longjmp and sigaltstack functions to |
56 | * This flavour uses SUSv'2 setjmp/longjmp and sigaltstack functions to |
57 | * do it's job. Coroutine creation is much slower than UCONTEXT, but |
57 | * do it's job. Coroutine creation is much slower than UCONTEXT, but |
58 | * context switching is often a bit cheaper. It should work on almost |
58 | * context switching is often a bit cheaper. It should work on almost |
59 | * all unices. Use this for GNU/Linux + glibc-2.2. glibc-2.1 and below |
59 | * all unices. Use this for GNU/Linux + glibc-2.2. glibc-2.1 and below |
60 | * do not work with any model (neither sigaltstack nor context functions |
60 | * do not work with any sane model (neither sigaltstack nor context |
61 | * are implemented) |
61 | * functions are implemented) |
|
|
62 | * |
|
|
63 | * -DCORO_LINUX |
|
|
64 | * |
|
|
65 | * Old GNU/Linux systems (<= glibc-2.1) work with this implementation |
|
|
66 | * (very fast). |
62 | * |
67 | * |
63 | * -DCORO_LOOSE |
68 | * -DCORO_LOOSE |
64 | * |
69 | * |
65 | * Microsoft's highly proprietary platform doesn't support sigaltstack, and |
70 | * Microsoft's highly proprietary platform doesn't support sigaltstack, and |
66 | * this automatically selects a suitable workaround for this platform. |
71 | * this automatically selects a suitable workaround for this platform. |
… | |
… | |
106 | |
111 | |
107 | /* |
112 | /* |
108 | * That was it. No other user-visible functions are implemented here. |
113 | * That was it. No other user-visible functions are implemented here. |
109 | */ |
114 | */ |
110 | |
115 | |
111 | #if !defined(CORO_LOOSE) && !defined(CORO_UCONTEXT) && !defined(CORO_SJLJ) |
116 | #if !defined(CORO_LOOSE) && !defined(CORO_UCONTEXT) \ |
|
|
117 | && !defined(CORO_SJLJ) && !defined(CORO_LINUX) |
112 | # if defined(WINDOWS) |
118 | # if defined(WINDOWS) |
113 | # define CORO_LOOSE 1 /* you don't win with windoze */ |
119 | # define CORO_LOOSE 1 /* you don't win with windoze */ |
|
|
120 | # elif defined(__linux) && defined(__x86) |
114 | # elif defined(HAVE_UCONTEXT_H) |
121 | # elif defined(HAVE_UCONTEXT_H) |
115 | # define CORO_UCONTEXT 1 |
122 | # define CORO_UCONTEXT 1 |
116 | # elif defined(HAVE_SETJMP_H) && defined(HAVE_SIGALTSTACK) |
123 | # elif defined(HAVE_SETJMP_H) && defined(HAVE_SIGALTSTACK) |
117 | # define CORO_SJLJ 1 |
124 | # define CORO_SJLJ 1 |
118 | # else |
125 | # else |
… | |
… | |
128 | ucontext_t uc; |
135 | ucontext_t uc; |
129 | }; |
136 | }; |
130 | |
137 | |
131 | #define coro_transfer(p,n) swapcontext(&((p)->uc), &((n)->uc)) |
138 | #define coro_transfer(p,n) swapcontext(&((p)->uc), &((n)->uc)) |
132 | |
139 | |
133 | #elif CORO_SJLJ || CORO_LOOSE |
140 | #elif CORO_SJLJ || CORO_LOOSE || CORO_LINUX |
134 | |
141 | |
135 | #include <setjmp.h> |
142 | #include <setjmp.h> |
136 | |
143 | |
137 | struct coro_context { |
144 | struct coro_context { |
138 | jmp_buf env; |
145 | jmp_buf env; |