… | |
… | |
39 | * 2006-10-26 Include stddef.h on OS X to work around one of its bugs. |
39 | * 2006-10-26 Include stddef.h on OS X to work around one of its bugs. |
40 | * Reported by Michael_G_Schwern. |
40 | * Reported by Michael_G_Schwern. |
41 | * 2006-11-26 Use _setjmp instead of setjmp on GNU/Linux. |
41 | * 2006-11-26 Use _setjmp instead of setjmp on GNU/Linux. |
42 | * 2007-04-27 Set unwind frame info if gcc 3+ and ELF is detected. |
42 | * 2007-04-27 Set unwind frame info if gcc 3+ and ELF is detected. |
43 | * Use _setjmp instead of setjmp on _XOPEN_SOURCE >= 600. |
43 | * Use _setjmp instead of setjmp on _XOPEN_SOURCE >= 600. |
|
|
44 | * 2007-05-02 Add assembly versions for x86 and amd64 (to avoid reliance |
|
|
45 | * on SIGUSR2 and sigaltstack in Crossfire). |
44 | */ |
46 | */ |
45 | |
47 | |
46 | #ifndef CORO_H |
48 | #ifndef CORO_H |
47 | #define CORO_H |
49 | #define CORO_H |
48 | |
50 | |
… | |
… | |
89 | * |
91 | * |
90 | * -DCORO_IRIX |
92 | * -DCORO_IRIX |
91 | * |
93 | * |
92 | * SGI's version of Microsoft's NT ;) |
94 | * SGI's version of Microsoft's NT ;) |
93 | * |
95 | * |
|
|
96 | * -DCORO_ASM |
|
|
97 | * |
|
|
98 | * Handcoded assembly, known to work only on a few architectures/ABI: |
|
|
99 | * ELF Linux x86 && amd64 when gcc is used and optimisation is turned on. |
|
|
100 | * |
94 | * If you define neither of these symbols, coro.h will try to autodetect |
101 | * If you define neither of these symbols, coro.h will try to autodetect |
95 | * the model. This currently works for CORO_LOSER only. For the other |
102 | * the model. This currently works for CORO_LOSER only. For the other |
96 | * alternatives you should check (e.g. using autoconf) and define the |
103 | * alternatives you should check (e.g. using autoconf) and define the |
97 | * following symbols: HAVE_UCONTEXT_H / HAVE_SETJMP_H / HAVE_SIGALTSTACK. |
104 | * following symbols: HAVE_UCONTEXT_H / HAVE_SETJMP_H / HAVE_SIGALTSTACK. |
98 | */ |
105 | */ |
… | |
… | |
136 | |
143 | |
137 | /*****************************************************************************/ |
144 | /*****************************************************************************/ |
138 | |
145 | |
139 | #if !defined(CORO_LOSER) && !defined(CORO_UCONTEXT) \ |
146 | #if !defined(CORO_LOSER) && !defined(CORO_UCONTEXT) \ |
140 | && !defined(CORO_SJLJ) && !defined(CORO_LINUX) \ |
147 | && !defined(CORO_SJLJ) && !defined(CORO_LINUX) \ |
141 | && !defined(CORO_IRIX) |
148 | && !defined(CORO_IRIX) && !defined(CORO_ASM) |
142 | # if defined(WINDOWS) |
149 | # if defined(WINDOWS) |
143 | # define CORO_LOSER 1 /* you don't win with windoze */ |
150 | # define CORO_LOSER 1 /* you don't win with windoze */ |
144 | # elif defined(__linux) && defined(__x86) |
151 | # elif defined(__linux) && (defined(__x86) || defined (__amd64)) |
|
|
152 | # define CORO_ASM 1 |
145 | # elif defined(HAVE_UCONTEXT_H) |
153 | # elif defined(HAVE_UCONTEXT_H) |
146 | # define CORO_UCONTEXT 1 |
154 | # define CORO_UCONTEXT 1 |
147 | # elif defined(HAVE_SETJMP_H) && defined(HAVE_SIGALTSTACK) |
155 | # elif defined(HAVE_SETJMP_H) && defined(HAVE_SIGALTSTACK) |
148 | # define CORO_SJLJ 1 |
156 | # define CORO_SJLJ 1 |
149 | # else |
157 | # else |
… | |
… | |
153 | |
161 | |
154 | /*****************************************************************************/ |
162 | /*****************************************************************************/ |
155 | |
163 | |
156 | #if CORO_UCONTEXT |
164 | #if CORO_UCONTEXT |
157 | |
165 | |
158 | #include <ucontext.h> |
166 | # include <ucontext.h> |
159 | |
167 | |
160 | struct coro_context { |
168 | struct coro_context { |
161 | ucontext_t uc; |
169 | ucontext_t uc; |
162 | }; |
170 | }; |
163 | |
171 | |
164 | #define coro_transfer(p,n) swapcontext (&((p)->uc), &((n)->uc)) |
172 | # define coro_transfer(p,n) swapcontext (&((p)->uc), &((n)->uc)) |
165 | |
173 | |
166 | #elif CORO_SJLJ || CORO_LOSER || CORO_LINUX || CORO_IRIX |
174 | #elif CORO_SJLJ || CORO_LOSER || CORO_LINUX || CORO_IRIX |
167 | |
175 | |
168 | #if defined(CORO_LINUX) && !defined(_GNU_SOURCE) |
176 | # if defined(CORO_LINUX) && !defined(_GNU_SOURCE) |
169 | # define _GNU_SOURCE /* for linux libc */ |
177 | # define _GNU_SOURCE /* for linux libc */ |
170 | #endif |
178 | # endif |
171 | |
179 | |
172 | #include <setjmp.h> |
180 | # include <setjmp.h> |
173 | |
181 | |
174 | struct coro_context { |
182 | struct coro_context { |
175 | jmp_buf env; |
183 | jmp_buf env; |
176 | }; |
184 | }; |
177 | |
185 | |
178 | #if CORO_LINUX || (_XOPEN_SOURCE >= 600) |
186 | # if CORO_LINUX || (_XOPEN_SOURCE >= 600) |
179 | # define coro_transfer(p,n) do { if (!_setjmp ((p)->env)) _longjmp ((n)->env, 1); } while (0) |
187 | # define coro_transfer(p,n) do { if (!_setjmp ((p)->env)) _longjmp ((n)->env, 1); } while (0) |
180 | #else |
188 | # else |
181 | # define coro_transfer(p,n) do { if (!setjmp ((p)->env)) longjmp ((n)->env, 1); } while (0) |
189 | # define coro_transfer(p,n) do { if (!setjmp ((p)->env)) longjmp ((n)->env, 1); } while (0) |
|
|
190 | # endif |
|
|
191 | |
|
|
192 | #elif CORO_ASM |
|
|
193 | |
|
|
194 | struct coro_context { |
|
|
195 | volatile void **sp; |
|
|
196 | }; |
|
|
197 | |
|
|
198 | void __attribute__ ((__noinline__, __fastcall__)) |
|
|
199 | coro_transfer(coro_context *prev, coro_context *next); |
|
|
200 | |
182 | #endif |
201 | #endif |
183 | |
202 | |
184 | #endif |
203 | #endif |
185 | |
204 | |
186 | #endif |
|
|
187 | |
|
|