|
|
1 | #define PERL_NO_GET_CONTEXT |
|
|
2 | |
1 | #include "EXTERN.h" |
3 | #include "EXTERN.h" |
2 | #include "perl.h" |
4 | #include "perl.h" |
3 | #include "XSUB.h" |
5 | #include "XSUB.h" |
|
|
6 | |
|
|
7 | #include "patchlevel.h" |
|
|
8 | |
|
|
9 | #if PATCHLEVEL < 6 |
|
|
10 | # ifndef PL_ppaddr |
|
|
11 | # define PL_ppaddr ppaddr |
|
|
12 | # endif |
|
|
13 | # ifndef call_sv |
|
|
14 | # define call_sv perl_call_sv |
|
|
15 | # endif |
|
|
16 | # ifndef get_sv |
|
|
17 | # define get_sv perl_get_sv |
|
|
18 | # endif |
|
|
19 | # ifndef get_cv |
|
|
20 | # define get_cv perl_get_cv |
|
|
21 | # endif |
|
|
22 | # ifndef IS_PADGV |
|
|
23 | # define IS_PADGV(v) 0 |
|
|
24 | # endif |
|
|
25 | # ifndef IS_PADCONST |
|
|
26 | # define IS_PADCONST(v) 0 |
|
|
27 | # endif |
|
|
28 | #endif |
4 | |
29 | |
5 | #include "libcoro/coro.c" |
30 | #include "libcoro/coro.c" |
6 | |
31 | |
7 | #include <signal.h> |
32 | #include <signal.h> |
8 | |
33 | |
… | |
… | |
16 | # undef HAVE_MMAP |
41 | # undef HAVE_MMAP |
17 | # endif |
42 | # endif |
18 | # endif |
43 | # endif |
19 | #endif |
44 | #endif |
20 | |
45 | |
21 | #define MAY_FLUSH /* increases codesize and is rarely used */ |
|
|
22 | |
|
|
23 | #define SUB_INIT "Coro::State::initialize" |
46 | #define SUB_INIT "Coro::State::initialize" |
24 | #define UCORO_STATE "_coro_state" |
47 | #define UCORO_STATE "_coro_state" |
25 | |
48 | |
26 | /* The next macro should declare a variable stacklevel that contains and approximation |
49 | /* The next macro should declare a variable stacklevel that contains and approximation |
27 | * to the current C stack pointer. Its property is that it changes with each call |
50 | * to the current C stack pointer. Its property is that it changes with each call |
… | |
… | |
32 | |
55 | |
33 | #define labs(l) ((l) >= 0 ? (l) : -(l)) |
56 | #define labs(l) ((l) >= 0 ? (l) : -(l)) |
34 | |
57 | |
35 | #include "CoroAPI.h" |
58 | #include "CoroAPI.h" |
36 | |
59 | |
|
|
60 | #ifdef USE_ITHREADS |
|
|
61 | static perl_mutex coro_mutex; |
|
|
62 | # define LOCK do { MUTEX_LOCK (&coro_mutex); } while (0) |
|
|
63 | # define UNLOCK do { MUTEX_UNLOCK (&coro_mutex); } while (0) |
|
|
64 | #else |
|
|
65 | # define LOCK 0 |
|
|
66 | # define UNLOCK 0 |
|
|
67 | #endif |
|
|
68 | |
37 | static struct CoroAPI coroapi; |
69 | static struct CoroAPI coroapi; |
|
|
70 | static AV *main_mainstack; /* used to differentiate between $main and others */ |
|
|
71 | static HV *coro_state_stash; |
|
|
72 | static SV *ucoro_state_sv; |
|
|
73 | static U32 ucoro_state_hash; |
|
|
74 | static __thread SV *coro_mortal; /* will be freed after next transfer */ |
38 | |
75 | |
39 | /* this is actually not only the c stack but also c registers etc... */ |
76 | /* this is actually not only the c stack but also c registers etc... */ |
40 | typedef struct { |
77 | typedef struct { |
41 | int refcnt; /* pointer reference counter */ |
78 | int refcnt; /* pointer reference counter */ |
42 | int usecnt; /* shared by how many coroutines */ |
79 | int usecnt; /* shared by how many coroutines */ |
… | |
… | |
100 | }; |
137 | }; |
101 | |
138 | |
102 | typedef struct coro *Coro__State; |
139 | typedef struct coro *Coro__State; |
103 | typedef struct coro *Coro__State_or_hashref; |
140 | typedef struct coro *Coro__State_or_hashref; |
104 | |
141 | |
105 | static AV *main_mainstack; /* used to differentiate between $main and others */ |
|
|
106 | static HV *coro_state_stash; |
|
|
107 | static SV *ucoro_state_sv; |
|
|
108 | static U32 ucoro_state_hash; |
|
|
109 | static HV *padlist_cache; |
|
|
110 | static SV *coro_mortal; /* will be freed after next transfer */ |
|
|
111 | |
|
|
112 | /* mostly copied from op.c:cv_clone2 */ |
142 | /* mostly copied from op.c:cv_clone2 */ |
113 | STATIC AV * |
143 | STATIC AV * |
114 | clone_padlist (AV *protopadlist) |
144 | clone_padlist (pTHX_ AV *protopadlist) |
115 | { |
145 | { |
116 | AV *av; |
146 | AV *av; |
117 | I32 ix; |
147 | I32 ix; |
118 | AV *protopad_name = (AV *) * av_fetch (protopadlist, 0, FALSE); |
148 | AV *protopad_name = (AV *) * av_fetch (protopadlist, 0, FALSE); |
119 | AV *protopad = (AV *) * av_fetch (protopadlist, 1, FALSE); |
149 | AV *protopad = (AV *) * av_fetch (protopadlist, 1, FALSE); |
… | |
… | |
143 | AvFLAGS (av) = AVf_REIFY; |
173 | AvFLAGS (av) = AVf_REIFY; |
144 | |
174 | |
145 | for (ix = fpad; ix > 0; ix--) |
175 | for (ix = fpad; ix > 0; ix--) |
146 | { |
176 | { |
147 | SV *namesv = (ix <= fname) ? pname[ix] : Nullsv; |
177 | SV *namesv = (ix <= fname) ? pname[ix] : Nullsv; |
|
|
178 | |
148 | if (namesv && namesv != &PL_sv_undef) |
179 | if (namesv && namesv != &PL_sv_undef) |
149 | { |
180 | { |
150 | char *name = SvPVX (namesv); /* XXX */ |
181 | char *name = SvPVX (namesv); /* XXX */ |
|
|
182 | |
151 | if (SvFLAGS (namesv) & SVf_FAKE || *name == '&') |
183 | if (SvFLAGS (namesv) & SVf_FAKE || *name == '&') |
152 | { /* lexical from outside? */ |
184 | { /* lexical from outside? */ |
153 | npad[ix] = SvREFCNT_inc (ppad[ix]); |
185 | npad[ix] = SvREFCNT_inc (ppad[ix]); |
154 | } |
186 | } |
155 | else |
187 | else |
… | |
… | |
161 | sv = (SV *) newAV (); |
193 | sv = (SV *) newAV (); |
162 | else if (*name == '%') |
194 | else if (*name == '%') |
163 | sv = (SV *) newHV (); |
195 | sv = (SV *) newHV (); |
164 | else |
196 | else |
165 | sv = NEWSV (0, 0); |
197 | sv = NEWSV (0, 0); |
|
|
198 | |
|
|
199 | #ifdef SvPADBUSY |
166 | if (!SvPADBUSY (sv)) |
200 | if (!SvPADBUSY (sv)) |
|
|
201 | #endif |
167 | SvPADMY_on (sv); |
202 | SvPADMY_on (sv); |
|
|
203 | |
168 | npad[ix] = sv; |
204 | npad[ix] = sv; |
169 | } |
205 | } |
170 | } |
206 | } |
171 | else if (IS_PADGV (ppad[ix]) || IS_PADCONST (ppad[ix])) |
207 | else if (IS_PADGV (ppad[ix]) || IS_PADCONST (ppad[ix])) |
172 | { |
208 | { |
… | |
… | |
201 | #endif |
237 | #endif |
202 | |
238 | |
203 | return newpadlist; |
239 | return newpadlist; |
204 | } |
240 | } |
205 | |
241 | |
206 | #ifdef MAY_FLUSH |
|
|
207 | STATIC void |
242 | STATIC void |
208 | free_padlist (AV *padlist) |
243 | free_padlist (pTHX_ AV *padlist) |
209 | { |
244 | { |
210 | /* may be during global destruction */ |
245 | /* may be during global destruction */ |
211 | if (SvREFCNT(padlist)) |
246 | if (SvREFCNT (padlist)) |
212 | { |
247 | { |
213 | I32 i = AvFILLp(padlist); |
248 | I32 i = AvFILLp (padlist); |
214 | while (i >= 0) |
249 | while (i >= 0) |
215 | { |
250 | { |
216 | SV **svp = av_fetch(padlist, i--, FALSE); |
251 | SV **svp = av_fetch (padlist, i--, FALSE); |
217 | SV *sv = svp ? *svp : Nullsv; |
|
|
218 | if (sv) |
252 | if (svp) |
|
|
253 | { |
|
|
254 | SV *sv; |
|
|
255 | while (&PL_sv_undef != (sv = av_pop ((AV *)*svp))) |
219 | SvREFCNT_dec(sv); |
256 | SvREFCNT_dec (sv); |
|
|
257 | |
|
|
258 | SvREFCNT_dec (*svp); |
|
|
259 | } |
220 | } |
260 | } |
221 | |
261 | |
222 | SvREFCNT_dec((SV*)padlist); |
262 | SvREFCNT_dec ((SV*)padlist); |
223 | } |
263 | } |
224 | } |
264 | } |
225 | #endif |
265 | |
|
|
266 | STATIC int |
|
|
267 | coro_cv_free (pTHX_ SV *sv, MAGIC *mg) |
|
|
268 | { |
|
|
269 | AV *padlist; |
|
|
270 | AV *av = (AV *)mg->mg_obj; |
|
|
271 | |
|
|
272 | /* casting is fun. */ |
|
|
273 | while (&PL_sv_undef != (SV *)(padlist = (AV *)av_pop (av))) |
|
|
274 | free_padlist (aTHX_ padlist); |
|
|
275 | } |
|
|
276 | |
|
|
277 | #define PERL_MAGIC_coro PERL_MAGIC_ext |
|
|
278 | |
|
|
279 | static MGVTBL vtbl_coro = {0, 0, 0, 0, coro_cv_free}; |
226 | |
280 | |
227 | /* the next two functions merely cache the padlists */ |
281 | /* the next two functions merely cache the padlists */ |
228 | STATIC void |
282 | STATIC void |
229 | get_padlist (CV *cv) |
283 | get_padlist (pTHX_ CV *cv) |
230 | { |
284 | { |
231 | SV **he = hv_fetch (padlist_cache, (void *)&cv, sizeof (CV *), 0); |
285 | MAGIC *mg = mg_find ((SV *)cv, PERL_MAGIC_coro); |
232 | |
286 | |
233 | if (he && AvFILLp ((AV *)*he) >= 0) |
287 | if (mg && AvFILLp ((AV *)mg->mg_obj) >= 0) |
234 | CvPADLIST (cv) = (AV *)av_pop ((AV *)*he); |
288 | CvPADLIST (cv) = (AV *)av_pop ((AV *)mg->mg_obj); |
235 | else |
289 | else |
236 | CvPADLIST (cv) = clone_padlist (CvPADLIST (cv)); |
290 | CvPADLIST (cv) = clone_padlist (aTHX_ CvPADLIST (cv)); |
237 | } |
291 | } |
238 | |
292 | |
239 | STATIC void |
293 | STATIC void |
240 | put_padlist (CV *cv) |
294 | put_padlist (pTHX_ CV *cv) |
241 | { |
295 | { |
242 | SV **he = hv_fetch (padlist_cache, (void *)&cv, sizeof (CV *), 1); |
296 | MAGIC *mg = mg_find ((SV *)cv, PERL_MAGIC_coro); |
243 | |
297 | |
244 | if (SvTYPE (*he) != SVt_PVAV) |
298 | if (!mg) |
245 | { |
299 | { |
246 | SvREFCNT_dec (*he); |
300 | sv_magic ((SV *)cv, 0, PERL_MAGIC_coro, 0, 0); |
|
|
301 | mg = mg_find ((SV *)cv, PERL_MAGIC_coro); |
|
|
302 | mg->mg_virtual = &vtbl_coro; |
247 | *he = (SV *)newAV (); |
303 | mg->mg_obj = (SV *)newAV (); |
248 | } |
304 | } |
249 | |
305 | |
250 | av_push ((AV *)*he, (SV *)CvPADLIST (cv)); |
306 | av_push ((AV *)mg->mg_obj, (SV *)CvPADLIST (cv)); |
251 | } |
307 | } |
252 | |
|
|
253 | #ifdef MAY_FLUSH |
|
|
254 | STATIC void |
|
|
255 | flush_padlist_cache () |
|
|
256 | { |
|
|
257 | HV *hv = padlist_cache; |
|
|
258 | padlist_cache = newHV (); |
|
|
259 | |
|
|
260 | if (hv_iterinit (hv)) |
|
|
261 | { |
|
|
262 | HE *he; |
|
|
263 | AV *padlist; |
|
|
264 | |
|
|
265 | while (!!(he = hv_iternext (hv))) |
|
|
266 | { |
|
|
267 | AV *av = (AV *)HeVAL(he); |
|
|
268 | |
|
|
269 | /* casting is fun. */ |
|
|
270 | while (&PL_sv_undef != (SV *)(padlist = (AV *)av_pop (av))) |
|
|
271 | free_padlist (padlist); |
|
|
272 | } |
|
|
273 | } |
|
|
274 | |
|
|
275 | SvREFCNT_dec (hv); |
|
|
276 | } |
|
|
277 | #endif |
|
|
278 | |
308 | |
279 | #define SB do { |
309 | #define SB do { |
280 | #define SE } while (0) |
310 | #define SE } while (0) |
281 | |
311 | |
282 | #define LOAD(state) load_state(aTHX_ (state)); |
312 | #define LOAD(state) load_state(aTHX_ (state)); |
283 | #define SAVE(state,flags) save_state(aTHX_ (state),(flags)); |
313 | #define SAVE(state,flags) save_state(aTHX_ (state),(flags)); |
284 | |
314 | |
285 | #define REPLACE_SV(sv,val) SB SvREFCNT_dec(sv); (sv) = (val); SE |
315 | #define REPLACE_SV(sv,val) SB SvREFCNT_dec(sv); (sv) = (val); (val) = 0; SE |
286 | |
316 | |
287 | static void |
317 | static void |
288 | load_state(pTHX_ Coro__State c) |
318 | load_state(pTHX_ Coro__State c) |
289 | { |
319 | { |
290 | PL_dowarn = c->dowarn; |
320 | PL_dowarn = c->dowarn; |
… | |
… | |
331 | { |
361 | { |
332 | AV *padlist = (AV *)POPs; |
362 | AV *padlist = (AV *)POPs; |
333 | |
363 | |
334 | if (padlist) |
364 | if (padlist) |
335 | { |
365 | { |
336 | put_padlist (cv); /* mark this padlist as available */ |
366 | put_padlist (aTHX_ cv); /* mark this padlist as available */ |
337 | CvPADLIST(cv) = padlist; |
367 | CvPADLIST(cv) = padlist; |
338 | #ifdef USE_THREADS |
|
|
339 | /*CvOWNER(cv) = (struct perl_thread *)POPs;*/ |
|
|
340 | #endif |
|
|
341 | } |
368 | } |
342 | |
369 | |
343 | ++CvDEPTH(cv); |
370 | ++CvDEPTH(cv); |
344 | } |
371 | } |
345 | |
372 | |
… | |
… | |
372 | if (CxTYPE(cx) == CXt_SUB) |
399 | if (CxTYPE(cx) == CXt_SUB) |
373 | { |
400 | { |
374 | CV *cv = cx->blk_sub.cv; |
401 | CV *cv = cx->blk_sub.cv; |
375 | if (CvDEPTH(cv)) |
402 | if (CvDEPTH(cv)) |
376 | { |
403 | { |
377 | #ifdef USE_THREADS |
|
|
378 | /*XPUSHs ((SV *)CvOWNER(cv));*/ |
|
|
379 | /*CvOWNER(cv) = 0;*/ |
|
|
380 | /*error must unlock this cv etc.. etc...*/ |
|
|
381 | #endif |
|
|
382 | EXTEND (SP, CvDEPTH(cv)*2); |
404 | EXTEND (SP, CvDEPTH(cv)*2); |
383 | |
405 | |
384 | while (--CvDEPTH(cv)) |
406 | while (--CvDEPTH(cv)) |
385 | { |
407 | { |
386 | /* this tells the restore code to increment CvDEPTH */ |
408 | /* this tells the restore code to increment CvDEPTH */ |
… | |
… | |
389 | } |
411 | } |
390 | |
412 | |
391 | PUSHs ((SV *)CvPADLIST(cv)); |
413 | PUSHs ((SV *)CvPADLIST(cv)); |
392 | PUSHs ((SV *)cv); |
414 | PUSHs ((SV *)cv); |
393 | |
415 | |
394 | get_padlist (cv); /* this is a monster */ |
416 | get_padlist (aTHX_ cv); /* this is a monster */ |
395 | } |
417 | } |
396 | } |
418 | } |
|
|
419 | #ifdef CXt_FORMAT |
397 | else if (CxTYPE(cx) == CXt_FORMAT) |
420 | else if (CxTYPE(cx) == CXt_FORMAT) |
398 | { |
421 | { |
399 | /* I never used formats, so how should I know how these are implemented? */ |
422 | /* I never used formats, so how should I know how these are implemented? */ |
400 | /* my bold guess is as a simple, plain sub... */ |
423 | /* my bold guess is as a simple, plain sub... */ |
401 | croak ("CXt_FORMAT not yet handled. Don't switch coroutines from within formats"); |
424 | croak ("CXt_FORMAT not yet handled. Don't switch coroutines from within formats"); |
402 | } |
425 | } |
|
|
426 | #endif |
403 | } |
427 | } |
404 | |
428 | |
405 | if (top_si->si_type == PERLSI_MAIN) |
429 | if (top_si->si_type == PERLSI_MAIN) |
406 | break; |
430 | break; |
407 | |
431 | |
… | |
… | |
450 | } |
474 | } |
451 | |
475 | |
452 | /* |
476 | /* |
453 | * allocate various perl stacks. This is an exact copy |
477 | * allocate various perl stacks. This is an exact copy |
454 | * of perl.c:init_stacks, except that it uses less memory |
478 | * of perl.c:init_stacks, except that it uses less memory |
455 | * on the assumption that coroutines do not usually need |
479 | * on the (sometimes correct) assumption that coroutines do |
456 | * a lot of stackspace. |
480 | * not usually need a lot of stackspace. |
457 | */ |
481 | */ |
458 | STATIC void |
482 | STATIC void |
459 | coro_init_stacks (pTHX) |
483 | coro_init_stacks (pTHX) |
460 | { |
484 | { |
|
|
485 | LOCK; |
|
|
486 | |
461 | PL_curstackinfo = new_stackinfo(96, 1024/sizeof(PERL_CONTEXT) - 1); |
487 | PL_curstackinfo = new_stackinfo(96, 1024/sizeof(PERL_CONTEXT) - 1); |
462 | PL_curstackinfo->si_type = PERLSI_MAIN; |
488 | PL_curstackinfo->si_type = PERLSI_MAIN; |
463 | PL_curstack = PL_curstackinfo->si_stack; |
489 | PL_curstack = PL_curstackinfo->si_stack; |
464 | PL_mainstack = PL_curstack; /* remember in case we switch stacks */ |
490 | PL_mainstack = PL_curstack; /* remember in case we switch stacks */ |
465 | |
491 | |
… | |
… | |
474 | |
500 | |
475 | New(54,PL_markstack,16,I32); |
501 | New(54,PL_markstack,16,I32); |
476 | PL_markstack_ptr = PL_markstack; |
502 | PL_markstack_ptr = PL_markstack; |
477 | PL_markstack_max = PL_markstack + 16; |
503 | PL_markstack_max = PL_markstack + 16; |
478 | |
504 | |
|
|
505 | #ifdef SET_MARK_OFFSET |
479 | SET_MARK_OFFSET; |
506 | SET_MARK_OFFSET; |
|
|
507 | #endif |
480 | |
508 | |
481 | New(54,PL_scopestack,16,I32); |
509 | New(54,PL_scopestack,16,I32); |
482 | PL_scopestack_ix = 0; |
510 | PL_scopestack_ix = 0; |
483 | PL_scopestack_max = 16; |
511 | PL_scopestack_max = 16; |
484 | |
512 | |
… | |
… | |
487 | PL_savestack_max = 96; |
515 | PL_savestack_max = 96; |
488 | |
516 | |
489 | New(54,PL_retstack,8,OP*); |
517 | New(54,PL_retstack,8,OP*); |
490 | PL_retstack_ix = 0; |
518 | PL_retstack_ix = 0; |
491 | PL_retstack_max = 8; |
519 | PL_retstack_max = 8; |
|
|
520 | |
|
|
521 | UNLOCK; |
492 | } |
522 | } |
493 | |
523 | |
494 | /* |
524 | /* |
495 | * destroy the stacks, the callchain etc... |
525 | * destroy the stacks, the callchain etc... |
496 | * still there is a memleak of 128 bytes... |
|
|
497 | */ |
526 | */ |
498 | STATIC void |
527 | STATIC void |
499 | destroy_stacks(pTHX) |
528 | destroy_stacks(pTHX) |
500 | { |
529 | { |
501 | if (!IN_DESTRUCT) |
530 | if (!IN_DESTRUCT) |
502 | { |
531 | { |
503 | /* is this ugly, I ask? */ |
532 | /* is this ugly, I ask? */ |
504 | while (PL_scopestack_ix) |
533 | LEAVE_SCOPE (0); |
505 | LEAVE; |
|
|
506 | |
534 | |
507 | /* sure it is, but more important: is it correct?? :/ */ |
535 | /* sure it is, but more important: is it correct?? :/ */ |
508 | while (PL_tmps_ix > PL_tmps_floor) /* should only ever be one iteration */ |
|
|
509 | FREETMPS; |
536 | FREETMPS; |
|
|
537 | |
|
|
538 | /*POPSTACK_TO (PL_mainstack);*//*D*//*use*/ |
510 | } |
539 | } |
511 | |
540 | |
512 | while (PL_curstackinfo->si_next) |
541 | while (PL_curstackinfo->si_next) |
513 | PL_curstackinfo = PL_curstackinfo->si_next; |
542 | PL_curstackinfo = PL_curstackinfo->si_next; |
514 | |
543 | |
515 | while (PL_curstackinfo) |
544 | while (PL_curstackinfo) |
516 | { |
545 | { |
517 | PERL_SI *p = PL_curstackinfo->si_prev; |
546 | PERL_SI *p = PL_curstackinfo->si_prev; |
518 | |
547 | |
519 | { |
548 | { /*D*//*remove*/ |
520 | dSP; |
549 | dSP; |
521 | SWITCHSTACK (PL_curstack, PL_curstackinfo->si_stack); |
550 | SWITCHSTACK (PL_curstack, PL_curstackinfo->si_stack); |
522 | PUTBACK; /* possibly superfluous */ |
551 | PUTBACK; /* possibly superfluous */ |
523 | } |
552 | } |
524 | |
553 | |
525 | if (!IN_DESTRUCT) |
554 | if (!IN_DESTRUCT) |
526 | { |
555 | { |
527 | dounwind(-1); |
556 | dounwind (-1);/*D*//*remove*/ |
528 | SvREFCNT_dec(PL_curstackinfo->si_stack); |
557 | SvREFCNT_dec (PL_curstackinfo->si_stack); |
529 | } |
558 | } |
530 | |
559 | |
531 | Safefree(PL_curstackinfo->si_cxstack); |
560 | Safefree (PL_curstackinfo->si_cxstack); |
532 | Safefree(PL_curstackinfo); |
561 | Safefree (PL_curstackinfo); |
533 | PL_curstackinfo = p; |
562 | PL_curstackinfo = p; |
534 | } |
563 | } |
535 | |
564 | |
536 | Safefree(PL_tmps_stack); |
565 | Safefree (PL_tmps_stack); |
537 | Safefree(PL_markstack); |
566 | Safefree (PL_markstack); |
538 | Safefree(PL_scopestack); |
567 | Safefree (PL_scopestack); |
539 | Safefree(PL_savestack); |
568 | Safefree (PL_savestack); |
540 | Safefree(PL_retstack); |
569 | Safefree (PL_retstack); |
541 | } |
570 | } |
542 | |
571 | |
543 | static void |
572 | static void |
544 | allocate_stack (Coro__State ctx, int alloc) |
573 | allocate_stack (Coro__State ctx, int alloc) |
545 | { |
574 | { |
… | |
… | |
548 | New (0, stack, 1, coro_stack); |
577 | New (0, stack, 1, coro_stack); |
549 | |
578 | |
550 | stack->refcnt = 1; |
579 | stack->refcnt = 1; |
551 | stack->usecnt = 1; |
580 | stack->usecnt = 1; |
552 | stack->gencnt = ctx->gencnt = 0; |
581 | stack->gencnt = ctx->gencnt = 0; |
|
|
582 | |
553 | if (alloc) |
583 | if (alloc) |
554 | { |
584 | { |
555 | #if HAVE_MMAP |
585 | #if HAVE_MMAP |
556 | stack->ssize = 128 * 1024 * sizeof (long); /* mmap should do allocate-on-write for us */ |
586 | stack->ssize = 16384 * sizeof (long); /* mmap should do allocate-on-write for us */ |
557 | stack->sptr = mmap (0, stack->ssize, PROT_EXEC|PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, 0, 0); |
587 | stack->sptr = mmap (0, stack->ssize, PROT_EXEC|PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, 0, 0); |
558 | if (stack->sptr == (void *)-1) |
588 | if (stack->sptr == (void *)-1) |
559 | #endif |
589 | #endif |
560 | { |
590 | { |
561 | /*FIXME*//*D*//* reasonable stack size! */ |
591 | /*FIXME*//*D*//* reasonable stack size! */ |
562 | stack->ssize = -4096 * sizeof (long); |
592 | stack->ssize = - (8192 * sizeof (long)); |
563 | New (0, stack->sptr, 4096, long); |
593 | New (0, stack->sptr, 8192, long); |
564 | } |
594 | } |
565 | } |
595 | } |
566 | else |
596 | else |
567 | stack->sptr = 0; |
597 | stack->sptr = 0; |
568 | |
598 | |
… | |
… | |
582 | { |
612 | { |
583 | #ifdef HAVE_MMAP |
613 | #ifdef HAVE_MMAP |
584 | if (stack->ssize > 0 && stack->sptr) |
614 | if (stack->ssize > 0 && stack->sptr) |
585 | munmap (stack->sptr, stack->ssize); |
615 | munmap (stack->sptr, stack->ssize); |
586 | else |
616 | else |
587 | #else |
617 | #endif |
588 | Safefree (stack->sptr); |
618 | Safefree (stack->sptr); |
589 | #endif |
619 | |
590 | Safefree (stack); |
620 | Safefree (stack); |
591 | } |
621 | } |
592 | else if (ctx->gencnt == stack->gencnt) |
622 | else if (ctx->gencnt == stack->gencnt) |
593 | --stack->usecnt; |
623 | --stack->usecnt; |
594 | } |
624 | } |
… | |
… | |
598 | setup_coro (void *arg) |
628 | setup_coro (void *arg) |
599 | { |
629 | { |
600 | /* |
630 | /* |
601 | * emulate part of the perl startup here. |
631 | * emulate part of the perl startup here. |
602 | */ |
632 | */ |
|
|
633 | dTHX; |
603 | dSP; |
634 | dSP; |
604 | Coro__State ctx = (Coro__State)arg; |
635 | Coro__State ctx = (Coro__State)arg; |
605 | SV *sub_init = (SV*)get_cv(SUB_INIT, FALSE); |
636 | SV *sub_init = (SV *)get_cv (SUB_INIT, FALSE); |
606 | |
637 | |
607 | coro_init_stacks (aTHX); |
638 | coro_init_stacks (aTHX); |
608 | /*PL_curcop = 0;*/ |
639 | /*PL_curcop = 0;*/ |
609 | /*PL_in_eval = PL_in_eval;*/ /* inherit */ |
640 | /*PL_in_eval = PL_in_eval;*/ /* inherit */ |
610 | SvREFCNT_dec (GvAV (PL_defgv)); |
641 | SvREFCNT_dec (GvAV (PL_defgv)); |
611 | GvAV (PL_defgv) = ctx->args; |
642 | GvAV (PL_defgv) = ctx->args; ctx->args = 0; |
612 | |
643 | |
613 | SPAGAIN; |
644 | SPAGAIN; |
614 | |
645 | |
615 | if (ctx->stack) |
646 | if (ctx->stack) |
616 | { |
647 | { |
… | |
… | |
656 | continue_coro (void *arg) |
687 | continue_coro (void *arg) |
657 | { |
688 | { |
658 | /* |
689 | /* |
659 | * this is a _very_ stripped down perl interpreter ;) |
690 | * this is a _very_ stripped down perl interpreter ;) |
660 | */ |
691 | */ |
|
|
692 | dTHX; |
661 | Coro__State ctx = (Coro__State)arg; |
693 | Coro__State ctx = (Coro__State)arg; |
662 | JMPENV coro_start_env; |
694 | JMPENV coro_start_env; |
663 | |
695 | |
664 | PL_top_env = &ctx->start_env; |
696 | PL_top_env = &ctx->start_env; |
665 | |
697 | |
… | |
… | |
669 | |
701 | |
670 | abort (); |
702 | abort (); |
671 | } |
703 | } |
672 | |
704 | |
673 | STATIC void |
705 | STATIC void |
674 | transfer(pTHX_ struct coro *prev, struct coro *next, int flags) |
706 | transfer (pTHX_ struct coro *prev, struct coro *next, int flags) |
675 | { |
707 | { |
676 | dSTACKLEVEL; |
708 | dSTACKLEVEL; |
677 | static struct coro *xnext; |
|
|
678 | |
709 | |
679 | if (prev != next) |
710 | if (prev != next) |
680 | { |
711 | { |
681 | xnext = next; |
|
|
682 | |
|
|
683 | if (next->mainstack) |
712 | if (next->mainstack) |
684 | { |
713 | { |
|
|
714 | LOCK; |
685 | SAVE (prev, flags); |
715 | SAVE (prev, flags); |
686 | LOAD (next); |
716 | LOAD (next); |
|
|
717 | UNLOCK; |
687 | |
718 | |
688 | /* mark this state as in-use */ |
719 | /* mark this state as in-use */ |
689 | next->mainstack = 0; |
720 | next->mainstack = 0; |
690 | next->tmps_ix = -2; |
721 | next->tmps_ix = -2; |
691 | |
722 | |
… | |
… | |
710 | continue_coro, (void *)next, |
741 | continue_coro, (void *)next, |
711 | next->stack->sptr, labs (next->stack->ssize)); |
742 | next->stack->sptr, labs (next->stack->ssize)); |
712 | } |
743 | } |
713 | |
744 | |
714 | coro_transfer (&(prev->stack->cctx), &(next->stack->cctx)); |
745 | coro_transfer (&(prev->stack->cctx), &(next->stack->cctx)); |
|
|
746 | prev->cursp = stacklevel; |
715 | /* don't add any code here */ |
747 | /* don't add any code here */ |
716 | } |
748 | } |
717 | |
749 | else |
|
|
750 | next->cursp = stacklevel; |
718 | } |
751 | } |
719 | else if (next->tmps_ix == -2) |
752 | else if (next->tmps_ix == -2) |
720 | croak ("tried to transfer to running coroutine"); |
753 | croak ("tried to transfer to running coroutine"); |
721 | else |
754 | else |
722 | { |
755 | { |
|
|
756 | LOCK; |
723 | SAVE (prev, -1); /* first get rid of the old state */ |
757 | SAVE (prev, -1); /* first get rid of the old state */ |
|
|
758 | UNLOCK; |
724 | |
759 | |
725 | if (flags & TRANSFER_SAVE_CCTXT) |
760 | if (flags & TRANSFER_SAVE_CCTXT) |
726 | { |
761 | { |
727 | if (!prev->stack) |
762 | if (!prev->stack) |
728 | allocate_stack (prev, 0); |
763 | allocate_stack (prev, 0); |
… | |
… | |
730 | if (prev->stack->sptr && flags & TRANSFER_LAZY_STACK) |
765 | if (prev->stack->sptr && flags & TRANSFER_LAZY_STACK) |
731 | { |
766 | { |
732 | PL_top_env = &next->start_env; |
767 | PL_top_env = &next->start_env; |
733 | |
768 | |
734 | setup_coro (next); |
769 | setup_coro (next); |
|
|
770 | next->cursp = stacklevel; |
735 | |
771 | |
736 | prev->stack->refcnt++; |
772 | prev->stack->refcnt++; |
737 | prev->stack->usecnt++; |
773 | prev->stack->usecnt++; |
738 | next->stack = prev->stack; |
774 | next->stack = prev->stack; |
739 | next->gencnt = prev->gencnt; |
775 | next->gencnt = prev->gencnt; |
740 | } |
776 | } |
741 | else |
777 | else |
742 | { |
778 | { |
|
|
779 | assert (!next->stack); |
743 | allocate_stack (next, 1); |
780 | allocate_stack (next, 1); |
744 | coro_create (&(next->stack->cctx), |
781 | coro_create (&(next->stack->cctx), |
745 | setup_coro, (void *)next, |
782 | setup_coro, (void *)next, |
746 | next->stack->sptr, labs (next->stack->ssize)); |
783 | next->stack->sptr, labs (next->stack->ssize)); |
747 | coro_transfer (&(prev->stack->cctx), &(next->stack->cctx)); |
784 | coro_transfer (&(prev->stack->cctx), &(next->stack->cctx)); |
|
|
785 | prev->cursp = stacklevel; |
748 | /* don't add any code here */ |
786 | /* don't add any code here */ |
749 | } |
787 | } |
750 | } |
788 | } |
751 | else |
789 | else |
|
|
790 | { |
752 | setup_coro (next); |
791 | setup_coro (next); |
|
|
792 | next->cursp = stacklevel; |
|
|
793 | } |
753 | } |
794 | } |
754 | |
|
|
755 | /* |
|
|
756 | * xnext is now either prev or next, depending on wether |
|
|
757 | * we switched the c stack or not. that's why I use a global |
|
|
758 | * variable, that should become thread-specific at one point. |
|
|
759 | */ |
|
|
760 | xnext->cursp = stacklevel; |
|
|
761 | } |
795 | } |
762 | |
796 | |
|
|
797 | LOCK; |
763 | if (coro_mortal) |
798 | if (coro_mortal) |
764 | { |
799 | { |
765 | SvREFCNT_dec (coro_mortal); |
800 | SvREFCNT_dec (coro_mortal); |
766 | coro_mortal = 0; |
801 | coro_mortal = 0; |
767 | } |
802 | } |
|
|
803 | UNLOCK; |
768 | } |
804 | } |
769 | |
805 | |
770 | #define SV_CORO(sv,func) \ |
806 | #define SV_CORO(sv,func) \ |
771 | do { \ |
807 | do { \ |
772 | if (SvROK (sv)) \ |
808 | if (SvROK (sv)) \ |
773 | sv = SvRV (sv); \ |
809 | sv = SvRV (sv); \ |
774 | \ |
810 | \ |
775 | if (SvTYPE(sv) == SVt_PVHV) \ |
811 | if (SvTYPE (sv) == SVt_PVHV) \ |
776 | { \ |
812 | { \ |
777 | HE *he = hv_fetch_ent((HV *)sv, ucoro_state_sv, 0, ucoro_state_hash); \ |
813 | HE *he = hv_fetch_ent ((HV *)sv, ucoro_state_sv, 0, ucoro_state_hash); \ |
778 | \ |
814 | \ |
779 | if (!he) \ |
815 | if (!he) \ |
780 | croak ("%s() -- %s is a hashref but lacks the " UCORO_STATE " key", func, # sv); \ |
816 | croak ("%s() -- %s is a hashref but lacks the " UCORO_STATE " key", func, # sv); \ |
781 | \ |
817 | \ |
782 | (sv) = SvRV (HeVAL(he)); \ |
818 | (sv) = SvRV (HeVAL(he)); \ |
783 | } \ |
819 | } \ |
784 | \ |
820 | \ |
785 | /* must also be changed inside Coro::Cont::yield */ \ |
821 | /* must also be changed inside Coro::Cont::yield */ \ |
786 | if (!SvOBJECT(sv) || SvSTASH(sv) != coro_state_stash) \ |
822 | if (!SvOBJECT (sv) || SvSTASH (sv) != coro_state_stash) \ |
787 | croak ("%s() -- %s is not (and contains not) a Coro::State object", func, # sv); \ |
823 | croak ("%s() -- %s is not (and contains not) a Coro::State object", func, # sv); \ |
788 | \ |
824 | \ |
789 | } while(0) |
825 | } while(0) |
790 | |
826 | |
791 | #define SvSTATE(sv) (struct coro *)SvIV (sv) |
827 | #define SvSTATE(sv) (struct coro *)SvIV (sv) |
… | |
… | |
794 | api_transfer(pTHX_ SV *prev, SV *next, int flags) |
830 | api_transfer(pTHX_ SV *prev, SV *next, int flags) |
795 | { |
831 | { |
796 | SV_CORO (prev, "Coro::transfer"); |
832 | SV_CORO (prev, "Coro::transfer"); |
797 | SV_CORO (next, "Coro::transfer"); |
833 | SV_CORO (next, "Coro::transfer"); |
798 | |
834 | |
799 | transfer(aTHX_ SvSTATE(prev), SvSTATE(next), flags); |
835 | transfer (aTHX_ SvSTATE (prev), SvSTATE (next), flags); |
800 | } |
836 | } |
801 | |
837 | |
802 | /** Coro ********************************************************************/ |
838 | /** Coro ********************************************************************/ |
803 | |
839 | |
804 | #define PRIO_MAX 3 |
840 | #define PRIO_MAX 3 |
… | |
… | |
812 | static GV *coro_current, *coro_idle; |
848 | static GV *coro_current, *coro_idle; |
813 | static AV *coro_ready[PRIO_MAX-PRIO_MIN+1]; |
849 | static AV *coro_ready[PRIO_MAX-PRIO_MIN+1]; |
814 | static int coro_nready; |
850 | static int coro_nready; |
815 | |
851 | |
816 | static void |
852 | static void |
817 | coro_enq (SV *sv) |
853 | coro_enq (pTHX_ SV *sv) |
818 | { |
854 | { |
819 | if (SvTYPE (sv) == SVt_PVHV) |
855 | if (SvTYPE (sv) == SVt_PVHV) |
820 | { |
856 | { |
821 | SV **xprio = hv_fetch ((HV *)sv, "prio", 4, 0); |
857 | SV **xprio = hv_fetch ((HV *)sv, "prio", 4, 0); |
822 | int prio = xprio ? SvIV (*xprio) : PRIO_NORMAL; |
858 | int prio = xprio ? SvIV (*xprio) : PRIO_NORMAL; |
… | |
… | |
833 | |
869 | |
834 | croak ("Coro::ready tried to enqueue something that is not a coroutine"); |
870 | croak ("Coro::ready tried to enqueue something that is not a coroutine"); |
835 | } |
871 | } |
836 | |
872 | |
837 | static SV * |
873 | static SV * |
838 | coro_deq (int min_prio) |
874 | coro_deq (pTHX_ int min_prio) |
839 | { |
875 | { |
840 | int prio = PRIO_MAX - PRIO_MIN; |
876 | int prio = PRIO_MAX - PRIO_MIN; |
841 | |
877 | |
842 | min_prio -= PRIO_MIN; |
878 | min_prio -= PRIO_MIN; |
843 | if (min_prio < 0) |
879 | if (min_prio < 0) |
… | |
… | |
854 | } |
890 | } |
855 | |
891 | |
856 | static void |
892 | static void |
857 | api_ready (SV *coro) |
893 | api_ready (SV *coro) |
858 | { |
894 | { |
|
|
895 | dTHX; |
|
|
896 | |
859 | if (SvROK (coro)) |
897 | if (SvROK (coro)) |
860 | coro = SvRV (coro); |
898 | coro = SvRV (coro); |
861 | |
899 | |
|
|
900 | LOCK; |
862 | coro_enq (SvREFCNT_inc (coro)); |
901 | coro_enq (aTHX_ SvREFCNT_inc (coro)); |
|
|
902 | UNLOCK; |
863 | } |
903 | } |
864 | |
904 | |
865 | static void |
905 | static void |
866 | api_schedule (void) |
906 | api_schedule (void) |
867 | { |
907 | { |
|
|
908 | dTHX; |
|
|
909 | |
868 | SV *prev, *next; |
910 | SV *prev, *next; |
869 | |
911 | |
|
|
912 | LOCK; |
|
|
913 | |
870 | prev = SvRV (GvSV (coro_current)); |
914 | prev = SvRV (GvSV (coro_current)); |
871 | next = coro_deq (PRIO_MIN); |
915 | next = coro_deq (aTHX_ PRIO_MIN); |
872 | |
916 | |
873 | if (!next) |
917 | if (!next) |
874 | next = SvREFCNT_inc (SvRV (GvSV (coro_idle))); |
918 | next = SvREFCNT_inc (SvRV (GvSV (coro_idle))); |
875 | |
919 | |
876 | /* free this only after the transfer */ |
920 | /* free this only after the transfer */ |
… | |
… | |
879 | |
923 | |
880 | SvRV (GvSV (coro_current)) = next; |
924 | SvRV (GvSV (coro_current)) = next; |
881 | |
925 | |
882 | SV_CORO (next, "Coro::schedule"); |
926 | SV_CORO (next, "Coro::schedule"); |
883 | |
927 | |
|
|
928 | UNLOCK; |
|
|
929 | |
884 | transfer (aTHX_ SvSTATE (prev), SvSTATE (next), |
930 | transfer (aTHX_ SvSTATE (prev), SvSTATE (next), |
885 | TRANSFER_SAVE_ALL | TRANSFER_LAZY_STACK); |
931 | TRANSFER_SAVE_ALL | TRANSFER_LAZY_STACK); |
886 | } |
932 | } |
887 | |
933 | |
888 | static void |
934 | static void |
889 | api_cede (void) |
935 | api_cede (void) |
890 | { |
936 | { |
|
|
937 | dTHX; |
|
|
938 | |
|
|
939 | LOCK; |
891 | coro_enq (SvREFCNT_inc (SvRV (GvSV (coro_current)))); |
940 | coro_enq (aTHX_ SvREFCNT_inc (SvRV (GvSV (coro_current)))); |
|
|
941 | UNLOCK; |
892 | |
942 | |
893 | api_schedule (); |
943 | api_schedule (); |
894 | } |
944 | } |
895 | |
945 | |
896 | MODULE = Coro::State PACKAGE = Coro::State |
946 | MODULE = Coro::State PACKAGE = Coro::State |
897 | |
947 | |
898 | PROTOTYPES: ENABLE |
948 | PROTOTYPES: ENABLE |
899 | |
949 | |
900 | BOOT: |
950 | BOOT: |
901 | { /* {} necessary for stoopid perl-5.6.x */ |
951 | { /* {} necessary for stoopid perl-5.6.x */ |
|
|
952 | #ifdef USE_ITHREADS |
|
|
953 | MUTEX_INIT (&coro_mutex); |
|
|
954 | #endif |
|
|
955 | |
902 | ucoro_state_sv = newSVpv (UCORO_STATE, sizeof(UCORO_STATE) - 1); |
956 | ucoro_state_sv = newSVpv (UCORO_STATE, sizeof(UCORO_STATE) - 1); |
903 | PERL_HASH(ucoro_state_hash, UCORO_STATE, sizeof(UCORO_STATE) - 1); |
957 | PERL_HASH(ucoro_state_hash, UCORO_STATE, sizeof(UCORO_STATE) - 1); |
904 | coro_state_stash = gv_stashpv ("Coro::State", TRUE); |
958 | coro_state_stash = gv_stashpv ("Coro::State", TRUE); |
905 | |
959 | |
906 | newCONSTSUB (coro_state_stash, "SAVE_DEFAV", newSViv (TRANSFER_SAVE_DEFAV)); |
960 | newCONSTSUB (coro_state_stash, "SAVE_DEFAV", newSViv (TRANSFER_SAVE_DEFAV)); |
907 | newCONSTSUB (coro_state_stash, "SAVE_DEFSV", newSViv (TRANSFER_SAVE_DEFSV)); |
961 | newCONSTSUB (coro_state_stash, "SAVE_DEFSV", newSViv (TRANSFER_SAVE_DEFSV)); |
908 | newCONSTSUB (coro_state_stash, "SAVE_ERRSV", newSViv (TRANSFER_SAVE_ERRSV)); |
962 | newCONSTSUB (coro_state_stash, "SAVE_ERRSV", newSViv (TRANSFER_SAVE_ERRSV)); |
909 | newCONSTSUB (coro_state_stash, "SAVE_CCTXT", newSViv (TRANSFER_SAVE_CCTXT)); |
963 | newCONSTSUB (coro_state_stash, "SAVE_CCTXT", newSViv (TRANSFER_SAVE_CCTXT)); |
910 | |
|
|
911 | if (!padlist_cache) |
|
|
912 | padlist_cache = newHV (); |
|
|
913 | |
964 | |
914 | main_mainstack = PL_mainstack; |
965 | main_mainstack = PL_mainstack; |
915 | |
966 | |
916 | coroapi.ver = CORO_API_VERSION; |
967 | coroapi.ver = CORO_API_VERSION; |
917 | coroapi.transfer = api_transfer; |
968 | coroapi.transfer = api_transfer; |
… | |
… | |
925 | Coro__State coro; |
976 | Coro__State coro; |
926 | |
977 | |
927 | if (!SvROK (args) || SvTYPE (SvRV (args)) != SVt_PVAV) |
978 | if (!SvROK (args) || SvTYPE (SvRV (args)) != SVt_PVAV) |
928 | croak ("Coro::State::_newprocess expects an arrayref"); |
979 | croak ("Coro::State::_newprocess expects an arrayref"); |
929 | |
980 | |
930 | New (0, coro, 1, struct coro); |
981 | Newz (0, coro, 1, struct coro); |
931 | |
982 | |
932 | coro->args = (AV *)SvREFCNT_inc (SvRV (args)); |
983 | coro->args = (AV *)SvREFCNT_inc (SvRV (args)); |
933 | coro->mainstack = 0; /* actual work is done inside transfer */ |
984 | coro->mainstack = 0; /* actual work is done inside transfer */ |
934 | coro->stack = 0; |
985 | coro->stack = 0; |
935 | |
986 | |
936 | /* same as JMPENV_BOOTSTRAP */ |
987 | /* same as JMPENV_BOOTSTRAP */ |
937 | /* we might be able to recycle start_env, but safe is safe */ |
988 | /* we might be able to recycle start_env, but safe is safe */ |
938 | Zero(&coro->start_env, 1, JMPENV); |
989 | //Zero(&coro->start_env, 1, JMPENV); |
939 | coro->start_env.je_ret = -1; |
990 | coro->start_env.je_ret = -1; |
940 | coro->start_env.je_mustcatch = TRUE; |
991 | coro->start_env.je_mustcatch = TRUE; |
941 | |
992 | |
942 | RETVAL = coro; |
993 | RETVAL = coro; |
943 | OUTPUT: |
994 | OUTPUT: |
… | |
… | |
977 | |
1028 | |
978 | coro->mainstack = 0; |
1029 | coro->mainstack = 0; |
979 | } |
1030 | } |
980 | |
1031 | |
981 | deallocate_stack (coro); |
1032 | deallocate_stack (coro); |
982 | |
1033 | SvREFCNT_dec (coro->args); |
983 | Safefree (coro); |
1034 | Safefree (coro); |
984 | |
|
|
985 | void |
|
|
986 | flush() |
|
|
987 | CODE: |
|
|
988 | #ifdef MAY_FLUSH |
|
|
989 | flush_padlist_cache (); |
|
|
990 | #endif |
|
|
991 | |
1035 | |
992 | void |
1036 | void |
993 | _exit(code) |
1037 | _exit(code) |
994 | int code |
1038 | int code |
995 | PROTOTYPE: $ |
1039 | PROTOTYPE: $ |
996 | CODE: |
1040 | CODE: |
997 | #if defined(__GLIBC__) || _POSIX_C_SOURCE |
|
|
998 | _exit (code); |
1041 | _exit (code); |
999 | #else |
|
|
1000 | signal (SIGTERM, SIG_DFL); |
|
|
1001 | raise (SIGTERM); |
|
|
1002 | exit (code); |
|
|
1003 | #endif |
|
|
1004 | |
1042 | |
1005 | MODULE = Coro::State PACKAGE = Coro::Cont |
1043 | MODULE = Coro::State PACKAGE = Coro::Cont |
1006 | |
1044 | |
1007 | # this is slightly dirty (should expose a c-level api) |
1045 | # this is slightly dirty (should expose a c-level api) |
1008 | |
1046 | |
… | |
… | |
1014 | SV *sv; |
1052 | SV *sv; |
1015 | AV *defav = GvAV (PL_defgv); |
1053 | AV *defav = GvAV (PL_defgv); |
1016 | struct coro *prev, *next; |
1054 | struct coro *prev, *next; |
1017 | |
1055 | |
1018 | if (!returnstk) |
1056 | if (!returnstk) |
1019 | returnstk = SvRV (get_sv ("Coro::Cont::return", FALSE)); |
1057 | returnstk = SvRV ((SV *)get_sv ("Coro::Cont::return", FALSE)); |
1020 | |
1058 | |
1021 | /* set up @_ -- ugly */ |
1059 | /* set up @_ -- ugly */ |
1022 | av_clear (defav); |
1060 | av_clear (defav); |
1023 | av_fill (defav, items - 1); |
1061 | av_fill (defav, items - 1); |
1024 | while (items--) |
1062 | while (items--) |
… | |
… | |
1067 | sv_setiv(sv, (IV)&coroapi); |
1105 | sv_setiv(sv, (IV)&coroapi); |
1068 | SvREADONLY_on(sv); |
1106 | SvREADONLY_on(sv); |
1069 | } |
1107 | } |
1070 | } |
1108 | } |
1071 | |
1109 | |
|
|
1110 | #if !PERL_MICRO |
|
|
1111 | |
1072 | void |
1112 | void |
1073 | ready(self) |
1113 | ready(self) |
1074 | SV * self |
1114 | SV * self |
1075 | PROTOTYPE: $ |
1115 | PROTOTYPE: $ |
1076 | CODE: |
1116 | CODE: |
1077 | api_ready (self); |
1117 | api_ready (self); |
|
|
1118 | |
|
|
1119 | #endif |
1078 | |
1120 | |
1079 | int |
1121 | int |
1080 | nready(...) |
1122 | nready(...) |
1081 | PROTOTYPE: |
1123 | PROTOTYPE: |
1082 | CODE: |
1124 | CODE: |