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.40 by root, Sat Nov 8 04:52:01 2008 UTC vs.
Revision 1.43 by root, Sun Nov 16 00:55:41 2008 UTC

78 78
79static coro_func coro_init_func; 79static coro_func coro_init_func;
80static void *coro_init_arg; 80static void *coro_init_arg;
81static 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 */
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
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;
113 _setjmp (new_coro->env) 107 _setjmp (new_coro->env)
114 #else 108 #else
115 sigsetjmp (new_coro->env, 0) 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
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
353void 341void
354coro_transfer (coro_context *prev, coro_context *next) 342coro_transfer (coro_context *prev, coro_context *next)
355{ 343{
356 pthread_cond_signal (&next->cv); 344 pthread_cond_signal (&next->cv);
357 pthread_cond_wait (&prev->cv, &coro_mutex); 345 pthread_cond_wait (&prev->cv, &coro_mutex);
346#if __FreeBSD__ /* freebsd is of course broken and needs manual testcancel calls... yay... */
347 pthread_testcancel ();
348#endif
358} 349}
359 350
360void 351void
361coro_create (coro_context *ctx, coro_func coro, void *arg, void *sptr, long ssize) 352coro_create (coro_context *ctx, coro_func coro, void *arg, void *sptr, long ssize)
362{ 353{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines