… | |
… | |
225 | |
225 | |
226 | # if !CORO_LOSER |
226 | # if !CORO_LOSER |
227 | # include <unistd.h> |
227 | # include <unistd.h> |
228 | # endif |
228 | # endif |
229 | |
229 | |
|
|
230 | /* solaris is hopelessly borked, it expands _XOPEN_UNIX to nothing */ |
|
|
231 | # if __sun |
|
|
232 | # undef _XOPEN_UNIX |
|
|
233 | # define _XOPEN_UNIX 1 |
|
|
234 | # endif |
|
|
235 | |
230 | # include <setjmp.h> |
236 | # include <setjmp.h> |
231 | |
237 | |
232 | struct coro_context { |
238 | struct coro_context { |
|
|
239 | #if _XOPEN_UNIX > 0 || CORO_LOSER |
233 | jmp_buf env; |
240 | jmp_buf env; |
|
|
241 | #else |
|
|
242 | sigjmp_buf env; |
|
|
243 | #endif |
234 | }; |
244 | }; |
235 | |
245 | |
236 | # if _XOPEN_UNIX > 0 |
246 | # if _XOPEN_UNIX > 0 |
237 | # define coro_transfer(p,n) do { if (!_setjmp ((p)->env)) _longjmp ((n)->env, 1); } while (0) |
247 | # define coro_transfer(p,n) do { if (! _setjmp ((p)->env )) _longjmp ((n)->env, 1); } while (0) |
|
|
248 | # elif CORO_LOSER |
|
|
249 | # define coro_transfer(p,n) do { if (! setjmp ((p)->env )) longjmp ((n)->env, 1); } while (0) |
238 | # else |
250 | # else |
239 | # define coro_transfer(p,n) do { if (! setjmp ((p)->env)) longjmp ((n)->env, 1); } while (0) |
251 | # define coro_transfer(p,n) do { if (!sigsetjmp ((p)->env, 0)) siglongjmp ((n)->env, 1); } while (0) |
240 | # endif |
252 | # endif |
241 | |
253 | |
242 | # define coro_destroy(ctx) (void *)(ctx) |
254 | # define coro_destroy(ctx) (void *)(ctx) |
243 | |
255 | |
244 | #elif CORO_ASM |
256 | #elif CORO_ASM |
245 | |
257 | |
246 | struct coro_context { |
258 | struct coro_context { |
247 | volatile void **sp; /* must be at offset 0 */ |
259 | void **sp; /* must be at offset 0 */ |
248 | }; |
260 | }; |
249 | |
261 | |
250 | void __attribute__ ((__noinline__, __regparm__(2))) |
262 | void __attribute__ ((__noinline__, __regparm__(2))) |
251 | coro_transfer (coro_context *prev, coro_context *next); |
263 | coro_transfer (coro_context *prev, coro_context *next); |
252 | |
264 | |