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.240 by root, Sun Jun 29 00:28:17 2008 UTC vs.
Revision 1.245 by root, Mon Sep 22 05:40:21 2008 UTC

361 361
362 /* casting is fun. */ 362 /* casting is fun. */
363 while (&PL_sv_undef != (SV *)(padlist = (AV *)av_pop (av))) 363 while (&PL_sv_undef != (SV *)(padlist = (AV *)av_pop (av)))
364 free_padlist (aTHX_ padlist); 364 free_padlist (aTHX_ padlist);
365 365
366 SvREFCNT_dec (av); /* sv_magicext increased the refcount */
367
366 return 0; 368 return 0;
367} 369}
368 370
369#define CORO_MAGIC_type_cv PERL_MAGIC_ext 371#define CORO_MAGIC_type_cv PERL_MAGIC_ext
370#define CORO_MAGIC_type_state PERL_MAGIC_ext 372#define CORO_MAGIC_type_state PERL_MAGIC_ext
420 if (expect_true (mg && AvFILLp ((av = (AV *)mg->mg_obj)) >= 0)) 422 if (expect_true (mg && AvFILLp ((av = (AV *)mg->mg_obj)) >= 0))
421 CvPADLIST (cv) = (AV *)AvARRAY (av)[AvFILLp (av)--]; 423 CvPADLIST (cv) = (AV *)AvARRAY (av)[AvFILLp (av)--];
422 else 424 else
423 { 425 {
424#if CORO_PREFER_PERL_FUNCTIONS 426#if CORO_PREFER_PERL_FUNCTIONS
425 /* this is probably cleaner, but also slower? */ 427 /* this is probably cleaner? but also slower! */
428 /* in practise, it seems to be less stable */
426 CV *cp = Perl_cv_clone (cv); 429 CV *cp = Perl_cv_clone (cv);
427 CvPADLIST (cv) = CvPADLIST (cp); 430 CvPADLIST (cv) = CvPADLIST (cp);
428 CvPADLIST (cp) = 0; 431 CvPADLIST (cp) = 0;
429 SvREFCNT_dec (cp); 432 SvREFCNT_dec (cp);
430#else 433#else
663 #undef VAR 666 #undef VAR
664 } 667 }
665 else 668 else
666 slot = coro->slot; 669 slot = coro->slot;
667 670
671 if (slot)
672 {
668 rss += sizeof (slot->curstackinfo); 673 rss += sizeof (slot->curstackinfo);
669 rss += (slot->curstackinfo->si_cxmax + 1) * sizeof (PERL_CONTEXT); 674 rss += (slot->curstackinfo->si_cxmax + 1) * sizeof (PERL_CONTEXT);
670 rss += sizeof (SV) + sizeof (struct xpvav) + (1 + AvMAX (slot->curstack)) * sizeof (SV *); 675 rss += sizeof (SV) + sizeof (struct xpvav) + (1 + AvMAX (slot->curstack)) * sizeof (SV *);
671 rss += slot->tmps_max * sizeof (SV *); 676 rss += slot->tmps_max * sizeof (SV *);
672 rss += (slot->markstack_max - slot->markstack_ptr) * sizeof (I32); 677 rss += (slot->markstack_max - slot->markstack_ptr) * sizeof (I32);
673 rss += slot->scopestack_max * sizeof (I32); 678 rss += slot->scopestack_max * sizeof (I32);
674 rss += slot->savestack_max * sizeof (ANY); 679 rss += slot->savestack_max * sizeof (ANY);
675 680
676#if !PERL_VERSION_ATLEAST (5,10,0) 681#if !PERL_VERSION_ATLEAST (5,10,0)
677 rss += slot->retstack_max * sizeof (OP *); 682 rss += slot->retstack_max * sizeof (OP *);
678#endif 683#endif
684 }
679 } 685 }
680 686
681 return rss; 687 return rss;
682} 688}
683 689
686static int (*orig_sigelem_get) (pTHX_ SV *sv, MAGIC *mg); 692static int (*orig_sigelem_get) (pTHX_ SV *sv, MAGIC *mg);
687static int (*orig_sigelem_set) (pTHX_ SV *sv, MAGIC *mg); 693static int (*orig_sigelem_set) (pTHX_ SV *sv, MAGIC *mg);
688static int (*orig_sigelem_clr) (pTHX_ SV *sv, MAGIC *mg); 694static int (*orig_sigelem_clr) (pTHX_ SV *sv, MAGIC *mg);
689 695
690/* apparently < 5.8.8 */ 696/* apparently < 5.8.8 */
691#undef MgPV_nolen_const
692#ifndef MgPV_nolen_const 697#ifndef MgPV_nolen_const
693#define MgPV_nolen_const(mg) (((((int)(mg)->mg_len)) == HEf_SVKEY) ? \ 698#define MgPV_nolen_const(mg) (((((int)(mg)->mg_len)) == HEf_SVKEY) ? \
694 SvPV_nolen_const((SV*)((mg)->mg_ptr)) : \ 699 SvPV_nolen((SV*)((mg)->mg_ptr)) : \
695 (const char*)(mg)->mg_ptr) 700 (const char*)(mg)->mg_ptr)
696#endif 701#endif
697 702
698/* 703/*
699 * This overrides the default magic get method of %SIG elements. 704 * This overrides the default magic get method of %SIG elements.
1624 else 1629 else
1625 coro->slot->runops = RUNOPS_DEFAULT; 1630 coro->slot->runops = RUNOPS_DEFAULT;
1626 } 1631 }
1627} 1632}
1628 1633
1634static int
1635coro_gensub_free (pTHX_ SV *sv, MAGIC *mg)
1636{
1637 AV *padlist;
1638 AV *av = (AV *)mg->mg_obj;
1639
1640 abort ();
1641
1642 return 0;
1643}
1644
1645static MGVTBL coro_gensub_vtbl = {
1646 0, 0, 0, 0,
1647 coro_gensub_free
1648};
1649
1629MODULE = Coro::State PACKAGE = Coro::State PREFIX = api_ 1650MODULE = Coro::State PACKAGE = Coro::State PREFIX = api_
1630 1651
1631PROTOTYPES: DISABLE 1652PROTOTYPES: DISABLE
1632 1653
1633BOOT: 1654BOOT:
1799call (Coro::State coro, SV *coderef) 1820call (Coro::State coro, SV *coderef)
1800 ALIAS: 1821 ALIAS:
1801 eval = 1 1822 eval = 1
1802 CODE: 1823 CODE:
1803{ 1824{
1804 if (coro->mainstack) 1825 if (coro->mainstack && ((coro->flags & CF_RUNNING) || coro->slot))
1805 { 1826 {
1806 struct coro temp; 1827 struct coro temp;
1807 1828
1808 if (!(coro->flags & CF_RUNNING)) 1829 if (!(coro->flags & CF_RUNNING))
1809 { 1830 {
1891force_cctx () 1912force_cctx ()
1892 CODE: 1913 CODE:
1893 struct coro *coro = SvSTATE (coro_current); 1914 struct coro *coro = SvSTATE (coro_current);
1894 coro->cctx->idle_sp = 0; 1915 coro->cctx->idle_sp = 0;
1895 1916
1896MODULE = Coro::State PACKAGE = Coro
1897
1898BOOT:
1899{
1900 int i;
1901
1902 av_async_pool = coro_get_av (aTHX_ "Coro::async_pool", TRUE);
1903 sv_pool_rss = coro_get_sv (aTHX_ "Coro::POOL_RSS" , TRUE);
1904 sv_pool_size = coro_get_sv (aTHX_ "Coro::POOL_SIZE" , TRUE);
1905
1906 coro_current = coro_get_sv (aTHX_ "Coro::current", FALSE);
1907 SvREADONLY_on (coro_current);
1908
1909 coro_stash = gv_stashpv ("Coro", TRUE);
1910
1911 newCONSTSUB (coro_stash, "PRIO_MAX", newSViv (PRIO_MAX));
1912 newCONSTSUB (coro_stash, "PRIO_HIGH", newSViv (PRIO_HIGH));
1913 newCONSTSUB (coro_stash, "PRIO_NORMAL", newSViv (PRIO_NORMAL));
1914 newCONSTSUB (coro_stash, "PRIO_LOW", newSViv (PRIO_LOW));
1915 newCONSTSUB (coro_stash, "PRIO_IDLE", newSViv (PRIO_IDLE));
1916 newCONSTSUB (coro_stash, "PRIO_MIN", newSViv (PRIO_MIN));
1917
1918 for (i = PRIO_MAX - PRIO_MIN + 1; i--; )
1919 coro_ready[i] = newAV ();
1920
1921 {
1922 SV *sv = perl_get_sv ("Coro::API", TRUE);
1923 perl_get_sv ("Coro::API", TRUE); /* silence 5.10 warning */
1924
1925 coroapi.schedule = api_schedule;
1926 coroapi.cede = api_cede;
1927 coroapi.cede_notself = api_cede_notself;
1928 coroapi.ready = api_ready;
1929 coroapi.is_ready = api_is_ready;
1930 coroapi.nready = &coro_nready;
1931 coroapi.current = coro_current;
1932
1933 GCoroAPI = &coroapi;
1934 sv_setiv (sv, (IV)&coroapi);
1935 SvREADONLY_on (sv);
1936 }
1937}
1938
1939void
1940_set_current (SV *current)
1941 PROTOTYPE: $
1942 CODE:
1943 SvREFCNT_dec (SvRV (coro_current));
1944 SvRV_set (coro_current, SvREFCNT_inc (SvRV (current)));
1945
1946void
1947_set_readyhook (SV *hook)
1948 PROTOTYPE: $
1949 CODE:
1950 LOCK;
1951 SvREFCNT_dec (coro_readyhook);
1952 coro_readyhook = SvOK (hook) ? newSVsv (hook) : 0;
1953 UNLOCK;
1954
1955int
1956prio (Coro::State coro, int newprio = 0)
1957 ALIAS:
1958 nice = 1
1959 CODE:
1960{
1961 RETVAL = coro->prio;
1962
1963 if (items > 1)
1964 {
1965 if (ix)
1966 newprio = coro->prio - newprio;
1967
1968 if (newprio < PRIO_MIN) newprio = PRIO_MIN;
1969 if (newprio > PRIO_MAX) newprio = PRIO_MAX;
1970
1971 coro->prio = newprio;
1972 }
1973}
1974 OUTPUT:
1975 RETVAL
1976
1977SV *
1978ready (SV *self)
1979 PROTOTYPE: $
1980 CODE:
1981 RETVAL = boolSV (api_ready (self));
1982 OUTPUT:
1983 RETVAL
1984
1985int
1986nready (...)
1987 PROTOTYPE:
1988 CODE:
1989 RETVAL = coro_nready;
1990 OUTPUT:
1991 RETVAL
1992
1993void 1917void
1994throw (Coro::State self, SV *throw = &PL_sv_undef) 1918throw (Coro::State self, SV *throw = &PL_sv_undef)
1995 PROTOTYPE: $;$ 1919 PROTOTYPE: $;$
1996 CODE: 1920 CODE:
1997 SvREFCNT_dec (self->throw); 1921 SvREFCNT_dec (self->throw);
2011 SV **dst = ix ? (SV **)&self->slot->defav : (SV **)&self->slot->defsv; 1935 SV **dst = ix ? (SV **)&self->slot->defav : (SV **)&self->slot->defsv;
2012 1936
2013 SV *tmp = *src; *src = *dst; *dst = tmp; 1937 SV *tmp = *src; *src = *dst; *dst = tmp;
2014 } 1938 }
2015 1939
1940MODULE = Coro::State PACKAGE = Coro
1941
1942BOOT:
1943{
1944 int i;
1945
1946 av_async_pool = coro_get_av (aTHX_ "Coro::async_pool", TRUE);
1947 sv_pool_rss = coro_get_sv (aTHX_ "Coro::POOL_RSS" , TRUE);
1948 sv_pool_size = coro_get_sv (aTHX_ "Coro::POOL_SIZE" , TRUE);
1949
1950 coro_current = coro_get_sv (aTHX_ "Coro::current", FALSE);
1951 SvREADONLY_on (coro_current);
1952
1953 coro_stash = gv_stashpv ("Coro", TRUE);
1954
1955 newCONSTSUB (coro_stash, "PRIO_MAX", newSViv (PRIO_MAX));
1956 newCONSTSUB (coro_stash, "PRIO_HIGH", newSViv (PRIO_HIGH));
1957 newCONSTSUB (coro_stash, "PRIO_NORMAL", newSViv (PRIO_NORMAL));
1958 newCONSTSUB (coro_stash, "PRIO_LOW", newSViv (PRIO_LOW));
1959 newCONSTSUB (coro_stash, "PRIO_IDLE", newSViv (PRIO_IDLE));
1960 newCONSTSUB (coro_stash, "PRIO_MIN", newSViv (PRIO_MIN));
1961
1962 for (i = PRIO_MAX - PRIO_MIN + 1; i--; )
1963 coro_ready[i] = newAV ();
1964
1965 {
1966 SV *sv = perl_get_sv ("Coro::API", TRUE);
1967 perl_get_sv ("Coro::API", TRUE); /* silence 5.10 warning */
1968
1969 coroapi.schedule = api_schedule;
1970 coroapi.cede = api_cede;
1971 coroapi.cede_notself = api_cede_notself;
1972 coroapi.ready = api_ready;
1973 coroapi.is_ready = api_is_ready;
1974 coroapi.nready = &coro_nready;
1975 coroapi.current = coro_current;
1976
1977 GCoroAPI = &coroapi;
1978 sv_setiv (sv, (IV)&coroapi);
1979 SvREADONLY_on (sv);
1980 }
1981}
1982
1983void
1984_set_current (SV *current)
1985 PROTOTYPE: $
1986 CODE:
1987 SvREFCNT_dec (SvRV (coro_current));
1988 SvRV_set (coro_current, SvREFCNT_inc (SvRV (current)));
1989
1990void
1991_set_readyhook (SV *hook)
1992 PROTOTYPE: $
1993 CODE:
1994 LOCK;
1995 SvREFCNT_dec (coro_readyhook);
1996 coro_readyhook = SvOK (hook) ? newSVsv (hook) : 0;
1997 UNLOCK;
1998
1999int
2000prio (Coro::State coro, int newprio = 0)
2001 ALIAS:
2002 nice = 1
2003 CODE:
2004{
2005 RETVAL = coro->prio;
2006
2007 if (items > 1)
2008 {
2009 if (ix)
2010 newprio = coro->prio - newprio;
2011
2012 if (newprio < PRIO_MIN) newprio = PRIO_MIN;
2013 if (newprio > PRIO_MAX) newprio = PRIO_MAX;
2014
2015 coro->prio = newprio;
2016 }
2017}
2018 OUTPUT:
2019 RETVAL
2020
2021SV *
2022ready (SV *self)
2023 PROTOTYPE: $
2024 CODE:
2025 RETVAL = boolSV (api_ready (self));
2026 OUTPUT:
2027 RETVAL
2028
2029int
2030nready (...)
2031 PROTOTYPE:
2032 CODE:
2033 RETVAL = coro_nready;
2034 OUTPUT:
2035 RETVAL
2036
2016# for async_pool speedup 2037# for async_pool speedup
2017void 2038void
2018_pool_1 (SV *cb) 2039_pool_1 (SV *cb)
2019 CODE: 2040 CODE:
2020{ 2041{
2084 api_trace (coro_current, 0); 2105 api_trace (coro_current, 0);
2085 2106
2086 av_push (av_async_pool, newSVsv (coro_current)); 2107 av_push (av_async_pool, newSVsv (coro_current));
2087} 2108}
2088 2109
2110#if 0
2111
2112void
2113_generator_call (...)
2114 PROTOTYPE: @
2115 PPCODE:
2116 fprintf (stderr, "call %p\n", CvXSUBANY(cv).any_ptr);
2117 xxxx
2118 abort ();
2119
2120SV *
2121gensub (SV *sub, ...)
2122 PROTOTYPE: &;@
2123 CODE:
2124{
2125 struct coro *coro;
2126 MAGIC *mg;
2127 CV *xcv;
2128 CV *ncv = (CV *)newSV_type (SVt_PVCV);
2129 int i;
2130
2131 CvGV (ncv) = CvGV (cv);
2132 CvFILE (ncv) = CvFILE (cv);
2133
2134 Newz (0, coro, 1, struct coro);
2135 coro->args = newAV ();
2136 coro->flags = CF_NEW;
2137
2138 av_extend (coro->args, items - 1);
2139 for (i = 1; i < items; i++)
2140 av_push (coro->args, newSVsv (ST (i)));
2141
2142 CvISXSUB_on (ncv);
2143 CvXSUBANY (ncv).any_ptr = (void *)coro;
2144
2145 xcv = GvCV (gv_fetchpv ("Coro::_generator_call", 0, SVt_PVCV));
2146
2147 CvXSUB (ncv) = CvXSUB (xcv);
2148 CvANON_on (ncv);
2149
2150 mg = sv_magicext ((SV *)ncv, 0, CORO_MAGIC_type_state, &coro_gensub_vtbl, (char *)coro, 0);
2151 RETVAL = newRV_noinc ((SV *)ncv);
2152}
2153 OUTPUT:
2154 RETVAL
2155
2156#endif
2157
2089 2158
2090MODULE = Coro::State PACKAGE = Coro::AIO 2159MODULE = Coro::State PACKAGE = Coro::AIO
2091 2160
2092SV * 2161SV *
2093_get_state () 2162_get_state ()

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines