--- libcoro/coro.h 2008/11/14 05:27:08 1.38 +++ libcoro/coro.h 2011/05/30 02:32:06 1.46 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001-2008 Marc Alexander Lehmann + * Copyright (c) 2001-2009 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: @@ -66,11 +66,21 @@ * try harder to get _setjmp/_longjmp. * major code cleanup/restructuring. * 2008-11-10 the .cfi hacks are no longer needed. + * 2008-11-16 work around a freebsd pthread bug. + * 2008-11-19 define coro_*jmp symbols for easier porting. + * 2009-06-23 tentative win32-backend support for mingw32 (Yasuhiro Matsumoto). + * 2010-12-03 tentative support for uclibc (which lacks all sorts of things). + * 2011-05-30 set initial callee-saved-registers to zero with CORO_ASM. + * use .cfi_undefined rip on linux-elf for better backtraces. */ #ifndef CORO_H #define CORO_H +#if __cplusplus +extern "C" { +#endif + #define CORO_VERSION 2 /* @@ -117,11 +127,13 @@ * -DCORO_ASM * * Handcoded assembly, known to work only on a few architectures/ABI: - * ELF Linux x86 && amd64 when gcc is used and optimisation is turned on. + * GCC + x86/IA32 and amd64/x86_64 + GNU/Linux and a few BSDs. * * -DCORO_PTHREAD * * Use the pthread API. You have to provide and -lpthread. + * This is likely the slowest backend, and it also does not support fork(), + * so avoid it at all costs. * * If you define neither of these symbols, coro.h will try to autodetect * the model. This currently works for CORO_LOSER only. For the other @@ -238,22 +250,25 @@ # include -struct coro_context { -#if _XOPEN_UNIX > 0 || CORO_LOSER - jmp_buf env; -#else - sigjmp_buf env; -#endif -}; - -# if _XOPEN_UNIX > 0 -# define coro_transfer(p,n) do { if (! _setjmp ((p)->env )) _longjmp ((n)->env, 1); } while (0) +# if _XOPEN_UNIX > 0 || defined (_setjmp) +# define coro_jmp_buf jmp_buf +# define coro_setjmp(env) _setjmp (env) +# define coro_longjmp(env) _longjmp ((env), 1) # elif CORO_LOSER -# define coro_transfer(p,n) do { if (! setjmp ((p)->env )) longjmp ((n)->env, 1); } while (0) +# define coro_jmp_buf jmp_buf +# define coro_setjmp(env) setjmp (env) +# define coro_longjmp(env) longjmp ((env), 1) # else -# define coro_transfer(p,n) do { if (!sigsetjmp ((p)->env, 0)) siglongjmp ((n)->env, 1); } while (0) +# define coro_jmp_buf sigjmp_buf +# define coro_setjmp(env) sigsetjmp (env, 0) +# define coro_longjmp(env) siglongjmp ((env), 1) # endif +struct coro_context { + coro_jmp_buf env; +}; + +# define coro_transfer(p,n) do { if (!coro_setjmp ((p)->env)) coro_longjmp ((n)->env); } while (0) # define coro_destroy(ctx) (void *)(ctx) #elif CORO_ASM @@ -283,5 +298,9 @@ #endif +#if __cplusplus +} +#endif + #endif