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

Comparing cvsroot/libcoro/coro.c (file contents):
Revision 1.39 by root, Sat Nov 8 04:31:28 2008 UTC vs.
Revision 1.42 by root, Mon Nov 10 04:37:23 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
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 */
85# if __GNUC__ >= 3 && __ELF__ && __linux__
86# define HAVE_CFI 1
87# endif
88 82
89static void 83static void
90coro_init (void) 84coro_init (void)
91{ 85{
92 volatile coro_func func = coro_init_func; 86 volatile coro_func func = coro_init_func;
93 volatile void *arg = coro_init_arg; 87 volatile void *arg = coro_init_arg;
94 88
95 coro_transfer ((coro_context *)new_coro, (coro_context *)create_coro); 89 coro_transfer (new_coro, create_coro);
96 90
97 func ((void *)arg); 91 func ((void *)arg);
98 92
99 /* the new coro returned. bad. just abort() for now */ 93 /* the new coro returned. bad. just abort() for now */
100 abort (); 94 abort ();
110{ 104{
111 if ( 105 if (
112 #if _XOPEN_UNIX > 0 106 #if _XOPEN_UNIX > 0
113 _setjmp (new_coro->env) 107 _setjmp (new_coro->env)
114 #else 108 #else
115 setjmp (new_coro->env) 109 sigsetjmp (new_coro->env, 0)
116 #endif 110 #endif
117 ) { 111 ) {
118 #if HAVE_CFI
119 asm (".cfi_startproc");
120 #endif
121 coro_init (); /* start it */ 112 coro_init (); /* start it */
122 #if HAVE_CFI
123 asm (".cfi_endproc");
124 #endif
125 } 113 }
126 else 114 else
127 trampoline_done = 1; 115 trampoline_done = 1;
128} 116}
129 117
279 #error "linux libc or architecture not supported" 267 #error "linux libc or architecture not supported"
280 #endif 268 #endif
281 269
282# elif CORO_IRIX 270# elif CORO_IRIX
283 271
284 setjmp (ctx->env); 272 sigsetjmp (ctx->env, 0);
285 ctx->env[JB_PC] = (__uint64_t)coro_init; 273 ctx->env[JB_PC] = (__uint64_t)coro_init;
286 ctx->env[JB_SP] = (__uint64_t)STACK_ADJUST_PTR (sptr, ssize) - sizeof (long); 274 ctx->env[JB_SP] = (__uint64_t)STACK_ADJUST_PTR (sptr, ssize) - sizeof (long);
287 275
288# elif CORO_ASM 276# elif CORO_ASM
289 277
290 ctx->sp = (volatile void **)(ssize + (char *)sptr); 278 ctx->sp = (void **)(ssize + (char *)sptr);
291 *--ctx->sp = (void *)abort; /* needed for alignment only */ 279 *--ctx->sp = (void *)abort; /* needed for alignment only */
292 *--ctx->sp = (void *)coro_init; 280 *--ctx->sp = (void *)coro_init;
293 ctx->sp -= NUM_SAVED; 281 ctx->sp -= NUM_SAVED;
294 282
295# elif CORO_UCONTEXT 283# elif CORO_UCONTEXT
306# endif 294# endif
307 295
308 coro_transfer (create_coro, new_coro); 296 coro_transfer (create_coro, new_coro);
309} 297}
310 298
311#endif
312
313/*****************************************************************************/ 299/*****************************************************************************/
314/* pthread backend */ 300/* pthread backend */
315/*****************************************************************************/ 301/*****************************************************************************/
316
317#if CORO_PTHREAD 302#elif CORO_PTHREAD
318 303
319/* this mutex will be locked by the running coroutine */ 304/* this mutex will be locked by the running coroutine */
320pthread_mutex_t coro_mutex = PTHREAD_MUTEX_INITIALIZER; 305pthread_mutex_t coro_mutex = PTHREAD_MUTEX_INITIALIZER;
321 306
322struct coro_init_args 307struct coro_init_args
410 } 395 }
411 396
412 pthread_cond_destroy (&ctx->cv); 397 pthread_cond_destroy (&ctx->cv);
413} 398}
414 399
400#else
401# error unsupported backend
415#endif 402#endif
416 403

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines