ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libcoro/coro.h
(Generate patch)

Comparing libcoro/coro.h (file contents):
Revision 1.19 by root, Thu Nov 30 18:21:14 2006 UTC vs.
Revision 1.22 by root, Wed May 2 05:53:26 2007 UTC

37 37
38/* 38/*
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.
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).
42 */ 46 */
43 47
44#ifndef CORO_H 48#ifndef CORO_H
45#define CORO_H 49#define CORO_H
46 50
87 * 91 *
88 * -DCORO_IRIX 92 * -DCORO_IRIX
89 * 93 *
90 * SGI's version of Microsoft's NT ;) 94 * SGI's version of Microsoft's NT ;)
91 * 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 *
92 * 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
93 * 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
94 * alternatives you should check (e.g. using autoconf) and define the 103 * alternatives you should check (e.g. using autoconf) and define the
95 * following symbols: HAVE_UCONTEXT_H / HAVE_SETJMP_H / HAVE_SIGALTSTACK. 104 * following symbols: HAVE_UCONTEXT_H / HAVE_SETJMP_H / HAVE_SIGALTSTACK.
96 */ 105 */
134 143
135/*****************************************************************************/ 144/*****************************************************************************/
136 145
137#if !defined(CORO_LOSER) && !defined(CORO_UCONTEXT) \ 146#if !defined(CORO_LOSER) && !defined(CORO_UCONTEXT) \
138 && !defined(CORO_SJLJ) && !defined(CORO_LINUX) \ 147 && !defined(CORO_SJLJ) && !defined(CORO_LINUX) \
139 && !defined(CORO_IRIX) 148 && !defined(CORO_IRIX) && !defined(CORO_ASM)
140# if defined(WINDOWS) 149# if defined(WINDOWS)
141# define CORO_LOSER 1 /* you don't win with windoze */ 150# define CORO_LOSER 1 /* you don't win with windoze */
142# elif defined(__linux) && defined(__x86) 151# elif defined(__linux) && (defined(__x86) || defined (__amd64))
152# define CORO_ASM 1
143# elif defined(HAVE_UCONTEXT_H) 153# elif defined(HAVE_UCONTEXT_H)
144# define CORO_UCONTEXT 1 154# define CORO_UCONTEXT 1
145# elif defined(HAVE_SETJMP_H) && defined(HAVE_SIGALTSTACK) 155# elif defined(HAVE_SETJMP_H) && defined(HAVE_SIGALTSTACK)
146# define CORO_SJLJ 1 156# define CORO_SJLJ 1
147# else 157# else
151 161
152/*****************************************************************************/ 162/*****************************************************************************/
153 163
154#if CORO_UCONTEXT 164#if CORO_UCONTEXT
155 165
156#include <ucontext.h> 166# include <ucontext.h>
157 167
158struct coro_context { 168struct coro_context {
159 ucontext_t uc; 169 ucontext_t uc;
160}; 170};
161 171
162#define coro_transfer(p,n) swapcontext (&((p)->uc), &((n)->uc)) 172# define coro_transfer(p,n) swapcontext (&((p)->uc), &((n)->uc))
163 173
164#elif CORO_SJLJ || CORO_LOSER || CORO_LINUX || CORO_IRIX 174#elif CORO_SJLJ || CORO_LOSER || CORO_LINUX || CORO_IRIX
165 175
166#if defined(CORO_LINUX) && !defined(_GNU_SOURCE) 176# if defined(CORO_LINUX) && !defined(_GNU_SOURCE)
167# define _GNU_SOURCE /* for linux libc */ 177# define _GNU_SOURCE /* for linux libc */
168#endif 178# endif
169 179
170#include <setjmp.h> 180# include <setjmp.h>
171 181
172struct coro_context { 182struct coro_context {
173 jmp_buf env; 183 jmp_buf env;
174}; 184};
175 185
176#if CORO_LINUX 186# if CORO_LINUX || (_XOPEN_SOURCE >= 600)
177# 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)
178#else 188# else
179# 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
194struct coro_context {
195 volatile void **sp;
196};
197
198void __attribute__ ((__noinline__, __fastcall__))
199 coro_transfer(coro_context *prev, coro_context *next);
200
180#endif 201#endif
181 202
182#endif 203#endif
183 204
184#endif
185

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines