… | |
… | |
6 | #include "perl.h" |
6 | #include "perl.h" |
7 | #include "XSUB.h" |
7 | #include "XSUB.h" |
8 | |
8 | |
9 | #include "patchlevel.h" |
9 | #include "patchlevel.h" |
10 | |
10 | |
11 | #if PATCHLEVEL < 6 |
11 | #if PERL_VERSION < 6 |
12 | # ifndef PL_ppaddr |
12 | # ifndef PL_ppaddr |
13 | # define PL_ppaddr ppaddr |
13 | # define PL_ppaddr ppaddr |
14 | # endif |
14 | # endif |
15 | # ifndef call_sv |
15 | # ifndef call_sv |
16 | # define call_sv perl_call_sv |
16 | # define call_sv perl_call_sv |
… | |
… | |
57 | |
57 | |
58 | #include "CoroAPI.h" |
58 | #include "CoroAPI.h" |
59 | |
59 | |
60 | #ifdef USE_ITHREADS |
60 | #ifdef USE_ITHREADS |
61 | static perl_mutex coro_mutex; |
61 | static perl_mutex coro_mutex; |
62 | # define LOCK do { MUTEX_LOCK (&coro_mutex); } while (0) |
62 | # define LOCK do { MUTEX_LOCK (&coro_mutex); } while (0) |
63 | # define UNLOCK do { MUTEX_UNLOCK (&coro_mutex); } while (0) |
63 | # define UNLOCK do { MUTEX_UNLOCK (&coro_mutex); } while (0) |
64 | #else |
64 | #else |
65 | # define LOCK 0 |
65 | # define LOCK (void)0 |
66 | # define UNLOCK 0 |
66 | # define UNLOCK (void)0 |
67 | #endif |
67 | #endif |
68 | |
68 | |
69 | static struct CoroAPI coroapi; |
69 | static struct CoroAPI coroapi; |
70 | static AV *main_mainstack; /* used to differentiate between $main and others */ |
70 | static AV *main_mainstack; /* used to differentiate between $main and others */ |
71 | static HV *coro_state_stash; |
71 | static HV *coro_state_stash; |
… | |
… | |
128 | I32 savestack_ix; |
128 | I32 savestack_ix; |
129 | I32 savestack_max; |
129 | I32 savestack_max; |
130 | OP **retstack; |
130 | OP **retstack; |
131 | I32 retstack_ix; |
131 | I32 retstack_ix; |
132 | I32 retstack_max; |
132 | I32 retstack_max; |
|
|
133 | PMOP *curpm; |
133 | COP *curcop; |
134 | COP *curcop; |
134 | JMPENV *top_env; |
135 | JMPENV *top_env; |
135 | |
136 | |
136 | /* data associated with this coroutine (initial args) */ |
137 | /* data associated with this coroutine (initial args) */ |
137 | AV *args; |
138 | AV *args; |
… | |
… | |
347 | PL_savestack_ix = c->savestack_ix; |
348 | PL_savestack_ix = c->savestack_ix; |
348 | PL_savestack_max = c->savestack_max; |
349 | PL_savestack_max = c->savestack_max; |
349 | PL_retstack = c->retstack; |
350 | PL_retstack = c->retstack; |
350 | PL_retstack_ix = c->retstack_ix; |
351 | PL_retstack_ix = c->retstack_ix; |
351 | PL_retstack_max = c->retstack_max; |
352 | PL_retstack_max = c->retstack_max; |
|
|
353 | PL_curpm = c->curpm; |
352 | PL_curcop = c->curcop; |
354 | PL_curcop = c->curcop; |
353 | PL_top_env = c->top_env; |
355 | PL_top_env = c->top_env; |
354 | |
356 | |
355 | if (c->defav) REPLACE_SV (GvAV (PL_defgv), c->defav); |
357 | if (c->defav) REPLACE_SV (GvAV (PL_defgv), c->defav); |
356 | if (c->defsv) REPLACE_SV (DEFSV , c->defsv); |
358 | if (c->defsv) REPLACE_SV (DEFSV , c->defsv); |
… | |
… | |
472 | c->savestack_ix = PL_savestack_ix; |
474 | c->savestack_ix = PL_savestack_ix; |
473 | c->savestack_max = PL_savestack_max; |
475 | c->savestack_max = PL_savestack_max; |
474 | c->retstack = PL_retstack; |
476 | c->retstack = PL_retstack; |
475 | c->retstack_ix = PL_retstack_ix; |
477 | c->retstack_ix = PL_retstack_ix; |
476 | c->retstack_max = PL_retstack_max; |
478 | c->retstack_max = PL_retstack_max; |
|
|
479 | c->curpm = PL_curpm; |
477 | c->curcop = PL_curcop; |
480 | c->curcop = PL_curcop; |
478 | c->top_env = PL_top_env; |
481 | c->top_env = PL_top_env; |
479 | } |
482 | } |
480 | |
483 | |
481 | /* |
484 | /* |
… | |
… | |
586 | stack->gencnt = ctx->gencnt = 0; |
589 | stack->gencnt = ctx->gencnt = 0; |
587 | |
590 | |
588 | if (alloc) |
591 | if (alloc) |
589 | { |
592 | { |
590 | #if HAVE_MMAP |
593 | #if HAVE_MMAP |
591 | stack->ssize = 16384 * sizeof (long); /* mmap should do allocate-on-write for us */ |
594 | stack->ssize = STACKSIZE * sizeof (long); /* mmap should do allocate-on-write for us */ |
592 | stack->sptr = mmap (0, stack->ssize, PROT_EXEC|PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, 0, 0); |
595 | stack->sptr = mmap (0, stack->ssize, PROT_EXEC|PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, 0, 0); |
593 | if (stack->sptr == (void *)-1) |
596 | if (stack->sptr == (void *)-1) |
594 | #endif |
597 | #endif |
595 | { |
598 | { |
596 | /*FIXME*//*D*//* reasonable stack size! */ |
599 | /*FIXME*//*D*//* reasonable stack size! */ |
597 | stack->ssize = - (8192 * sizeof (long)); |
600 | stack->ssize = - (STACKSIZE * sizeof (long)); |
598 | New (0, stack->sptr, 8192, long); |
601 | New (0, stack->sptr, STACKSIZE, long); |
599 | } |
602 | } |
600 | } |
603 | } |
601 | else |
604 | else |
602 | stack->sptr = 0; |
605 | stack->sptr = 0; |
603 | |
606 | |