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

Comparing libcoro/coro.c (file contents):
Revision 1.39 by root, Sat Nov 8 04:31:28 2008 UTC vs.
Revision 1.40 by root, Sat Nov 8 04:52:01 2008 UTC

74# include <stdio.h> 74# include <stdio.h>
75# include <signal.h> 75# include <signal.h>
76# include <unistd.h> 76# include <unistd.h>
77# endif 77# endif
78 78
79static volatile coro_func coro_init_func; 79static coro_func coro_init_func;
80static volatile void *coro_init_arg; 80static void *coro_init_arg;
81static volatile coro_context *new_coro, *create_coro; 81static coro_context *new_coro, *create_coro;
82 82
83/* what we really want to detect here is wether we use a new-enough version of GAS */ 83/* what we really want to detect here is wether we use a new-enough version of GAS */
84/* with dwarf debug info. instead, check for gcc 3, ELF and GNU/Linux and hope for the best */ 84/* with dwarf debug info. instead, check for gcc 3, ELF and GNU/Linux and hope for the best */
85# if __GNUC__ >= 3 && __ELF__ && __linux__ 85# if __GNUC__ >= 3 && __ELF__ && __linux__
86# define HAVE_CFI 1 86# define HAVE_CFI 1
90coro_init (void) 90coro_init (void)
91{ 91{
92 volatile coro_func func = coro_init_func; 92 volatile coro_func func = coro_init_func;
93 volatile void *arg = coro_init_arg; 93 volatile void *arg = coro_init_arg;
94 94
95 coro_transfer ((coro_context *)new_coro, (coro_context *)create_coro); 95 coro_transfer (new_coro, create_coro);
96 96
97 func ((void *)arg); 97 func ((void *)arg);
98 98
99 /* the new coro returned. bad. just abort() for now */ 99 /* the new coro returned. bad. just abort() for now */
100 abort (); 100 abort ();
110{ 110{
111 if ( 111 if (
112 #if _XOPEN_UNIX > 0 112 #if _XOPEN_UNIX > 0
113 _setjmp (new_coro->env) 113 _setjmp (new_coro->env)
114 #else 114 #else
115 setjmp (new_coro->env) 115 sigsetjmp (new_coro->env, 0)
116 #endif 116 #endif
117 ) { 117 ) {
118 #if HAVE_CFI 118 #if HAVE_CFI
119 asm (".cfi_startproc"); 119 asm (".cfi_startproc");
120 #endif 120 #endif
279 #error "linux libc or architecture not supported" 279 #error "linux libc or architecture not supported"
280 #endif 280 #endif
281 281
282# elif CORO_IRIX 282# elif CORO_IRIX
283 283
284 setjmp (ctx->env); 284 sigsetjmp (ctx->env, 0);
285 ctx->env[JB_PC] = (__uint64_t)coro_init; 285 ctx->env[JB_PC] = (__uint64_t)coro_init;
286 ctx->env[JB_SP] = (__uint64_t)STACK_ADJUST_PTR (sptr, ssize) - sizeof (long); 286 ctx->env[JB_SP] = (__uint64_t)STACK_ADJUST_PTR (sptr, ssize) - sizeof (long);
287 287
288# elif CORO_ASM 288# elif CORO_ASM
289 289
306# endif 306# endif
307 307
308 coro_transfer (create_coro, new_coro); 308 coro_transfer (create_coro, new_coro);
309} 309}
310 310
311#endif
312
313/*****************************************************************************/ 311/*****************************************************************************/
314/* pthread backend */ 312/* pthread backend */
315/*****************************************************************************/ 313/*****************************************************************************/
316
317#if CORO_PTHREAD 314#elif CORO_PTHREAD
318 315
319/* this mutex will be locked by the running coroutine */ 316/* this mutex will be locked by the running coroutine */
320pthread_mutex_t coro_mutex = PTHREAD_MUTEX_INITIALIZER; 317pthread_mutex_t coro_mutex = PTHREAD_MUTEX_INITIALIZER;
321 318
322struct coro_init_args 319struct coro_init_args
410 } 407 }
411 408
412 pthread_cond_destroy (&ctx->cv); 409 pthread_cond_destroy (&ctx->cv);
413} 410}
414 411
412#else
413# error unsupported backend
415#endif 414#endif
416 415

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines