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.276 by root, Sat Nov 15 07:49:48 2008 UTC vs.
Revision 1.278 by root, Sun Nov 16 07:09:28 2008 UTC

811 811
812 return orig_sigelem_set ? orig_sigelem_set (aTHX_ sv, mg) : 0; 812 return orig_sigelem_set ? orig_sigelem_set (aTHX_ sv, mg) : 0;
813} 813}
814 814
815static void 815static void
816prepare_nop (aTHX_ struct coro_transfer_args *ta) 816prepare_nop (pTHX_ struct coro_transfer_args *ta)
817{ 817{
818 /* kind of mega-hacky, but works */ 818 /* kind of mega-hacky, but works */
819 ta->next = ta->prev = (struct coro *)ta; 819 ta->next = ta->prev = (struct coro *)ta;
820} 820}
821 821
822static int 822static int
823slf_check_nop (aTHX) 823slf_check_nop (pTHX_ struct CoroSLF *frame)
824{ 824{
825 return 0; 825 return 0;
826} 826}
827 827
828static void 828static void
1320 dSTACKLEVEL; 1320 dSTACKLEVEL;
1321 1321
1322 /* sometimes transfer is only called to set idle_sp */ 1322 /* sometimes transfer is only called to set idle_sp */
1323 if (expect_false (!next)) 1323 if (expect_false (!next))
1324 { 1324 {
1325 ((coro_cctx *)prev)->idle_sp = stacklevel; 1325 ((coro_cctx *)prev)->idle_sp = (void *)stacklevel;
1326 assert (((coro_cctx *)prev)->idle_te = PL_top_env); /* just for the side-effect when asserts are enabled */ 1326 assert (((coro_cctx *)prev)->idle_te = PL_top_env); /* just for the side-effect when asserts are enabled */
1327 } 1327 }
1328 else if (expect_true (prev != next)) 1328 else if (expect_true (prev != next))
1329 { 1329 {
1330 coro_cctx *prev__cctx; 1330 coro_cctx *prev__cctx;
1357 1357
1358 prev__cctx = prev->cctx; 1358 prev__cctx = prev->cctx;
1359 1359
1360 /* possibly untie and reuse the cctx */ 1360 /* possibly untie and reuse the cctx */
1361 if (expect_true ( 1361 if (expect_true (
1362 prev__cctx->idle_sp == stacklevel 1362 prev__cctx->idle_sp == (void *)stacklevel
1363 && !(prev__cctx->flags & CC_TRACE) 1363 && !(prev__cctx->flags & CC_TRACE)
1364 && !force_cctx 1364 && !force_cctx
1365 )) 1365 ))
1366 { 1366 {
1367 /* I assume that stacklevel is a stronger indicator than PL_top_env changes */ 1367 /* I assume that stacklevel is a stronger indicator than PL_top_env changes */
1719 PL_runops = RUNOPS_DEFAULT; 1719 PL_runops = RUNOPS_DEFAULT;
1720 else 1720 else
1721 coro->slot->runops = RUNOPS_DEFAULT; 1721 coro->slot->runops = RUNOPS_DEFAULT;
1722 } 1722 }
1723} 1723}
1724
1725#if 0
1726static int
1727coro_gensub_free (pTHX_ SV *sv, MAGIC *mg)
1728{
1729 AV *padlist;
1730 AV *av = (AV *)mg->mg_obj;
1731
1732 abort ();
1733
1734 return 0;
1735}
1736
1737static MGVTBL coro_gensub_vtbl = {
1738 0, 0, 0, 0,
1739 coro_gensub_free
1740};
1741#endif
1742 1724
1743/*****************************************************************************/ 1725/*****************************************************************************/
1744/* PerlIO::cede */ 1726/* PerlIO::cede */
1745 1727
1746typedef struct 1728typedef struct
1862static void 1844static void
1863slf_prepare_transfer (pTHX_ struct coro_transfer_args *ta) 1845slf_prepare_transfer (pTHX_ struct coro_transfer_args *ta)
1864{ 1846{
1865 SV **arg = (SV **)slf_frame.data; 1847 SV **arg = (SV **)slf_frame.data;
1866 1848
1867 prepare_transfer (ta, arg [0], arg [1]); 1849 prepare_transfer (aTHX_ ta, arg [0], arg [1]);
1868} 1850}
1869 1851
1870static void 1852static void
1871slf_init_transfer (pTHX_ struct CoroSLF *frame, SV **arg, int items) 1853slf_init_transfer (pTHX_ struct CoroSLF *frame, SV **arg, int items)
1872{ 1854{
2063 } 2045 }
2064 2046
2065 frame->check = slf_check_semaphore_down; 2047 frame->check = slf_check_semaphore_down;
2066 2048
2067} 2049}
2050
2051/*****************************************************************************/
2052
2053#define GENSUB_ARG CvXSUBANY (cv).any_ptr
2054
2055/* create a closure from XS, returns a code reference */
2056/* the arg can be accessed via GENSUB_ARG from the callback */
2057/* the callback must use dXSARGS/XSRETURN */
2058static SV *
2059gensub (pTHX_ void (*xsub)(pTHX_ CV *), void *arg)
2060{
2061 CV *cv = (CV *)NEWSV (0, 0);
2062
2063 sv_upgrade ((SV *)cv, SVt_PVCV);
2064
2065 CvANON_on (cv);
2066 CvISXSUB_on (cv);
2067 CvXSUB (cv) = xsub;
2068 GENSUB_ARG = arg;
2069
2070 return newRV_noinc ((SV *)cv);
2071}
2072
2073/*****************************************************************************/
2068 2074
2069MODULE = Coro::State PACKAGE = Coro::State PREFIX = api_ 2075MODULE = Coro::State PACKAGE = Coro::State PREFIX = api_
2070 2076
2071PROTOTYPES: DISABLE 2077PROTOTYPES: DISABLE
2072 2078
2536 api_trace (aTHX_ coro_current, 0); 2542 api_trace (aTHX_ coro_current, 0);
2537 2543
2538 av_push (av_async_pool, newSVsv (coro_current)); 2544 av_push (av_async_pool, newSVsv (coro_current));
2539} 2545}
2540 2546
2541#if 0
2542
2543void
2544_generator_call (...)
2545 PROTOTYPE: @
2546 PPCODE:
2547 fprintf (stderr, "call %p\n", CvXSUBANY(cv).any_ptr);
2548 xxxx
2549 abort ();
2550
2551SV *
2552gensub (SV *sub, ...)
2553 PROTOTYPE: &;@
2554 CODE:
2555{
2556 struct coro *coro;
2557 MAGIC *mg;
2558 CV *xcv;
2559 CV *ncv = (CV *)newSV_type (SVt_PVCV);
2560 int i;
2561
2562 CvGV (ncv) = CvGV (cv);
2563 CvFILE (ncv) = CvFILE (cv);
2564
2565 Newz (0, coro, 1, struct coro);
2566 coro->args = newAV ();
2567 coro->flags = CF_NEW;
2568
2569 av_extend (coro->args, items - 1);
2570 for (i = 1; i < items; i++)
2571 av_push (coro->args, newSVsv (ST (i)));
2572
2573 CvISXSUB_on (ncv);
2574 CvXSUBANY (ncv).any_ptr = (void *)coro;
2575
2576 xcv = GvCV (gv_fetchpv ("Coro::_generator_call", 0, SVt_PVCV));
2577
2578 CvXSUB (ncv) = CvXSUB (xcv);
2579 CvANON_on (ncv);
2580
2581 mg = sv_magicext ((SV *)ncv, 0, CORO_MAGIC_type_state, &coro_gensub_vtbl, (char *)coro, 0);
2582 RETVAL = newRV_noinc ((SV *)ncv);
2583}
2584 OUTPUT:
2585 RETVAL
2586
2587#endif
2588
2589 2547
2590MODULE = Coro::State PACKAGE = Coro::AIO 2548MODULE = Coro::State PACKAGE = Coro::AIO
2591 2549
2592void 2550void
2593_get_state (SV *self) 2551_get_state (SV *self)
2642MODULE = Coro::State PACKAGE = Coro::AnyEvent 2600MODULE = Coro::State PACKAGE = Coro::AnyEvent
2643 2601
2644BOOT: 2602BOOT:
2645 sv_activity = coro_get_sv (aTHX_ "Coro::AnyEvent::ACTIVITY", TRUE); 2603 sv_activity = coro_get_sv (aTHX_ "Coro::AnyEvent::ACTIVITY", TRUE);
2646 2604
2647SV * 2605void
2648_schedule (...) 2606_schedule (...)
2649 CODE: 2607 CODE:
2650{ 2608{
2651 static int incede; 2609 static int incede;
2652 2610
2717 AvARRAY (av)[0] = AvARRAY (av)[1]; 2675 AvARRAY (av)[0] = AvARRAY (av)[1];
2718 AvARRAY (av)[1] = count_sv; 2676 AvARRAY (av)[1] = count_sv;
2719 cb = av_shift (av); 2677 cb = av_shift (av);
2720 2678
2721 if (SvOBJECT (cb)) 2679 if (SvOBJECT (cb))
2722 api_ready (cb); 2680 api_ready (aTHX_ cb);
2723 else 2681 else
2724 croak ("callbacks not yet supported"); 2682 croak ("callbacks not yet supported");
2725 2683
2726 SvREFCNT_dec (cb); 2684 SvREFCNT_dec (cb);
2727 } 2685 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines