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.340 by root, Mon Dec 15 00:30:40 2008 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
238enum { 238enum {
239 CF_RUNNING = 0x0001, /* coroutine is running */ 239 CF_RUNNING = 0x0001, /* coroutine is running */
240 CF_READY = 0x0002, /* coroutine is ready */ 240 CF_READY = 0x0002, /* coroutine is ready */
241 CF_NEW = 0x0004, /* has never been switched to */ 241 CF_NEW = 0x0004, /* has never been switched to */
242 CF_DESTROYED = 0x0008, /* coroutine data has been freed */ 242 CF_DESTROYED = 0x0008, /* coroutine data has been freed */
243 CF_SUSPENDED = 0x0010, /* coroutine can't be scheduled */
243}; 244};
244 245
245/* the structure where most of the perl state is stored, overlaid on the cxstack */ 246/* the structure where most of the perl state is stored, overlaid on the cxstack */
246typedef struct 247typedef struct
247{ 248{
260/* this is a structure representing a perl-level coroutine */ 261/* this is a structure representing a perl-level coroutine */
261struct coro { 262struct coro {
262 /* the C coroutine allocated to this perl coroutine, if any */ 263 /* the C coroutine allocated to this perl coroutine, if any */
263 coro_cctx *cctx; 264 coro_cctx *cctx;
264 265
266 /* ready queue */
267 struct coro *next_ready;
268
265 /* state data */ 269 /* state data */
266 struct CoroSLF slf_frame; /* saved slf frame */ 270 struct CoroSLF slf_frame; /* saved slf frame */
267 AV *mainstack; 271 AV *mainstack;
268 perl_slots *slot; /* basically the saved sp */ 272 perl_slots *slot; /* basically the saved sp */
269 273
313#define PRIO_MIN -4 317#define PRIO_MIN -4
314 318
315/* for Coro.pm */ 319/* for Coro.pm */
316static SV *coro_current; 320static SV *coro_current;
317static SV *coro_readyhook; 321static SV *coro_readyhook;
318static AV *coro_ready [PRIO_MAX - PRIO_MIN + 1]; 322static struct coro *coro_ready [PRIO_MAX - PRIO_MIN + 1][2]; /* head|tail */
319static CV *cv_coro_run, *cv_coro_terminate; 323static CV *cv_coro_run, *cv_coro_terminate;
320static struct coro *coro_first; 324static struct coro *coro_first;
321#define coro_nready coroapi.nready 325#define coro_nready coroapi.nready
322 326
323/** lowlevel stuff **********************************************************/ 327/** lowlevel stuff **********************************************************/
611 { 615 {
612 while (expect_true (cxix >= 0)) 616 while (expect_true (cxix >= 0))
613 { 617 {
614 PERL_CONTEXT *cx = &ccstk[cxix--]; 618 PERL_CONTEXT *cx = &ccstk[cxix--];
615 619
616 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))
617 { 621 {
618 CV *cv = cx->blk_sub.cv; 622 CV *cv = cx->blk_sub.cv;
619 623
620 if (expect_true (CvDEPTH (cv))) 624 if (expect_true (CvDEPTH (cv)))
621 { 625 {
986} 990}
987 991
988static void 992static void
989coro_destruct_perl (pTHX_ struct coro *coro) 993coro_destruct_perl (pTHX_ struct coro *coro)
990{ 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
991 coro_unwind_stacks (aTHX); 1005 coro_unwind_stacks (aTHX);
1006 coro_destruct_stacks (aTHX);
992 1007
993 SvREFCNT_dec (GvSV (PL_defgv)); 1008 // now save some sv's to be free'd later
994 SvREFCNT_dec (GvAV (PL_defgv)); 1009 svf [0] = GvSV (PL_defgv);
995 SvREFCNT_dec (GvSV (PL_errgv)); 1010 svf [1] = (SV *)GvAV (PL_defgv);
996 SvREFCNT_dec (PL_defoutgv); 1011 svf [2] = GvSV (PL_errgv);
997 SvREFCNT_dec (PL_rs); 1012 svf [3] = (SV *)PL_defoutgv;
998 SvREFCNT_dec (GvSV (irsgv)); 1013 svf [4] = PL_rs;
999 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));
1000 1019
1001 SvREFCNT_dec (PL_diehook); 1020 load_perl (aTHX_ current);
1002 SvREFCNT_dec (PL_warnhook);
1003 1021 }
1022
1023 {
1024 int i;
1025
1026 for (i = 0; i < sizeof (svf) / sizeof (*svf); ++i)
1027 SvREFCNT_dec (svf [i]);
1028
1004 SvREFCNT_dec (coro->saved_deffh); 1029 SvREFCNT_dec (coro->saved_deffh);
1005 SvREFCNT_dec (coro->rouse_cb); 1030 SvREFCNT_dec (coro->rouse_cb);
1006 SvREFCNT_dec (coro->invoke_cb); 1031 SvREFCNT_dec (coro->invoke_cb);
1007 SvREFCNT_dec (coro->invoke_av); 1032 SvREFCNT_dec (coro->invoke_av);
1008 1033 }
1009 coro_destruct_stacks (aTHX);
1010} 1034}
1011 1035
1012INLINE void 1036INLINE void
1013free_coro_mortal (pTHX) 1037free_coro_mortal (pTHX)
1014{ 1038{
1382 /* TODO: throwing up here is considered harmful */ 1406 /* TODO: throwing up here is considered harmful */
1383 1407
1384 if (expect_true (prev != next)) 1408 if (expect_true (prev != next))
1385 { 1409 {
1386 if (expect_false (!(prev->flags & (CF_RUNNING | CF_NEW)))) 1410 if (expect_false (!(prev->flags & (CF_RUNNING | CF_NEW))))
1387 croak ("Coro::State::transfer called with a suspended prev Coro::State, but can only transfer from running or new states,"); 1411 croak ("Coro::State::transfer called with a blocked prev Coro::State, but can only transfer from running or new states,");
1388 1412
1389 if (expect_false (next->flags & CF_RUNNING))
1390 croak ("Coro::State::transfer called with running next Coro::State, but can only transfer to inactive states,");
1391
1392 if (expect_false (next->flags & CF_DESTROYED)) 1413 if (expect_false (next->flags & (CF_RUNNING | CF_DESTROYED | CF_SUSPENDED)))
1393 croak ("Coro::State::transfer called with destroyed next Coro::State, but can only transfer to inactive states,"); 1414 croak ("Coro::State::transfer called with running, destroyed or suspended next Coro::State, but can only transfer to inactive states,");
1394 1415
1395#if !PERL_VERSION_ATLEAST (5,10,0) 1416#if !PERL_VERSION_ATLEAST (5,10,0)
1396 if (expect_false (PL_lex_state != LEX_NOTPARSING)) 1417 if (expect_false (PL_lex_state != LEX_NOTPARSING))
1397 croak ("Coro::State::transfer called while parsing, but this is not supported in your perl version,"); 1418 croak ("Coro::State::transfer called while parsing, but this is not supported in your perl version,");
1398#endif 1419#endif
1486coro_state_destroy (pTHX_ struct coro *coro) 1507coro_state_destroy (pTHX_ struct coro *coro)
1487{ 1508{
1488 if (coro->flags & CF_DESTROYED) 1509 if (coro->flags & CF_DESTROYED)
1489 return 0; 1510 return 0;
1490 1511
1491 if (coro->on_destroy) 1512 if (coro->on_destroy && !PL_dirty)
1492 coro->on_destroy (aTHX_ coro); 1513 coro->on_destroy (aTHX_ coro);
1493 1514
1494 coro->flags |= CF_DESTROYED; 1515 coro->flags |= CF_DESTROYED;
1495 1516
1496 if (coro->flags & CF_READY) 1517 if (coro->flags & CF_READY)
1504 1525
1505 if (coro->mainstack 1526 if (coro->mainstack
1506 && coro->mainstack != main_mainstack 1527 && coro->mainstack != main_mainstack
1507 && coro->slot 1528 && coro->slot
1508 && !PL_dirty) 1529 && !PL_dirty)
1509 {
1510 struct coro *current = SvSTATE_current;
1511
1512 assert (("FATAL: tried to destroy currently running coroutine", coro->mainstack != PL_mainstack));
1513
1514 save_perl (aTHX_ current);
1515 load_perl (aTHX_ coro);
1516
1517 coro_destruct_perl (aTHX_ coro); 1530 coro_destruct_perl (aTHX_ coro);
1518
1519 load_perl (aTHX_ current);
1520
1521 coro->slot = 0;
1522 }
1523 1531
1524 cctx_destroy (coro->cctx); 1532 cctx_destroy (coro->cctx);
1525 SvREFCNT_dec (coro->startcv); 1533 SvREFCNT_dec (coro->startcv);
1526 SvREFCNT_dec (coro->args); 1534 SvREFCNT_dec (coro->args);
1527 SvREFCNT_dec (CORO_THROW); 1535 SvREFCNT_dec (CORO_THROW);
1614/** Coro ********************************************************************/ 1622/** Coro ********************************************************************/
1615 1623
1616INLINE void 1624INLINE void
1617coro_enq (pTHX_ struct coro *coro) 1625coro_enq (pTHX_ struct coro *coro)
1618{ 1626{
1619 av_push (coro_ready [coro->prio - PRIO_MIN], SvREFCNT_inc_NN (coro->hv)); 1627 struct coro **ready = coro_ready [coro->prio - PRIO_MIN];
1620}
1621 1628
1622INLINE SV * 1629 SvREFCNT_inc_NN (coro->hv);
1630
1631 coro->next_ready = 0;
1632 *(ready [0] ? &ready [1]->next_ready : &ready [0]) = coro;
1633 ready [1] = coro;
1634}
1635
1636INLINE struct coro *
1623coro_deq (pTHX) 1637coro_deq (pTHX)
1624{ 1638{
1625 int prio; 1639 int prio;
1626 1640
1627 for (prio = PRIO_MAX - PRIO_MIN + 1; --prio >= 0; ) 1641 for (prio = PRIO_MAX - PRIO_MIN + 1; --prio >= 0; )
1628 if (AvFILLp (coro_ready [prio]) >= 0) 1642 {
1629 return av_shift (coro_ready [prio]); 1643 struct coro **ready = coro_ready [prio];
1644
1645 if (ready [0])
1646 {
1647 struct coro *coro = ready [0];
1648 ready [0] = coro->next_ready;
1649 return coro;
1650 }
1651 }
1630 1652
1631 return 0; 1653 return 0;
1632} 1654}
1633 1655
1634static int 1656static int
1698static void 1720static void
1699prepare_schedule (pTHX_ struct coro_transfer_args *ta) 1721prepare_schedule (pTHX_ struct coro_transfer_args *ta)
1700{ 1722{
1701 for (;;) 1723 for (;;)
1702 { 1724 {
1703 SV *next_sv = coro_deq (aTHX); 1725 struct coro *next = coro_deq (aTHX);
1704 1726
1705 if (expect_true (next_sv)) 1727 if (expect_true (next))
1706 { 1728 {
1707 struct coro *next = SvSTATE_hv (next_sv);
1708
1709 /* cannot transfer to destroyed coros, skip and look for next */ 1729 /* cannot transfer to destroyed coros, skip and look for next */
1710 if (expect_false (next->flags & CF_DESTROYED)) 1730 if (expect_false (next->flags & (CF_DESTROYED | CF_SUSPENDED)))
1711 SvREFCNT_dec (next_sv); /* coro_nready has already been taken care of by destroy */ 1731 SvREFCNT_dec (next->hv); /* coro_nready has already been taken care of by destroy */
1712 else 1732 else
1713 { 1733 {
1714 next->flags &= ~CF_READY; 1734 next->flags &= ~CF_READY;
1715 --coro_nready; 1735 --coro_nready;
1716 1736
1990 SV *data = (SV *)GENSUB_ARG; 2010 SV *data = (SV *)GENSUB_ARG;
1991 2011
1992 if (SvTYPE (SvRV (data)) != SVt_PVAV) 2012 if (SvTYPE (SvRV (data)) != SVt_PVAV)
1993 { 2013 {
1994 /* first call, set args */ 2014 /* first call, set args */
2015 SV *coro = SvRV (data);
1995 AV *av = newAV (); 2016 AV *av = newAV ();
1996 SV *coro = SvRV (data);
1997 2017
1998 SvRV_set (data, (SV *)av); 2018 SvRV_set (data, (SV *)av);
1999 api_ready (aTHX_ coro);
2000 SvREFCNT_dec (coro);
2001 2019
2002 /* better take a full copy of the arguments */ 2020 /* better take a full copy of the arguments */
2003 while (items--) 2021 while (items--)
2004 av_store (av, items, newSVsv (ST (items))); 2022 av_store (av, items, newSVsv (ST (items)));
2023
2024 api_ready (aTHX_ coro);
2025 SvREFCNT_dec (coro);
2005 } 2026 }
2006 2027
2007 XSRETURN_EMPTY; 2028 XSRETURN_EMPTY;
2008} 2029}
2009 2030
2026 2047
2027 EXTEND (SP, AvFILLp (av) + 1); 2048 EXTEND (SP, AvFILLp (av) + 1);
2028 for (i = 0; i <= AvFILLp (av); ++i) 2049 for (i = 0; i <= AvFILLp (av); ++i)
2029 PUSHs (sv_2mortal (AvARRAY (av)[i])); 2050 PUSHs (sv_2mortal (AvARRAY (av)[i]));
2030 2051
2031 /* we have stolen the elements, so ste length to zero and free */ 2052 /* we have stolen the elements, so set length to zero and free */
2032 AvFILLp (av) = -1; 2053 AvFILLp (av) = -1;
2033 av_undef (av); 2054 av_undef (av);
2034 2055
2035 PUTBACK; 2056 PUTBACK;
2036 } 2057 }
2456/* Coro::Semaphore & Coro::Signal */ 2477/* Coro::Semaphore & Coro::Signal */
2457 2478
2458static SV * 2479static SV *
2459coro_waitarray_new (pTHX_ int count) 2480coro_waitarray_new (pTHX_ int count)
2460{ 2481{
2461 /* 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 */
2462 AV *av = newAV (); 2483 AV *av = newAV ();
2463 SV **ary; 2484 SV **ary;
2464 2485
2465 /* unfortunately, building manually saves memory */ 2486 /* unfortunately, building manually saves memory */
2466 Newx (ary, 2, SV *); 2487 Newx (ary, 2, SV *);
3100 if (ix) 3121 if (ix)
3101 eval_sv (coderef, 0); 3122 eval_sv (coderef, 0);
3102 else 3123 else
3103 call_sv (coderef, G_KEEPERR | G_EVAL | G_VOID | G_DISCARD); 3124 call_sv (coderef, G_KEEPERR | G_EVAL | G_VOID | G_DISCARD);
3104 3125
3126 POPSTACK;
3105 SPAGAIN; 3127 SPAGAIN;
3106 POPSTACK;
3107 3128
3108 if (current != coro) 3129 if (current != coro)
3109 { 3130 {
3110 PUTBACK; 3131 PUTBACK;
3111 save_perl (aTHX_ coro); 3132 save_perl (aTHX_ coro);
3121 ALIAS: 3142 ALIAS:
3122 is_ready = CF_READY 3143 is_ready = CF_READY
3123 is_running = CF_RUNNING 3144 is_running = CF_RUNNING
3124 is_new = CF_NEW 3145 is_new = CF_NEW
3125 is_destroyed = CF_DESTROYED 3146 is_destroyed = CF_DESTROYED
3147 is_suspended = CF_SUSPENDED
3126 CODE: 3148 CODE:
3127 RETVAL = boolSV (coro->flags & ix); 3149 RETVAL = boolSV (coro->flags & ix);
3128 OUTPUT: 3150 OUTPUT:
3129 RETVAL 3151 RETVAL
3130 3152
3195 SV **dst = ix ? (SV **)&self->slot->defav : (SV **)&self->slot->defsv; 3217 SV **dst = ix ? (SV **)&self->slot->defav : (SV **)&self->slot->defsv;
3196 3218
3197 SV *tmp = *src; *src = *dst; *dst = tmp; 3219 SV *tmp = *src; *src = *dst; *dst = tmp;
3198 } 3220 }
3199 3221
3222void
3223cancel (Coro::State self)
3224 CODE:
3225 coro_state_destroy (aTHX_ self);
3226 coro_call_on_destroy (aTHX_ self); /* actually only for Coro objects */
3227
3200 3228
3201MODULE = Coro::State PACKAGE = Coro 3229MODULE = Coro::State PACKAGE = Coro
3202 3230
3203BOOT: 3231BOOT:
3204{ 3232{
3205 int i;
3206
3207 sv_pool_rss = coro_get_sv (aTHX_ "Coro::POOL_RSS" , TRUE); 3233 sv_pool_rss = coro_get_sv (aTHX_ "Coro::POOL_RSS" , TRUE);
3208 sv_pool_size = coro_get_sv (aTHX_ "Coro::POOL_SIZE" , TRUE); 3234 sv_pool_size = coro_get_sv (aTHX_ "Coro::POOL_SIZE" , TRUE);
3209 cv_coro_run = get_cv ( "Coro::_coro_run" , GV_ADD); 3235 cv_coro_run = get_cv ( "Coro::_coro_run" , GV_ADD);
3210 cv_coro_terminate = get_cv ( "Coro::terminate" , GV_ADD); 3236 cv_coro_terminate = get_cv ( "Coro::terminate" , GV_ADD);
3211 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);
3226 newCONSTSUB (coro_stash, "PRIO_NORMAL", newSViv (PRIO_NORMAL)); 3252 newCONSTSUB (coro_stash, "PRIO_NORMAL", newSViv (PRIO_NORMAL));
3227 newCONSTSUB (coro_stash, "PRIO_LOW", newSViv (PRIO_LOW)); 3253 newCONSTSUB (coro_stash, "PRIO_LOW", newSViv (PRIO_LOW));
3228 newCONSTSUB (coro_stash, "PRIO_IDLE", newSViv (PRIO_IDLE)); 3254 newCONSTSUB (coro_stash, "PRIO_IDLE", newSViv (PRIO_IDLE));
3229 newCONSTSUB (coro_stash, "PRIO_MIN", newSViv (PRIO_MIN)); 3255 newCONSTSUB (coro_stash, "PRIO_MIN", newSViv (PRIO_MIN));
3230 3256
3231 for (i = PRIO_MAX - PRIO_MIN + 1; i--; )
3232 coro_ready[i] = newAV ();
3233
3234 { 3257 {
3235 SV *sv = coro_get_sv (aTHX_ "Coro::API", TRUE); 3258 SV *sv = coro_get_sv (aTHX_ "Coro::API", TRUE);
3236 3259
3237 coroapi.schedule = api_schedule; 3260 coroapi.schedule = api_schedule;
3238 coroapi.schedule_to = api_schedule_to; 3261 coroapi.schedule_to = api_schedule_to;
3278cede_notself (...) 3301cede_notself (...)
3279 CODE: 3302 CODE:
3280 CORO_EXECUTE_SLF_XS (slf_init_cede_notself); 3303 CORO_EXECUTE_SLF_XS (slf_init_cede_notself);
3281 3304
3282void 3305void
3283_cancel (Coro::State self)
3284 CODE:
3285 coro_state_destroy (aTHX_ self);
3286 coro_call_on_destroy (aTHX_ self);
3287
3288void
3289_set_current (SV *current) 3306_set_current (SV *current)
3290 PROTOTYPE: $ 3307 PROTOTYPE: $
3291 CODE: 3308 CODE:
3292 SvREFCNT_dec (SvRV (coro_current)); 3309 SvREFCNT_dec (SvRV (coro_current));
3293 SvRV_set (coro_current, SvREFCNT_inc_NN (SvRV (current))); 3310 SvRV_set (coro_current, SvREFCNT_inc_NN (SvRV (current)));
3335 PROTOTYPE: 3352 PROTOTYPE:
3336 CODE: 3353 CODE:
3337 RETVAL = coro_nready; 3354 RETVAL = coro_nready;
3338 OUTPUT: 3355 OUTPUT:
3339 RETVAL 3356 RETVAL
3357
3358void
3359suspend (Coro::State self)
3360 PROTOTYPE: $
3361 CODE:
3362 self->flags |= CF_SUSPENDED;
3363
3364void
3365resume (Coro::State self)
3366 PROTOTYPE: $
3367 CODE:
3368 self->flags &= ~CF_SUSPENDED;
3340 3369
3341void 3370void
3342_pool_handler (...) 3371_pool_handler (...)
3343 CODE: 3372 CODE:
3344 CORO_EXECUTE_SLF_XS (slf_init_pool_handler); 3373 CORO_EXECUTE_SLF_XS (slf_init_pool_handler);
3419 av_push (*avp, SvREFCNT_inc (block)); 3448 av_push (*avp, SvREFCNT_inc (block));
3420 3449
3421 if (!ix) 3450 if (!ix)
3422 on_enterleave_call (aTHX_ block); 3451 on_enterleave_call (aTHX_ block);
3423 3452
3424 LEAVE; /* pp_entersub unfortunately forces an ENTER/LEAVE around xs calls */ 3453 LEAVE; /* pp_entersub unfortunately forces an ENTER/LEAVE around XS calls */
3425 SAVEDESTRUCTOR_X (ix ? coro_pop_on_leave : coro_pop_on_enter, (void *)coro); 3454 SAVEDESTRUCTOR_X (ix ? coro_pop_on_leave : coro_pop_on_enter, (void *)coro);
3426 ENTER; /* pp_entersub unfortunately forces an ENTER/LEAVE around xs calls */ 3455 ENTER; /* pp_entersub unfortunately forces an ENTER/LEAVE around XS calls */
3427} 3456}
3428 3457
3429 3458
3430MODULE = Coro::State PACKAGE = PerlIO::cede 3459MODULE = Coro::State PACKAGE = PerlIO::cede
3431 3460
3443 GvSTASH (CvGV (cv)) 3472 GvSTASH (CvGV (cv))
3444 ); 3473 );
3445 OUTPUT: 3474 OUTPUT:
3446 RETVAL 3475 RETVAL
3447 3476
3448# helper for Coro::Channel 3477# helper for Coro::Channel and others
3449SV * 3478SV *
3450_alloc (int count) 3479_alloc (int count)
3451 CODE: 3480 CODE:
3452 RETVAL = coro_waitarray_new (aTHX_ count); 3481 RETVAL = coro_waitarray_new (aTHX_ count);
3453 OUTPUT: 3482 OUTPUT:
3511 for (i = 1; i <= wcount; ++i) 3540 for (i = 1; i <= wcount; ++i)
3512 PUSHs (sv_2mortal (newRV_inc (AvARRAY (av)[i]))); 3541 PUSHs (sv_2mortal (newRV_inc (AvARRAY (av)[i])));
3513 } 3542 }
3514} 3543}
3515 3544
3545MODULE = Coro::State PACKAGE = Coro::SemaphoreSet
3546
3547void
3548_may_delete (SV *sem, int count, int extra_refs)
3549 PPCODE:
3550{
3551 AV *av = (AV *)SvRV (sem);
3552
3553 if (SvREFCNT ((SV *)av) == 1 + extra_refs
3554 && AvFILLp (av) == 0 /* no waiters, just count */
3555 && SvIV (AvARRAY (av)[0]) == count)
3556 XSRETURN_YES;
3557
3558 XSRETURN_NO;
3559}
3560
3516MODULE = Coro::State PACKAGE = Coro::Signal 3561MODULE = Coro::State PACKAGE = Coro::Signal
3517 3562
3518SV * 3563SV *
3519new (SV *klass) 3564new (SV *klass)
3520 CODE: 3565 CODE:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines