--- libcoro/coro.h 2005/08/20 01:07:45 1.12 +++ libcoro/coro.h 2007/04/27 19:35:28 1.21 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001-2005 Marc Alexander Lehmann + * Copyright (c) 2001-2006 Marc Alexander Lehmann * * Redistribution and use in source and binary forms, with or without modifica- * tion, are permitted provided that the following conditions are met: @@ -35,6 +35,14 @@ * */ +/* + * 2006-10-26 Include stddef.h on OS X to work around one of its bugs. + * Reported by Michael_G_Schwern. + * 2006-11-26 Use _setjmp instead of setjmp on GNU/Linux. + * 2007-04-27 Set unwind frame info if gcc 3+ and ELF is detected. + * Use _setjmp instead of setjmp on _XOPEN_SOURCE >= 600. + */ + #ifndef CORO_H #define CORO_H @@ -57,11 +65,11 @@ * * This flavour uses SUSv2's get/set/swap/makecontext functions that * unfortunately only newer unices support. - * Use this for GNU/Linux + glibc-2.2.3. + * Use this for GNU/Linux + glibc-2.2.3 and possibly higher. * * -DCORO_SJLJ * - * This flavour uses SUSv'2 setjmp/longjmp and sigaltstack functions to + * This flavour uses SUSv2's setjmp/longjmp and sigaltstack functions to * do it's job. Coroutine creation is much slower than UCONTEXT, but * context switching is often a bit cheaper. It should work on almost * all unices. Use this for GNU/Linux + glibc-2.2. glibc-2.1 and below @@ -71,7 +79,7 @@ * -DCORO_LINUX * * Old GNU/Linux systems (<= glibc-2.1) work with this implementation - * (very fast). + * (it is very fast and therefore recommended over other methods). * * -DCORO_LOSER * @@ -95,23 +103,25 @@ typedef void (*coro_func)(void *); /* - * A coroutine state is saved in the following structure. Treat it as a + * A coroutine state is saved in the following structure. Treat it as an * opaque type. errno and sigmask might be saved, but don't rely on it, - * implement your own switching primitive. + * implement your own switching primitive if you need that. */ typedef struct coro_context coro_context; /* * This function creates a new coroutine. Apart from a pointer to an - * uninitialized coro_context, it expects a pointer to the entry function + * uninitialised coro_context, it expects a pointer to the entry function * and the single pointer value that is given to it as argument. * * Allocating/deallocating the stack is your own responsibility, so there is * no coro_destroy function. */ -void coro_create (coro_context *ctx, - coro_func coro, void *arg, - void *sptr, long ssize); +void coro_create (coro_context *ctx, /* an uninitialised coro_context */ + coro_func coro, /* the coroutine code to be executed */ + void *arg, /* a single pointer passed to the coro */ + void *sptr, /* start of stack area */ + long ssize); /* size of stack area */ /* * The following prototype defines the coroutine switching function. It is @@ -156,7 +166,7 @@ #elif CORO_SJLJ || CORO_LOSER || CORO_LINUX || CORO_IRIX #if defined(CORO_LINUX) && !defined(_GNU_SOURCE) -# define _GNU_SOURCE // for linux libc +# define _GNU_SOURCE /* for linux libc */ #endif #include @@ -165,7 +175,11 @@ jmp_buf env; }; -#define coro_transfer(p,n) do { if (!setjmp ((p)->env)) longjmp ((n)->env, 1); } while(0) +#if CORO_LINUX || (_XOPEN_SOURCE >= 600) +# define coro_transfer(p,n) do { if (!_setjmp ((p)->env)) _longjmp ((n)->env, 1); } while (0) +#else +# define coro_transfer(p,n) do { if (!setjmp ((p)->env)) longjmp ((n)->env, 1); } while (0) +#endif #endif