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

Comparing libcoro/coro.h (file contents):
Revision 1.6 by root, Sun Sep 16 01:34:36 2001 UTC vs.
Revision 1.8 by root, Wed Jan 12 20:35:35 2005 UTC

28 * This library is modelled strictly after Ralf S. Engelschalls article at 28 * This library is modelled strictly after Ralf S. Engelschalls article at
29 * http://www.gnu.org/software/pth/rse-pmt.ps. So most of the credit must 29 * http://www.gnu.org/software/pth/rse-pmt.ps. So most of the credit must
30 * go to Ralf S. Engelschall <rse@engelschall.com>. 30 * go to Ralf S. Engelschall <rse@engelschall.com>.
31 * 31 *
32 * This coroutine library is very much stripped down. You should either 32 * This coroutine library is very much stripped down. You should either
33 * build your own process avstraction using it or - better - just use GNU 33 * build your own process abstraction using it or - better - just use GNU
34 * Portable Threads, http://www.gnu.org/software/pth/. 34 * Portable Threads, http://www.gnu.org/software/pth/.
35 * 35 *
36 * VERSION: 0.1 36 * VERSION: 0.1
37 */ 37 */
38 38
101 * and the single pointer value that is given to it as argument. 101 * and the single pointer value that is given to it as argument.
102 * 102 *
103 * Allocating/deallocating the stack is your own responsibility, so there is 103 * Allocating/deallocating the stack is your own responsibility, so there is
104 * no coro_destroy function. 104 * no coro_destroy function.
105 */ 105 */
106void coro_create(coro_context *ctx, 106void coro_create (coro_context *ctx,
107 coro_func coro, void *arg, 107 coro_func coro, void *arg,
108 void *sptr, long ssize); 108 void *sptr, long ssize);
109 109
110/* 110/*
111 * The following prototype defines the coroutine switching function. It is 111 * The following prototype defines the coroutine switching function. It is
112 * usually implemented as a macro, so watch out. 112 * usually implemented as a macro, so watch out.
113 * 113 *
143 143
144struct coro_context { 144struct coro_context {
145 ucontext_t uc; 145 ucontext_t uc;
146}; 146};
147 147
148#define coro_transfer(p,n) swapcontext(&((p)->uc), &((n)->uc)) 148#define coro_transfer(p,n) swapcontext (&((p)->uc), &((n)->uc))
149 149
150#elif CORO_SJLJ || CORO_LOOSE || CORO_LINUX || CORO_IRIX 150#elif CORO_SJLJ || CORO_LOOSE || CORO_LINUX || CORO_IRIX
151
152#ifdef CORO_LINUX
153# define _GNU_SOURCE // for linux libc
154#endif
151 155
152#include <setjmp.h> 156#include <setjmp.h>
153 157
154struct coro_context { 158struct coro_context {
155 jmp_buf env; 159 jmp_buf env;
156}; 160};
157 161
158#define coro_transfer(p,n) if (!setjmp ((p)->env)) longjmp ((n)->env, 1) 162#define coro_transfer(p,n) do { if (!setjmp ((p)->env)) longjmp ((n)->env, 1); } while(0)
159 163
160#endif 164#endif
161 165
162#endif 166#endif
163 167

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines