--- cvsroot/libcoro/coro.c 2008/11/08 04:31:28 1.39 +++ cvsroot/libcoro/coro.c 2008/11/16 00:55:41 1.43 @@ -76,15 +76,9 @@ # include # endif -static volatile coro_func coro_init_func; -static volatile void *coro_init_arg; -static volatile coro_context *new_coro, *create_coro; - -/* what we really want to detect here is wether we use a new-enough version of GAS */ -/* with dwarf debug info. instead, check for gcc 3, ELF and GNU/Linux and hope for the best */ -# if __GNUC__ >= 3 && __ELF__ && __linux__ -# define HAVE_CFI 1 -# endif +static coro_func coro_init_func; +static void *coro_init_arg; +static coro_context *new_coro, *create_coro; static void coro_init (void) @@ -92,7 +86,7 @@ volatile coro_func func = coro_init_func; volatile void *arg = coro_init_arg; - coro_transfer ((coro_context *)new_coro, (coro_context *)create_coro); + coro_transfer (new_coro, create_coro); func ((void *)arg); @@ -112,16 +106,10 @@ #if _XOPEN_UNIX > 0 _setjmp (new_coro->env) #else - setjmp (new_coro->env) + sigsetjmp (new_coro->env, 0) #endif ) { - #if HAVE_CFI - asm (".cfi_startproc"); - #endif coro_init (); /* start it */ - #if HAVE_CFI - asm (".cfi_endproc"); - #endif } else trampoline_done = 1; @@ -281,13 +269,13 @@ # elif CORO_IRIX - setjmp (ctx->env); + sigsetjmp (ctx->env, 0); ctx->env[JB_PC] = (__uint64_t)coro_init; ctx->env[JB_SP] = (__uint64_t)STACK_ADJUST_PTR (sptr, ssize) - sizeof (long); # elif CORO_ASM - ctx->sp = (volatile void **)(ssize + (char *)sptr); + ctx->sp = (void **)(ssize + (char *)sptr); *--ctx->sp = (void *)abort; /* needed for alignment only */ *--ctx->sp = (void *)coro_init; ctx->sp -= NUM_SAVED; @@ -308,13 +296,10 @@ coro_transfer (create_coro, new_coro); } -#endif - /*****************************************************************************/ /* pthread backend */ /*****************************************************************************/ - -#if CORO_PTHREAD +#elif CORO_PTHREAD /* this mutex will be locked by the running coroutine */ pthread_mutex_t coro_mutex = PTHREAD_MUTEX_INITIALIZER; @@ -358,6 +343,9 @@ { pthread_cond_signal (&next->cv); pthread_cond_wait (&prev->cv, &coro_mutex); +#if __FreeBSD__ /* freebsd is of course broken and needs manual testcancel calls... yay... */ + pthread_testcancel (); +#endif } void @@ -412,5 +400,7 @@ pthread_cond_destroy (&ctx->cv); } +#else +# error unsupported backend #endif