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.348 by root, Wed Jun 10 00:20:26 2009 UTC vs.
Revision 1.354 by root, Tue Jun 23 00:56:14 2009 UTC

137 137
138#define IN_DESTRUCT PL_dirty 138#define IN_DESTRUCT PL_dirty
139 139
140#if __GNUC__ >= 3 140#if __GNUC__ >= 3
141# define attribute(x) __attribute__(x) 141# define attribute(x) __attribute__(x)
142# define expect(expr,value) __builtin_expect ((expr),(value)) 142# define expect(expr,value) __builtin_expect ((expr), (value))
143# define INLINE static inline 143# define INLINE static inline
144#else 144#else
145# define attribute(x) 145# define attribute(x)
146# define expect(expr,value) (expr) 146# define expect(expr,value) (expr)
147# define INLINE static 147# define INLINE static
615 { 615 {
616 while (expect_true (cxix >= 0)) 616 while (expect_true (cxix >= 0))
617 { 617 {
618 PERL_CONTEXT *cx = &ccstk[cxix--]; 618 PERL_CONTEXT *cx = &ccstk[cxix--];
619 619
620 if (expect_true (CxTYPE (cx) == CXt_SUB || CxTYPE (cx) == CXt_FORMAT)) 620 if (expect_true (CxTYPE (cx) == CXt_SUB) || expect_false (CxTYPE (cx) == CXt_FORMAT))
621 { 621 {
622 CV *cv = cx->blk_sub.cv; 622 CV *cv = cx->blk_sub.cv;
623 623
624 if (expect_true (CvDEPTH (cv))) 624 if (expect_true (CvDEPTH (cv)))
625 { 625 {
990} 990}
991 991
992static void 992static void
993coro_destruct_perl (pTHX_ struct coro *coro) 993coro_destruct_perl (pTHX_ struct coro *coro)
994{ 994{
995 SV *svf [9];
996
997 {
998 struct coro *current = SvSTATE_current;
999
1000 assert (("FATAL: tried to destroy currently running coroutine", coro->mainstack != PL_mainstack));
1001
1002 save_perl (aTHX_ current);
1003 load_perl (aTHX_ coro);
1004
995 coro_unwind_stacks (aTHX); 1005 coro_unwind_stacks (aTHX);
1006 coro_destruct_stacks (aTHX);
996 1007
997 SvREFCNT_dec (GvSV (PL_defgv)); 1008 // now save some sv's to be free'd later
998 SvREFCNT_dec (GvAV (PL_defgv)); 1009 svf [0] = GvSV (PL_defgv);
999 SvREFCNT_dec (GvSV (PL_errgv)); 1010 svf [1] = (SV *)GvAV (PL_defgv);
1000 SvREFCNT_dec (PL_defoutgv); 1011 svf [2] = GvSV (PL_errgv);
1001 SvREFCNT_dec (PL_rs); 1012 svf [3] = (SV *)PL_defoutgv;
1002 SvREFCNT_dec (GvSV (irsgv)); 1013 svf [4] = PL_rs;
1003 SvREFCNT_dec (GvHV (PL_hintgv)); 1014 svf [5] = GvSV (irsgv);
1015 svf [6] = (SV *)GvHV (PL_hintgv);
1016 svf [7] = PL_diehook;
1017 svf [8] = PL_warnhook;
1018 assert (9 == sizeof (svf) / sizeof (*svf));
1004 1019
1005 SvREFCNT_dec (PL_diehook); 1020 load_perl (aTHX_ current);
1006 SvREFCNT_dec (PL_warnhook);
1007 1021 }
1022
1023 {
1024 int i;
1025
1026 for (i = 0; i < sizeof (svf) / sizeof (*svf); ++i)
1027 SvREFCNT_dec (svf [i]);
1028
1008 SvREFCNT_dec (coro->saved_deffh); 1029 SvREFCNT_dec (coro->saved_deffh);
1009 SvREFCNT_dec (coro->rouse_cb); 1030 SvREFCNT_dec (coro->rouse_cb);
1010 SvREFCNT_dec (coro->invoke_cb); 1031 SvREFCNT_dec (coro->invoke_cb);
1011 SvREFCNT_dec (coro->invoke_av); 1032 SvREFCNT_dec (coro->invoke_av);
1012 1033 }
1013 coro_destruct_stacks (aTHX);
1014} 1034}
1015 1035
1016INLINE void 1036INLINE void
1017free_coro_mortal (pTHX) 1037free_coro_mortal (pTHX)
1018{ 1038{
1505 1525
1506 if (coro->mainstack 1526 if (coro->mainstack
1507 && coro->mainstack != main_mainstack 1527 && coro->mainstack != main_mainstack
1508 && coro->slot 1528 && coro->slot
1509 && !PL_dirty) 1529 && !PL_dirty)
1510 {
1511 struct coro *current = SvSTATE_current;
1512
1513 assert (("FATAL: tried to destroy currently running coroutine", coro->mainstack != PL_mainstack));
1514
1515 save_perl (aTHX_ current);
1516 load_perl (aTHX_ coro);
1517
1518 coro_destruct_perl (aTHX_ coro); 1530 coro_destruct_perl (aTHX_ coro);
1519
1520 load_perl (aTHX_ current);
1521
1522 coro->slot = 0;
1523 }
1524 1531
1525 cctx_destroy (coro->cctx); 1532 cctx_destroy (coro->cctx);
1526 SvREFCNT_dec (coro->startcv); 1533 SvREFCNT_dec (coro->startcv);
1527 SvREFCNT_dec (coro->args); 1534 SvREFCNT_dec (coro->args);
1528 SvREFCNT_dec (CORO_THROW); 1535 SvREFCNT_dec (CORO_THROW);
2470/* Coro::Semaphore & Coro::Signal */ 2477/* Coro::Semaphore & Coro::Signal */
2471 2478
2472static SV * 2479static SV *
2473coro_waitarray_new (pTHX_ int count) 2480coro_waitarray_new (pTHX_ int count)
2474{ 2481{
2475 /* a semaphore contains a counter IV in $sem->[0] and any waiters after that */ 2482 /* a waitarray=semaphore contains a counter IV in $sem->[0] and any waiters after that */
2476 AV *av = newAV (); 2483 AV *av = newAV ();
2477 SV **ary; 2484 SV **ary;
2478 2485
2479 /* unfortunately, building manually saves memory */ 2486 /* unfortunately, building manually saves memory */
2480 Newx (ary, 2, SV *); 2487 Newx (ary, 2, SV *);
3221 3228
3222MODULE = Coro::State PACKAGE = Coro 3229MODULE = Coro::State PACKAGE = Coro
3223 3230
3224BOOT: 3231BOOT:
3225{ 3232{
3226 int i;
3227
3228 sv_pool_rss = coro_get_sv (aTHX_ "Coro::POOL_RSS" , TRUE); 3233 sv_pool_rss = coro_get_sv (aTHX_ "Coro::POOL_RSS" , TRUE);
3229 sv_pool_size = coro_get_sv (aTHX_ "Coro::POOL_SIZE" , TRUE); 3234 sv_pool_size = coro_get_sv (aTHX_ "Coro::POOL_SIZE" , TRUE);
3230 cv_coro_run = get_cv ( "Coro::_coro_run" , GV_ADD); 3235 cv_coro_run = get_cv ( "Coro::_coro_run" , GV_ADD);
3231 cv_coro_terminate = get_cv ( "Coro::terminate" , GV_ADD); 3236 cv_coro_terminate = get_cv ( "Coro::terminate" , GV_ADD);
3232 coro_current = coro_get_sv (aTHX_ "Coro::current" , FALSE); SvREADONLY_on (coro_current); 3237 coro_current = coro_get_sv (aTHX_ "Coro::current" , FALSE); SvREADONLY_on (coro_current);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines