… | |
… | |
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 | |
… | |
… | |
146 | * and the single pointer value that is given to it as argument. |
147 | * and the single pointer value that is given to it as argument. |
147 | * |
148 | * |
148 | * Allocating/deallocating the stack is your own responsibility. |
149 | * Allocating/deallocating the stack is your own responsibility. |
149 | * |
150 | * |
150 | * As a special case, if coro, arg, sptr and ssize are all zero, |
151 | * As a special case, if coro, arg, sptr and ssize are all zero, |
151 | * then an "empty" coro_contetx will be created that is suitable |
152 | * then an "empty" coro_context will be created that is suitable |
152 | * as an initial source for coro_transfer. |
153 | * as an initial source for coro_transfer. |
153 | * |
154 | * |
154 | * This function is not reentrant, but putting a mutex around it |
155 | * This function is not reentrant, but putting a mutex around it |
155 | * will work. |
156 | * will work. |
156 | */ |
157 | */ |
… | |
… | |
171 | #endif |
172 | #endif |
172 | |
173 | |
173 | /* |
174 | /* |
174 | * The following prototype defines the coroutine destroy function. It is |
175 | * The following prototype defines the coroutine destroy function. It is |
175 | * usually implemented as a macro, so watch out. It also serves |
176 | * usually implemented as a macro, so watch out. It also serves |
176 | * no purpose unless you want to use the CORO_PTHREAD backend. |
177 | * no purpose unless you want to use the CORO_PTHREAD backend, |
|
|
178 | * where it is used to clean up the thread. You are responsible |
|
|
179 | * for freeing the stack and the context itself. |
177 | * |
180 | * |
178 | * This function is thread-safe and reentrant. |
181 | * This function is thread-safe and reentrant. |
179 | */ |
182 | */ |
180 | #if 0 |
183 | #if 0 |
181 | void coro_destroy (coro_context *ctx); |
184 | void coro_destroy (coro_context *ctx); |
… | |
… | |
225 | |
228 | |
226 | # if !CORO_LOSER |
229 | # if !CORO_LOSER |
227 | # include <unistd.h> |
230 | # include <unistd.h> |
228 | # endif |
231 | # endif |
229 | |
232 | |
|
|
233 | /* solaris is hopelessly borked, it expands _XOPEN_UNIX to nothing */ |
|
|
234 | # if __sun |
|
|
235 | # undef _XOPEN_UNIX |
|
|
236 | # define _XOPEN_UNIX 1 |
|
|
237 | # endif |
|
|
238 | |
230 | # include <setjmp.h> |
239 | # include <setjmp.h> |
231 | |
240 | |
232 | struct coro_context { |
241 | struct coro_context { |
|
|
242 | #if _XOPEN_UNIX > 0 || CORO_LOSER |
233 | jmp_buf env; |
243 | jmp_buf env; |
|
|
244 | #else |
|
|
245 | sigjmp_buf env; |
|
|
246 | #endif |
234 | }; |
247 | }; |
235 | |
248 | |
236 | # if _XOPEN_UNIX > 0 |
249 | # if _XOPEN_UNIX > 0 |
237 | # define coro_transfer(p,n) do { if (! _setjmp ((p)->env )) _longjmp ((n)->env, 1); } while (0) |
250 | # define coro_transfer(p,n) do { if (! _setjmp ((p)->env )) _longjmp ((n)->env, 1); } while (0) |
238 | # elif CORO_LOSER |
251 | # elif CORO_LOSER |