… | |
… | |
51 | * Use _setjmp instead of setjmp on _XOPEN_SOURCE >= 600. |
51 | * Use _setjmp instead of setjmp on _XOPEN_SOURCE >= 600. |
52 | * 2007-05-02 Add assembly versions for x86 and amd64 (to avoid reliance |
52 | * 2007-05-02 Add assembly versions for x86 and amd64 (to avoid reliance |
53 | * on SIGUSR2 and sigaltstack in Crossfire). |
53 | * on SIGUSR2 and sigaltstack in Crossfire). |
54 | * 2008-01-21 Disable CFI usage on anything but GNU/Linux. |
54 | * 2008-01-21 Disable CFI usage on anything but GNU/Linux. |
55 | * 2008-03-02 Switched to 2-clause BSD license with GPL exception. |
55 | * 2008-03-02 Switched to 2-clause BSD license with GPL exception. |
|
|
56 | * 2008-04-04 New (but highly unrecommended) pthreads backend. |
|
|
57 | * 2008-04-24 Reinstate CORO_LOSER (had wrong stack adjustments). |
56 | */ |
58 | */ |
57 | |
59 | |
58 | #ifndef CORO_H |
60 | #ifndef CORO_H |
59 | #define CORO_H |
61 | #define CORO_H |
60 | |
62 | |
… | |
… | |
103 | * |
105 | * |
104 | * -DCORO_ASM |
106 | * -DCORO_ASM |
105 | * |
107 | * |
106 | * Handcoded assembly, known to work only on a few architectures/ABI: |
108 | * Handcoded assembly, known to work only on a few architectures/ABI: |
107 | * ELF Linux x86 && amd64 when gcc is used and optimisation is turned on. |
109 | * ELF Linux x86 && amd64 when gcc is used and optimisation is turned on. |
|
|
110 | * |
|
|
111 | * -DCORO_PTHREAD |
|
|
112 | * |
|
|
113 | * Use the pthread API. You have to provide <pthread.h> and -lpthread. |
108 | * |
114 | * |
109 | * If you define neither of these symbols, coro.h will try to autodetect |
115 | * If you define neither of these symbols, coro.h will try to autodetect |
110 | * the model. This currently works for CORO_LOSER only. For the other |
116 | * the model. This currently works for CORO_LOSER only. For the other |
111 | * alternatives you should check (e.g. using autoconf) and define the |
117 | * alternatives you should check (e.g. using autoconf) and define the |
112 | * following symbols: HAVE_UCONTEXT_H / HAVE_SETJMP_H / HAVE_SIGALTSTACK. |
118 | * following symbols: HAVE_UCONTEXT_H / HAVE_SETJMP_H / HAVE_SIGALTSTACK. |
… | |
… | |
151 | |
157 | |
152 | /*****************************************************************************/ |
158 | /*****************************************************************************/ |
153 | |
159 | |
154 | #if !defined(CORO_LOSER) && !defined(CORO_UCONTEXT) \ |
160 | #if !defined(CORO_LOSER) && !defined(CORO_UCONTEXT) \ |
155 | && !defined(CORO_SJLJ) && !defined(CORO_LINUX) \ |
161 | && !defined(CORO_SJLJ) && !defined(CORO_LINUX) \ |
156 | && !defined(CORO_IRIX) && !defined(CORO_ASM) |
162 | && !defined(CORO_IRIX) && !defined(CORO_ASM) \ |
|
|
163 | && !defined(CORO_PTHREAD) |
157 | # if defined(WINDOWS) |
164 | # if defined(WINDOWS) |
158 | # define CORO_LOSER 1 /* you don't win with windoze */ |
165 | # define CORO_LOSER 1 /* you don't win with windoze */ |
159 | # elif defined(__linux) && (defined(__x86) || defined (__amd64)) |
166 | # elif defined(__linux) && (defined(__x86) || defined (__amd64)) |
160 | # define CORO_ASM 1 |
167 | # define CORO_ASM 1 |
161 | # elif defined(HAVE_UCONTEXT_H) |
168 | # elif defined(HAVE_UCONTEXT_H) |
… | |
… | |
201 | |
208 | |
202 | struct coro_context { |
209 | struct coro_context { |
203 | volatile void **sp; |
210 | volatile void **sp; |
204 | }; |
211 | }; |
205 | |
212 | |
206 | void __attribute__ ((__noinline__, __fastcall__)) |
213 | void __attribute__ ((__noinline__, __regparm__(2))) |
207 | coro_transfer(coro_context *prev, coro_context *next); |
214 | coro_transfer (coro_context *prev, coro_context *next); |
|
|
215 | |
|
|
216 | #elif CORO_PTHREAD |
|
|
217 | |
|
|
218 | #include <pthread.h> |
|
|
219 | |
|
|
220 | extern pthread_mutex_t coro_mutex; |
|
|
221 | |
|
|
222 | struct coro_context { |
|
|
223 | pthread_cond_t c; |
|
|
224 | }; |
|
|
225 | |
|
|
226 | void coro_transfer (coro_context *prev, coro_context *next); |
208 | |
227 | |
209 | #endif |
228 | #endif |
210 | |
229 | |
211 | #endif |
230 | #endif |
212 | |
231 | |