ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Coro/Coro/State.xs
(Generate patch)

Comparing Coro/Coro/State.xs (file contents):
Revision 1.151 by root, Wed Sep 19 21:39:15 2007 UTC vs.
Revision 1.153 by root, Thu Sep 20 12:18:00 2007 UTC

210 210
211/* for Coro.pm */ 211/* for Coro.pm */
212static SV *coro_current; 212static SV *coro_current;
213static AV *coro_ready [PRIO_MAX-PRIO_MIN+1]; 213static AV *coro_ready [PRIO_MAX-PRIO_MIN+1];
214static int coro_nready; 214static int coro_nready;
215static struct coro *first; 215static struct coro *coro_first;
216 216
217/** lowlevel stuff **********************************************************/ 217/** lowlevel stuff **********************************************************/
218 218
219static AV * 219static AV *
220coro_clone_padlist (pTHX_ CV *cv) 220coro_clone_padlist (pTHX_ CV *cv)
538 Safefree (PL_scopestack); 538 Safefree (PL_scopestack);
539 Safefree (PL_savestack); 539 Safefree (PL_savestack);
540#if !PERL_VERSION_ATLEAST (5,9,0) 540#if !PERL_VERSION_ATLEAST (5,9,0)
541 Safefree (PL_retstack); 541 Safefree (PL_retstack);
542#endif 542#endif
543}
544
545static size_t
546coro_rss (struct coro *coro)
547{
548 size_t rss = sizeof (coro);
549
550 if (coro->mainstack)
551 {
552 if (coro->flags & CF_RUNNING)
553 {
554 #define VAR(name,type)coro->name = PL_ ## name;
555 # include "state.h"
556 #undef VAR
557 }
558
559 rss += sizeof (coro->curstackinfo);
560 rss += sizeof (struct xpvav) + (1 + AvFILL (coro->curstackinfo->si_stack)) * sizeof (SV *);
561 rss += (coro->curstackinfo->si_cxmax + 1) * sizeof (PERL_CONTEXT);
562 rss += sizeof (struct xpvav) + (1 + AvFILL (coro->curstack)) * sizeof (SV *);
563 rss += coro->tmps_max * sizeof (SV *);
564 rss += (coro->markstack_max - coro->markstack_ptr) * sizeof (I32);
565 rss += coro->scopestack_max * sizeof (I32);
566 rss += coro->savestack_max * sizeof (ANY);
567
568#if !PERL_VERSION_ATLEAST (5,9,0)
569 rss += coro->retstack_max * sizeof (OP *);
570#endif
571 }
572
573 return rss;
543} 574}
544 575
545/** coroutine stack handling ************************************************/ 576/** coroutine stack handling ************************************************/
546 577
547static void 578static void
900 cctx_destroy (coro->cctx); 931 cctx_destroy (coro->cctx);
901 SvREFCNT_dec (coro->args); 932 SvREFCNT_dec (coro->args);
902 933
903 if (coro->next) coro->next->prev = coro->prev; 934 if (coro->next) coro->next->prev = coro->prev;
904 if (coro->prev) coro->prev->next = coro->next; 935 if (coro->prev) coro->prev->next = coro->next;
905 if (coro == first) first = coro->next; 936 if (coro == coro_first) coro_first = coro->next;
906 937
907 return 1; 938 return 1;
908} 939}
909 940
910static int 941static int
1218 Newz (0, coro, 1, struct coro); 1249 Newz (0, coro, 1, struct coro);
1219 coro->args = newAV (); 1250 coro->args = newAV ();
1220 coro->save = CORO_SAVE_DEF; 1251 coro->save = CORO_SAVE_DEF;
1221 coro->flags = CF_NEW; 1252 coro->flags = CF_NEW;
1222 1253
1223 if (first) first->prev = coro; 1254 if (coro_first) coro_first->prev = coro;
1224 coro->next = first; 1255 coro->next = coro_first;
1225 first = coro; 1256 coro_first = coro;
1226 1257
1227 coro->hv = hv = newHV (); 1258 coro->hv = hv = newHV ();
1228 sv_magicext ((SV *)hv, 0, PERL_MAGIC_ext, &coro_state_vtbl, (char *)coro, 0)->mg_flags |= MGf_DUP; 1259 sv_magicext ((SV *)hv, 0, PERL_MAGIC_ext, &coro_state_vtbl, (char *)coro, 0)->mg_flags |= MGf_DUP;
1229 RETVAL = sv_bless (newRV_noinc ((SV *)hv), gv_stashpv (klass, 1)); 1260 RETVAL = sv_bless (newRV_noinc ((SV *)hv), gv_stashpv (klass, 1));
1230 1261
1339void 1370void
1340list () 1371list ()
1341 PPCODE: 1372 PPCODE:
1342{ 1373{
1343 struct coro *coro; 1374 struct coro *coro;
1344 for (coro = first; coro; coro = coro->next) 1375 for (coro = coro_first; coro; coro = coro->next)
1345 if (coro->hv) 1376 if (coro->hv)
1346 XPUSHs (sv_2mortal (newRV_inc ((SV *)coro->hv))); 1377 XPUSHs (sv_2mortal (newRV_inc ((SV *)coro->hv)));
1347} 1378}
1348 1379
1349void 1380void
1350_eval (SV *coro_sv, SV *coderef) 1381_eval (Coro::State coro, SV *coderef)
1351 CODE: 1382 CODE:
1352{ 1383{
1353 struct coro *coro = SvSTATE (coro_sv);
1354 if (coro->mainstack) 1384 if (coro->mainstack)
1355 { 1385 {
1356 struct coro temp; 1386 struct coro temp;
1357 Zero (&temp, 1, struct coro); 1387 Zero (&temp, 1, struct coro);
1358 temp.save = CORO_SAVE_ALL; 1388 temp.save = CORO_SAVE_ALL;
1383 } 1413 }
1384 } 1414 }
1385} 1415}
1386 1416
1387SV * 1417SV *
1388is_ready (SV *coro_sv) 1418is_ready (Coro::State coro)
1389 PROTOTYPE: $ 1419 PROTOTYPE: $
1390 ALIAS: 1420 ALIAS:
1391 is_ready = CF_READY 1421 is_ready = CF_READY
1392 is_running = CF_RUNNING 1422 is_running = CF_RUNNING
1393 is_new = CF_NEW 1423 is_new = CF_NEW
1394 is_destroyed = CF_DESTROYED 1424 is_destroyed = CF_DESTROYED
1395 CODE: 1425 CODE:
1396 struct coro *coro = SvSTATE (coro_sv);
1397 RETVAL = boolSV (coro->flags & ix); 1426 RETVAL = boolSV (coro->flags & ix);
1427 OUTPUT:
1428 RETVAL
1429
1430IV
1431rss (Coro::State coro)
1432 PROTOTYPE: $
1433 CODE:
1434 RETVAL = coro_rss (coro);
1398 OUTPUT: 1435 OUTPUT:
1399 RETVAL 1436 RETVAL
1400 1437
1401 1438
1402MODULE = Coro::State PACKAGE = Coro 1439MODULE = Coro::State PACKAGE = Coro

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines