… | |
… | |
63 | * speed up CORO_PTHREAD. Do no longer leak threads either. |
63 | * speed up CORO_PTHREAD. Do no longer leak threads either. |
64 | * coro_create now allows one to create source coro_contexts. |
64 | * coro_create now allows one to create source coro_contexts. |
65 | * do not rely on makecontext passing a void * correctly. |
65 | * do not rely on makecontext passing a void * correctly. |
66 | * try harder to get _setjmp/_longjmp. |
66 | * try harder to get _setjmp/_longjmp. |
67 | * major code cleanup/restructuring. |
67 | * major code cleanup/restructuring. |
|
|
68 | * 2008-11-10 the .cfi hacks are no longer needed. |
68 | */ |
69 | */ |
69 | |
70 | |
70 | #ifndef CORO_H |
71 | #ifndef CORO_H |
71 | #define CORO_H |
72 | #define CORO_H |
72 | |
73 | |
… | |
… | |
225 | |
226 | |
226 | # if !CORO_LOSER |
227 | # if !CORO_LOSER |
227 | # include <unistd.h> |
228 | # include <unistd.h> |
228 | # endif |
229 | # endif |
229 | |
230 | |
|
|
231 | /* solaris is hopelessly borked, it expands _XOPEN_UNIX to nothing */ |
|
|
232 | # if __sun |
|
|
233 | # undef _XOPEN_UNIX |
|
|
234 | # define _XOPEN_UNIX 1 |
|
|
235 | # endif |
|
|
236 | |
230 | # include <setjmp.h> |
237 | # include <setjmp.h> |
231 | |
238 | |
232 | struct coro_context { |
239 | struct coro_context { |
|
|
240 | #if _XOPEN_UNIX > 0 || CORO_LOSER |
233 | jmp_buf env; |
241 | jmp_buf env; |
|
|
242 | #else |
|
|
243 | sigjmp_buf env; |
|
|
244 | #endif |
234 | }; |
245 | }; |
235 | |
246 | |
236 | # if _XOPEN_UNIX > 0 |
247 | # if _XOPEN_UNIX > 0 |
237 | # define coro_transfer(p,n) do { if (!_setjmp ((p)->env)) _longjmp ((n)->env, 1); } while (0) |
248 | # define coro_transfer(p,n) do { if (! _setjmp ((p)->env )) _longjmp ((n)->env, 1); } while (0) |
|
|
249 | # elif CORO_LOSER |
|
|
250 | # define coro_transfer(p,n) do { if (! setjmp ((p)->env )) longjmp ((n)->env, 1); } while (0) |
238 | # else |
251 | # else |
239 | # define coro_transfer(p,n) do { if (! setjmp ((p)->env)) longjmp ((n)->env, 1); } while (0) |
252 | # define coro_transfer(p,n) do { if (!sigsetjmp ((p)->env, 0)) siglongjmp ((n)->env, 1); } while (0) |
240 | # endif |
253 | # endif |
241 | |
254 | |
242 | # define coro_destroy(ctx) (void *)(ctx) |
255 | # define coro_destroy(ctx) (void *)(ctx) |
243 | |
256 | |
244 | #elif CORO_ASM |
257 | #elif CORO_ASM |
245 | |
258 | |
246 | struct coro_context { |
259 | struct coro_context { |
247 | volatile void **sp; /* must be at offset 0 */ |
260 | void **sp; /* must be at offset 0 */ |
248 | }; |
261 | }; |
249 | |
262 | |
250 | void __attribute__ ((__noinline__, __regparm__(2))) |
263 | void __attribute__ ((__noinline__, __regparm__(2))) |
251 | coro_transfer (coro_context *prev, coro_context *next); |
264 | coro_transfer (coro_context *prev, coro_context *next); |
252 | |
265 | |