… | |
… | |
5 | #include "EXTERN.h" |
5 | #include "EXTERN.h" |
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 | |
|
|
11 | // threaded perls might need much more, 65536 or more, |
|
|
12 | // which is 0.5 to 1MB |
|
|
13 | #define STACKSIZE 16384 |
|
|
14 | |
10 | |
15 | #if PERL_VERSION < 6 |
11 | #if PERL_VERSION < 6 |
16 | # ifndef PL_ppaddr |
12 | # ifndef PL_ppaddr |
17 | # define PL_ppaddr ppaddr |
13 | # define PL_ppaddr ppaddr |
18 | # endif |
14 | # endif |
… | |
… | |
31 | # ifndef IS_PADCONST |
27 | # ifndef IS_PADCONST |
32 | # define IS_PADCONST(v) 0 |
28 | # define IS_PADCONST(v) 0 |
33 | # endif |
29 | # endif |
34 | #endif |
30 | #endif |
35 | |
31 | |
|
|
32 | #include <errno.h> |
36 | #include <signal.h> |
33 | #include <signal.h> |
37 | |
34 | |
38 | #ifdef HAVE_MMAP |
35 | #ifdef HAVE_MMAP |
39 | # include <unistd.h> |
36 | # include <unistd.h> |
40 | # include <sys/mman.h> |
37 | # include <sys/mman.h> |
… | |
… | |
61 | |
58 | |
62 | #include "CoroAPI.h" |
59 | #include "CoroAPI.h" |
63 | |
60 | |
64 | #ifdef USE_ITHREADS |
61 | #ifdef USE_ITHREADS |
65 | static perl_mutex coro_mutex; |
62 | static perl_mutex coro_mutex; |
66 | # define LOCK do { MUTEX_LOCK (&coro_mutex); } while (0) |
63 | # define LOCK do { MUTEX_LOCK (&coro_mutex); } while (0) |
67 | # define UNLOCK do { MUTEX_UNLOCK (&coro_mutex); } while (0) |
64 | # define UNLOCK do { MUTEX_UNLOCK (&coro_mutex); } while (0) |
68 | #else |
65 | #else |
69 | # define LOCK 0 |
66 | # define LOCK (void)0 |
70 | # define UNLOCK 0 |
67 | # define UNLOCK (void)0 |
71 | #endif |
68 | #endif |
72 | |
69 | |
73 | static struct CoroAPI coroapi; |
70 | static struct CoroAPI coroapi; |
74 | static AV *main_mainstack; /* used to differentiate between $main and others */ |
71 | static AV *main_mainstack; /* used to differentiate between $main and others */ |
75 | static HV *coro_state_stash; |
72 | static HV *coro_state_stash; |
… | |
… | |
174 | av_store (newpadlist, 1, (SV *) newpad); |
171 | av_store (newpadlist, 1, (SV *) newpad); |
175 | |
172 | |
176 | av = newAV (); /* will be @_ */ |
173 | av = newAV (); /* will be @_ */ |
177 | av_extend (av, 0); |
174 | av_extend (av, 0); |
178 | av_store (newpad, 0, (SV *) av); |
175 | av_store (newpad, 0, (SV *) av); |
179 | AvFLAGS (av) = AVf_REIFY; |
176 | AvREIFY_on (av); |
180 | |
177 | |
181 | for (ix = fpad; ix > 0; ix--) |
178 | for (ix = fpad; ix > 0; ix--) |
182 | { |
179 | { |
183 | SV *namesv = (ix <= fname) ? pname[ix] : Nullsv; |
180 | SV *namesv = (ix <= fname) ? pname[ix] : Nullsv; |
184 | |
181 | |
… | |
… | |
349 | PL_scopestack_ix = c->scopestack_ix; |
346 | PL_scopestack_ix = c->scopestack_ix; |
350 | PL_scopestack_max = c->scopestack_max; |
347 | PL_scopestack_max = c->scopestack_max; |
351 | PL_savestack = c->savestack; |
348 | PL_savestack = c->savestack; |
352 | PL_savestack_ix = c->savestack_ix; |
349 | PL_savestack_ix = c->savestack_ix; |
353 | PL_savestack_max = c->savestack_max; |
350 | PL_savestack_max = c->savestack_max; |
|
|
351 | #if PERL_VERSION < 9 |
354 | PL_retstack = c->retstack; |
352 | PL_retstack = c->retstack; |
355 | PL_retstack_ix = c->retstack_ix; |
353 | PL_retstack_ix = c->retstack_ix; |
356 | PL_retstack_max = c->retstack_max; |
354 | PL_retstack_max = c->retstack_max; |
|
|
355 | #endif |
357 | PL_curpm = c->curpm; |
356 | PL_curpm = c->curpm; |
358 | PL_curcop = c->curcop; |
357 | PL_curcop = c->curcop; |
359 | PL_top_env = c->top_env; |
358 | PL_top_env = c->top_env; |
360 | |
359 | |
361 | if (c->defav) REPLACE_SV (GvAV (PL_defgv), c->defav); |
360 | if (c->defav) REPLACE_SV (GvAV (PL_defgv), c->defav); |
… | |
… | |
475 | c->scopestack_ix = PL_scopestack_ix; |
474 | c->scopestack_ix = PL_scopestack_ix; |
476 | c->scopestack_max = PL_scopestack_max; |
475 | c->scopestack_max = PL_scopestack_max; |
477 | c->savestack = PL_savestack; |
476 | c->savestack = PL_savestack; |
478 | c->savestack_ix = PL_savestack_ix; |
477 | c->savestack_ix = PL_savestack_ix; |
479 | c->savestack_max = PL_savestack_max; |
478 | c->savestack_max = PL_savestack_max; |
|
|
479 | #if PERL_VERSION < 9 |
480 | c->retstack = PL_retstack; |
480 | c->retstack = PL_retstack; |
481 | c->retstack_ix = PL_retstack_ix; |
481 | c->retstack_ix = PL_retstack_ix; |
482 | c->retstack_max = PL_retstack_max; |
482 | c->retstack_max = PL_retstack_max; |
|
|
483 | #endif |
483 | c->curpm = PL_curpm; |
484 | c->curpm = PL_curpm; |
484 | c->curcop = PL_curcop; |
485 | c->curcop = PL_curcop; |
485 | c->top_env = PL_top_env; |
486 | c->top_env = PL_top_env; |
486 | } |
487 | } |
487 | |
488 | |
… | |
… | |
524 | |
525 | |
525 | New(54,PL_savestack,96,ANY); |
526 | New(54,PL_savestack,96,ANY); |
526 | PL_savestack_ix = 0; |
527 | PL_savestack_ix = 0; |
527 | PL_savestack_max = 96; |
528 | PL_savestack_max = 96; |
528 | |
529 | |
|
|
530 | #if PERL_VERSION < 9 |
529 | New(54,PL_retstack,8,OP*); |
531 | New(54,PL_retstack,8,OP*); |
530 | PL_retstack_ix = 0; |
532 | PL_retstack_ix = 0; |
531 | PL_retstack_max = 8; |
533 | PL_retstack_max = 8; |
|
|
534 | #endif |
532 | |
535 | |
533 | UNLOCK; |
536 | UNLOCK; |
534 | } |
537 | } |
535 | |
538 | |
536 | /* |
539 | /* |
… | |
… | |
576 | |
579 | |
577 | Safefree (PL_tmps_stack); |
580 | Safefree (PL_tmps_stack); |
578 | Safefree (PL_markstack); |
581 | Safefree (PL_markstack); |
579 | Safefree (PL_scopestack); |
582 | Safefree (PL_scopestack); |
580 | Safefree (PL_savestack); |
583 | Safefree (PL_savestack); |
|
|
584 | #if PERL_VERSION < 9 |
581 | Safefree (PL_retstack); |
585 | Safefree (PL_retstack); |
|
|
586 | #endif |
582 | } |
587 | } |
583 | |
588 | |
584 | static void |
589 | static void |
585 | allocate_stack (Coro__State ctx, int alloc) |
590 | allocate_stack (Coro__State ctx, int alloc) |
586 | { |
591 | { |
… | |
… | |
1150 | cede(...) |
1155 | cede(...) |
1151 | PROTOTYPE: |
1156 | PROTOTYPE: |
1152 | CODE: |
1157 | CODE: |
1153 | api_cede (); |
1158 | api_cede (); |
1154 | |
1159 | |
|
|
1160 | # and these are hacks |
|
|
1161 | SV * |
|
|
1162 | _aio_get_state () |
|
|
1163 | CODE: |
|
|
1164 | { |
|
|
1165 | struct { |
|
|
1166 | int errorno; |
|
|
1167 | int laststype; |
|
|
1168 | int laststatval; |
|
|
1169 | Stat_t statcache; |
|
|
1170 | } data; |
|
|
1171 | |
|
|
1172 | data.errorno = errno; |
|
|
1173 | data.laststype = PL_laststype; |
|
|
1174 | data.laststatval = PL_laststatval; |
|
|
1175 | data.statcache = PL_statcache; |
|
|
1176 | |
|
|
1177 | RETVAL = newSVpvn ((char *)&data, sizeof data); |
|
|
1178 | } |
|
|
1179 | OUTPUT: |
|
|
1180 | RETVAL |
|
|
1181 | |
|
|
1182 | void |
|
|
1183 | _aio_set_state (char *data_) |
|
|
1184 | PROTOTYPE: $ |
|
|
1185 | CODE: |
|
|
1186 | { |
|
|
1187 | struct { |
|
|
1188 | int errorno; |
|
|
1189 | int laststype; |
|
|
1190 | int laststatval; |
|
|
1191 | Stat_t statcache; |
|
|
1192 | } *data = (void *)data_; |
|
|
1193 | |
|
|
1194 | errno = data->errorno; |
|
|
1195 | PL_laststype = data->laststype; |
|
|
1196 | PL_laststatval = data->laststatval; |
|
|
1197 | PL_statcache = data->statcache; |
|
|
1198 | } |