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.245 by root, Mon Sep 22 05:40:21 2008 UTC vs.
Revision 1.253 by root, Fri Nov 7 20:12:26 2008 UTC

4#define PERL_EXT 4#define PERL_EXT
5 5
6#include "EXTERN.h" 6#include "EXTERN.h"
7#include "perl.h" 7#include "perl.h"
8#include "XSUB.h" 8#include "XSUB.h"
9#include "perliol.h"
9 10
10#include "patchlevel.h" 11#include "patchlevel.h"
11 12
12#include <stdio.h> 13#include <stdio.h>
13#include <errno.h> 14#include <errno.h>
80# ifndef IS_PADCONST 81# ifndef IS_PADCONST
81# define IS_PADCONST(v) 0 82# define IS_PADCONST(v) 0
82# endif 83# endif
83#endif 84#endif
84 85
86/* 5.11 */
87#ifndef CxHASARGS
88# define CxHASARGS(cx) (cx)->blk_sub.hasargs
89#endif
90
91/* 5.10.0 */
92#ifndef SvREFCNT_inc_NN
93# define SvREFCNT_inc_NN(sv) SvREFCNT_inc (sv)
94#endif
95
85/* 5.8.8 */ 96/* 5.8.8 */
86#ifndef GV_NOTQUAL 97#ifndef GV_NOTQUAL
87# define GV_NOTQUAL 0 98# define GV_NOTQUAL 0
88#endif 99#endif
89#ifndef newSV 100#ifndef newSV
90# define newSV(l) NEWSV(0,l) 101# define newSV(l) NEWSV(0,l)
91#endif
92
93/* 5.11 */
94#ifndef CxHASARGS
95# define CxHASARGS(cx) (cx)->blk_sub.hasargs
96#endif 102#endif
97 103
98/* 5.8.7 */ 104/* 5.8.7 */
99#ifndef SvRV_set 105#ifndef SvRV_set
100# define SvRV_set(s,v) SvRV(s) = (v) 106# define SvRV_set(s,v) SvRV(s) = (v)
136#define NOINLINE attribute ((noinline)) 142#define NOINLINE attribute ((noinline))
137 143
138#include "CoroAPI.h" 144#include "CoroAPI.h"
139 145
140#ifdef USE_ITHREADS 146#ifdef USE_ITHREADS
141static perl_mutex coro_mutex; 147static perl_mutex coro_lock;
142# define LOCK do { MUTEX_LOCK (&coro_mutex); } while (0) 148# define LOCK do { MUTEX_LOCK (&coro_lock); } while (0)
143# define UNLOCK do { MUTEX_UNLOCK (&coro_mutex); } while (0) 149# define UNLOCK do { MUTEX_UNLOCK (&coro_lock); } while (0)
144#else 150#else
145# define LOCK (void)0 151# define LOCK (void)0
146# define UNLOCK (void)0 152# define UNLOCK (void)0
147#endif 153#endif
148 154
149/* helper storage struct for Coro::AIO */ 155/* helper storage struct for Coro::AIO */
150struct io_state 156struct io_state
151{ 157{
158 AV *res;
152 int errorno; 159 int errorno;
153 I32 laststype; 160 I32 laststype;
154 int laststatval; 161 int laststatval;
155 Stat_t statcache; 162 Stat_t statcache;
156}; 163};
157 164
165static double (*nvtime)(); /* so why doesn't it take void? */
166
158static size_t coro_stacksize = CORO_STACKSIZE; 167static size_t coro_stacksize = CORO_STACKSIZE;
159static struct CoroAPI coroapi; 168static struct CoroAPI coroapi;
160static AV *main_mainstack; /* used to differentiate between $main and others */ 169static AV *main_mainstack; /* used to differentiate between $main and others */
161static JMPENV *main_top_env; 170static JMPENV *main_top_env;
162static HV *coro_state_stash, *coro_stash; 171static HV *coro_state_stash, *coro_stash;
163static volatile SV *coro_mortal; /* will be freed after next transfer */ 172static volatile SV *coro_mortal; /* will be freed/thrown after next transfer */
164 173
165static GV *irsgv; /* $/ */ 174static GV *irsgv; /* $/ */
166static GV *stdoutgv; /* *STDOUT */ 175static GV *stdoutgv; /* *STDOUT */
167static SV *rv_diehook; 176static SV *rv_diehook;
168static SV *rv_warnhook; 177static SV *rv_warnhook;
321 Perl_pad_push (aTHX_ padlist, AvFILLp (padlist) + 1, 1); 330 Perl_pad_push (aTHX_ padlist, AvFILLp (padlist) + 1, 1);
322#endif 331#endif
323 newpad = (AV *)AvARRAY (padlist)[AvFILLp (padlist)]; 332 newpad = (AV *)AvARRAY (padlist)[AvFILLp (padlist)];
324 --AvFILLp (padlist); 333 --AvFILLp (padlist);
325 334
326 av_store (newpadlist, 0, SvREFCNT_inc (*av_fetch (padlist, 0, FALSE))); 335 av_store (newpadlist, 0, SvREFCNT_inc_NN (*av_fetch (padlist, 0, FALSE)));
327 av_store (newpadlist, 1, (SV *)newpad); 336 av_store (newpadlist, 1, (SV *)newpad);
328 337
329 return newpadlist; 338 return newpadlist;
330} 339}
331 340
374static MGVTBL coro_cv_vtbl = { 383static MGVTBL coro_cv_vtbl = {
375 0, 0, 0, 0, 384 0, 0, 0, 0,
376 coro_cv_free 385 coro_cv_free
377}; 386};
378 387
379#define CORO_MAGIC(sv,type) \ 388#define CORO_MAGIC(sv, type) \
380 SvMAGIC (sv) \ 389 SvMAGIC (sv) \
381 ? SvMAGIC (sv)->mg_type == type \ 390 ? SvMAGIC (sv)->mg_type == type \
382 ? SvMAGIC (sv) \ 391 ? SvMAGIC (sv) \
383 : mg_find (sv, type) \ 392 : mg_find (sv, type) \
384 : 0 393 : 0
385 394
386#define CORO_MAGIC_cv(cv) CORO_MAGIC (((SV *)(cv)), CORO_MAGIC_type_cv) 395#define CORO_MAGIC_cv(cv) CORO_MAGIC (((SV *)(cv)), CORO_MAGIC_type_cv)
387#define CORO_MAGIC_state(sv) CORO_MAGIC (((SV *)(sv)), CORO_MAGIC_type_state) 396#define CORO_MAGIC_state(sv) CORO_MAGIC (((SV *)(sv)), CORO_MAGIC_type_state)
388 397
389static struct coro * 398static struct coro *
619 628
620/* 629/*
621 * destroy the stacks, the callchain etc... 630 * destroy the stacks, the callchain etc...
622 */ 631 */
623static void 632static void
624coro_destroy_stacks (pTHX) 633coro_destruct_stacks (pTHX)
625{ 634{
626 while (PL_curstackinfo->si_next) 635 while (PL_curstackinfo->si_next)
627 PL_curstackinfo = PL_curstackinfo->si_next; 636 PL_curstackinfo = PL_curstackinfo->si_next;
628 637
629 while (PL_curstackinfo) 638 while (PL_curstackinfo)
807 GvSV (PL_defgv) = newSV (0); 816 GvSV (PL_defgv) = newSV (0);
808 GvAV (PL_defgv) = coro->args; coro->args = 0; 817 GvAV (PL_defgv) = coro->args; coro->args = 0;
809 GvSV (PL_errgv) = newSV (0); 818 GvSV (PL_errgv) = newSV (0);
810 GvSV (irsgv) = newSVpvn ("\n", 1); sv_magic (GvSV (irsgv), (SV *)irsgv, PERL_MAGIC_sv, "/", 0); 819 GvSV (irsgv) = newSVpvn ("\n", 1); sv_magic (GvSV (irsgv), (SV *)irsgv, PERL_MAGIC_sv, "/", 0);
811 PL_rs = newSVsv (GvSV (irsgv)); 820 PL_rs = newSVsv (GvSV (irsgv));
812 PL_defoutgv = (GV *)SvREFCNT_inc (stdoutgv); 821 PL_defoutgv = (GV *)SvREFCNT_inc_NN (stdoutgv);
813 822
814 { 823 {
815 dSP; 824 dSP;
816 LOGOP myop; 825 LOGOP myop;
817 826
834 */ 843 */
835 ENTER; 844 ENTER;
836} 845}
837 846
838static void 847static void
839coro_destroy (pTHX_ struct coro *coro) 848coro_destruct (pTHX_ struct coro *coro)
840{ 849{
841 if (!IN_DESTRUCT) 850 if (!IN_DESTRUCT)
842 { 851 {
843 /* restore all saved variables and stuff */ 852 /* restore all saved variables and stuff */
844 LEAVE_SCOPE (0); 853 LEAVE_SCOPE (0);
866 SvREFCNT_dec (PL_warnhook); 875 SvREFCNT_dec (PL_warnhook);
867 876
868 SvREFCNT_dec (coro->saved_deffh); 877 SvREFCNT_dec (coro->saved_deffh);
869 SvREFCNT_dec (coro->throw); 878 SvREFCNT_dec (coro->throw);
870 879
871 coro_destroy_stacks (aTHX); 880 coro_destruct_stacks (aTHX);
872} 881}
873 882
874static void 883static void
875free_coro_mortal (pTHX) 884free_coro_mortal (pTHX)
876{ 885{
913 : cx->blk_gimme == G_SCALAR ? bot + 1 922 : cx->blk_gimme == G_SCALAR ? bot + 1
914 : bot; 923 : bot;
915 924
916 av_extend (av, top - bot); 925 av_extend (av, top - bot);
917 while (bot < top) 926 while (bot < top)
918 av_push (av, SvREFCNT_inc (*bot++)); 927 av_push (av, SvREFCNT_inc_NN (*bot++));
919 928
920 PL_runops = RUNOPS_DEFAULT; 929 PL_runops = RUNOPS_DEFAULT;
921 ENTER; 930 ENTER;
922 SAVETMPS; 931 SAVETMPS;
923 EXTEND (SP, 3); 932 EXTEND (SP, 3);
1071 coro_cctx *cctx; 1080 coro_cctx *cctx;
1072 void *stack_start; 1081 void *stack_start;
1073 size_t stack_size; 1082 size_t stack_size;
1074 1083
1075 ++cctx_count; 1084 ++cctx_count;
1076
1077 Newz (0, cctx, 1, coro_cctx); 1085 Newz (0, cctx, 1, coro_cctx);
1078 1086
1079#if HAVE_MMAP 1087#if HAVE_MMAP
1080 cctx->ssize = ((coro_stacksize * sizeof (long) + PAGESIZE - 1) / PAGESIZE + CORO_STACKGUARD) * PAGESIZE; 1088 cctx->ssize = ((coro_stacksize * sizeof (long) + PAGESIZE - 1) / PAGESIZE + CORO_STACKGUARD) * PAGESIZE;
1081 /* mmap supposedly does allocate-on-write for us */ 1089 /* mmap supposedly does allocate-on-write for us */
1117{ 1125{
1118 if (!cctx) 1126 if (!cctx)
1119 return; 1127 return;
1120 1128
1121 --cctx_count; 1129 --cctx_count;
1130 coro_destroy (&cctx->cctx);
1122 1131
1132 /* coro_transfer creates new, empty cctx's */
1133 if (cctx->sptr)
1134 {
1123#if CORO_USE_VALGRIND 1135#if CORO_USE_VALGRIND
1124 VALGRIND_STACK_DEREGISTER (cctx->valgrind_id); 1136 VALGRIND_STACK_DEREGISTER (cctx->valgrind_id);
1125#endif 1137#endif
1126 1138
1127#if HAVE_MMAP 1139#if HAVE_MMAP
1128 if (cctx->flags & CC_MAPPED) 1140 if (cctx->flags & CC_MAPPED)
1129 munmap (cctx->sptr, cctx->ssize); 1141 munmap (cctx->sptr, cctx->ssize);
1130 else 1142 else
1131#endif 1143#endif
1132 Safefree (cctx->sptr); 1144 Safefree (cctx->sptr);
1145 }
1133 1146
1134 Safefree (cctx); 1147 Safefree (cctx);
1135} 1148}
1136 1149
1137/* wether this cctx should be destructed */ 1150/* wether this cctx should be destructed */
1156} 1169}
1157 1170
1158static void 1171static void
1159cctx_put (coro_cctx *cctx) 1172cctx_put (coro_cctx *cctx)
1160{ 1173{
1174 assert (("cctx_put called on non-initialised cctx", cctx->sptr));
1175
1161 /* free another cctx if overlimit */ 1176 /* free another cctx if overlimit */
1162 if (expect_false (cctx_idle >= MAX_IDLE_CCTX)) 1177 if (expect_false (cctx_idle >= MAX_IDLE_CCTX))
1163 { 1178 {
1164 coro_cctx *first = cctx_first; 1179 coro_cctx *first = cctx_first;
1165 cctx_first = first->next; 1180 cctx_first = first->next;
1199/* always use the TRANSFER macro */ 1214/* always use the TRANSFER macro */
1200static void NOINLINE 1215static void NOINLINE
1201transfer (pTHX_ struct coro *prev, struct coro *next, int force_cctx) 1216transfer (pTHX_ struct coro *prev, struct coro *next, int force_cctx)
1202{ 1217{
1203 dSTACKLEVEL; 1218 dSTACKLEVEL;
1204 static volatile int has_throw;
1205 1219
1206 /* sometimes transfer is only called to set idle_sp */ 1220 /* sometimes transfer is only called to set idle_sp */
1207 if (expect_false (!next)) 1221 if (expect_false (!next))
1208 { 1222 {
1209 ((coro_cctx *)prev)->idle_sp = STACKLEVEL; 1223 ((coro_cctx *)prev)->idle_sp = STACKLEVEL;
1210 assert (((coro_cctx *)prev)->idle_te = PL_top_env); /* just for the side-effect when asserts are enabled */ 1224 assert (((coro_cctx *)prev)->idle_te = PL_top_env); /* just for the side-effect when asserts are enabled */
1211 } 1225 }
1212 else if (expect_true (prev != next)) 1226 else if (expect_true (prev != next))
1213 { 1227 {
1228 static volatile int has_throw;
1214 coro_cctx *prev__cctx; 1229 coro_cctx *prev__cctx;
1215 1230
1216 if (expect_false (prev->flags & CF_NEW)) 1231 if (expect_false (prev->flags & CF_NEW))
1217 { 1232 {
1218 /* create a new empty context */ 1233 /* create a new empty/source context */
1234 ++cctx_count;
1219 Newz (0, prev->cctx, 1, coro_cctx); 1235 New (0, prev->cctx, 1, coro_cctx);
1236 prev->cctx->sptr = 0;
1237 coro_create (&prev->cctx->cctx, 0, 0, 0, 0);
1238
1220 prev->flags &= ~CF_NEW; 1239 prev->flags &= ~CF_NEW;
1221 prev->flags |= CF_RUNNING; 1240 prev->flags |= CF_RUNNING;
1222 } 1241 }
1223 1242
1224 prev->flags &= ~CF_RUNNING; 1243 prev->flags &= ~CF_RUNNING;
1331 croak ("FATAL: tried to destroy currently running coroutine"); 1350 croak ("FATAL: tried to destroy currently running coroutine");
1332 1351
1333 save_perl (aTHX_ &temp); 1352 save_perl (aTHX_ &temp);
1334 load_perl (aTHX_ coro); 1353 load_perl (aTHX_ coro);
1335 1354
1336 coro_destroy (aTHX_ coro); 1355 coro_destruct (aTHX_ coro);
1337 1356
1338 load_perl (aTHX_ &temp); 1357 load_perl (aTHX_ &temp);
1339 1358
1340 coro->slot = 0; 1359 coro->slot = 0;
1341 } 1360 }
1447 LOCK; 1466 LOCK;
1448 1467
1449 sv_hook = coro_nready ? 0 : coro_readyhook; 1468 sv_hook = coro_nready ? 0 : coro_readyhook;
1450 xs_hook = coro_nready ? 0 : coroapi.readyhook; 1469 xs_hook = coro_nready ? 0 : coroapi.readyhook;
1451 1470
1452 coro_enq (aTHX_ SvREFCNT_inc (coro_sv)); 1471 coro_enq (aTHX_ SvREFCNT_inc_NN (coro_sv));
1453 ++coro_nready; 1472 ++coro_nready;
1454 1473
1455 UNLOCK; 1474 UNLOCK;
1456 1475
1457 if (sv_hook) 1476 if (sv_hook)
1645static MGVTBL coro_gensub_vtbl = { 1664static MGVTBL coro_gensub_vtbl = {
1646 0, 0, 0, 0, 1665 0, 0, 0, 0,
1647 coro_gensub_free 1666 coro_gensub_free
1648}; 1667};
1649 1668
1669/*****************************************************************************/
1670/* PerlIO::cede */
1671
1672typedef struct
1673{
1674 PerlIOBuf base;
1675 NV next, every;
1676} PerlIOCede;
1677
1678static IV
1679PerlIOCede_pushed (pTHX_ PerlIO *f, const char *mode, SV *arg, PerlIO_funcs *tab)
1680{
1681 PerlIOCede *self = PerlIOSelf (f, PerlIOCede);
1682
1683 self->every = SvCUR (arg) ? SvNV (arg) : 0.01;
1684 self->next = nvtime () + self->every;
1685
1686 return PerlIOBuf_pushed (aTHX_ f, mode, Nullsv, tab);
1687}
1688
1689static SV *
1690PerlIOCede_getarg (pTHX_ PerlIO *f, CLONE_PARAMS *param, int flags)
1691{
1692 PerlIOCede *self = PerlIOSelf (f, PerlIOCede);
1693
1694 return newSVnv (self->every);
1695}
1696
1697static IV
1698PerlIOCede_flush (pTHX_ PerlIO *f)
1699{
1700 PerlIOCede *self = PerlIOSelf (f, PerlIOCede);
1701 double now = nvtime ();
1702
1703 if (now >= self->next)
1704 {
1705 api_cede ();
1706 self->next = now + self->every;
1707 }
1708
1709 return PerlIOBuf_flush (aTHX_ f);
1710}
1711
1712static PerlIO_funcs PerlIO_cede =
1713{
1714 sizeof(PerlIO_funcs),
1715 "cede",
1716 sizeof(PerlIOCede),
1717 PERLIO_K_DESTRUCT | PERLIO_K_RAW,
1718 PerlIOCede_pushed,
1719 PerlIOBuf_popped,
1720 PerlIOBuf_open,
1721 PerlIOBase_binmode,
1722 PerlIOCede_getarg,
1723 PerlIOBase_fileno,
1724 PerlIOBuf_dup,
1725 PerlIOBuf_read,
1726 PerlIOBuf_unread,
1727 PerlIOBuf_write,
1728 PerlIOBuf_seek,
1729 PerlIOBuf_tell,
1730 PerlIOBuf_close,
1731 PerlIOCede_flush,
1732 PerlIOBuf_fill,
1733 PerlIOBase_eof,
1734 PerlIOBase_error,
1735 PerlIOBase_clearerr,
1736 PerlIOBase_setlinebuf,
1737 PerlIOBuf_get_base,
1738 PerlIOBuf_bufsiz,
1739 PerlIOBuf_get_ptr,
1740 PerlIOBuf_get_cnt,
1741 PerlIOBuf_set_ptrcnt,
1742};
1743
1744
1650MODULE = Coro::State PACKAGE = Coro::State PREFIX = api_ 1745MODULE = Coro::State PACKAGE = Coro::State PREFIX = api_
1651 1746
1652PROTOTYPES: DISABLE 1747PROTOTYPES: DISABLE
1653 1748
1654BOOT: 1749BOOT:
1655{ 1750{
1656#ifdef USE_ITHREADS 1751#ifdef USE_ITHREADS
1657 MUTEX_INIT (&coro_mutex); 1752 MUTEX_INIT (&coro_lock);
1658#endif 1753#endif
1659 BOOT_PAGESIZE; 1754 BOOT_PAGESIZE;
1660 1755
1661 irsgv = gv_fetchpv ("/" , GV_ADD|GV_NOTQUAL, SVt_PV); 1756 irsgv = gv_fetchpv ("/" , GV_ADD|GV_NOTQUAL, SVt_PV);
1662 stdoutgv = gv_fetchpv ("STDOUT", GV_ADD|GV_NOTQUAL, SVt_PVIO); 1757 stdoutgv = gv_fetchpv ("STDOUT", GV_ADD|GV_NOTQUAL, SVt_PVIO);
1683 main_top_env = main_top_env->je_prev; 1778 main_top_env = main_top_env->je_prev;
1684 1779
1685 coroapi.ver = CORO_API_VERSION; 1780 coroapi.ver = CORO_API_VERSION;
1686 coroapi.rev = CORO_API_REVISION; 1781 coroapi.rev = CORO_API_REVISION;
1687 coroapi.transfer = api_transfer; 1782 coroapi.transfer = api_transfer;
1783
1784 {
1785 SV **svp = hv_fetch (PL_modglobal, "Time::NVtime", 12, 0);
1786
1787 if (!svp) croak ("Time::HiRes is required");
1788 if (!SvIOK (*svp)) croak ("Time::NVtime isn't a function pointer");
1789
1790 nvtime = INT2PTR (double (*)(), SvIV (*svp));
1791 }
1688 1792
1689 assert (("PRIO_NORMAL must be 0", !PRIO_NORMAL)); 1793 assert (("PRIO_NORMAL must be 0", !PRIO_NORMAL));
1690} 1794}
1691 1795
1692SV * 1796SV *
1740 ta.next = 0; 1844 ta.next = 0;
1741 break; 1845 break;
1742 1846
1743 case 1: 1847 case 1:
1744 if (items != 2) 1848 if (items != 2)
1745 croak ("Coro::State::transfer (prev,next) expects two arguments, not %d", items); 1849 croak ("Coro::State::transfer (prev, next) expects two arguments, not %d", items);
1746 1850
1747 prepare_transfer (aTHX_ &ta, ST (0), ST (1)); 1851 prepare_transfer (aTHX_ &ta, ST (0), ST (1));
1748 break; 1852 break;
1749 1853
1750 case 2: 1854 case 2:
1913 CODE: 2017 CODE:
1914 struct coro *coro = SvSTATE (coro_current); 2018 struct coro *coro = SvSTATE (coro_current);
1915 coro->cctx->idle_sp = 0; 2019 coro->cctx->idle_sp = 0;
1916 2020
1917void 2021void
1918throw (Coro::State self, SV *throw = &PL_sv_undef)
1919 PROTOTYPE: $;$
1920 CODE:
1921 SvREFCNT_dec (self->throw);
1922 self->throw = SvOK (throw) ? newSVsv (throw) : 0;
1923
1924void
1925swap_defsv (Coro::State self) 2022swap_defsv (Coro::State self)
1926 PROTOTYPE: $ 2023 PROTOTYPE: $
1927 ALIAS: 2024 ALIAS:
1928 swap_defav = 1 2025 swap_defav = 1
1929 CODE: 2026 CODE:
1983void 2080void
1984_set_current (SV *current) 2081_set_current (SV *current)
1985 PROTOTYPE: $ 2082 PROTOTYPE: $
1986 CODE: 2083 CODE:
1987 SvREFCNT_dec (SvRV (coro_current)); 2084 SvREFCNT_dec (SvRV (coro_current));
1988 SvRV_set (coro_current, SvREFCNT_inc (SvRV (current))); 2085 SvRV_set (coro_current, SvREFCNT_inc_NN (SvRV (current)));
1989 2086
1990void 2087void
1991_set_readyhook (SV *hook) 2088_set_readyhook (SV *hook)
1992 PROTOTYPE: $ 2089 PROTOTYPE: $
1993 CODE: 2090 CODE:
2032 CODE: 2129 CODE:
2033 RETVAL = coro_nready; 2130 RETVAL = coro_nready;
2034 OUTPUT: 2131 OUTPUT:
2035 RETVAL 2132 RETVAL
2036 2133
2134void
2135throw (Coro::State self, SV *throw = &PL_sv_undef)
2136 PROTOTYPE: $;$
2137 CODE:
2138 SvREFCNT_dec (self->throw);
2139 self->throw = SvOK (throw) ? newSVsv (throw) : 0;
2140
2037# for async_pool speedup 2141# for async_pool speedup
2038void 2142void
2039_pool_1 (SV *cb) 2143_pool_1 (SV *cb)
2040 CODE: 2144 CODE:
2041{ 2145{
2053 SvREFCNT_dec (old); 2157 SvREFCNT_dec (old);
2054 croak ("\3async_pool terminate\2\n"); 2158 croak ("\3async_pool terminate\2\n");
2055 } 2159 }
2056 2160
2057 SvREFCNT_dec (coro->saved_deffh); 2161 SvREFCNT_dec (coro->saved_deffh);
2058 coro->saved_deffh = SvREFCNT_inc ((SV *)PL_defoutgv); 2162 coro->saved_deffh = SvREFCNT_inc_NN ((SV *)PL_defoutgv);
2059 2163
2060 hv_store (hv, "desc", sizeof ("desc") - 1, 2164 hv_store (hv, "desc", sizeof ("desc") - 1,
2061 newSVpvn ("[async_pool]", sizeof ("[async_pool]") - 1), 0); 2165 newSVpvn ("[async_pool]", sizeof ("[async_pool]") - 1), 0);
2062 2166
2063 invoke_av = (AV *)SvRV (invoke); 2167 invoke_av = (AV *)SvRV (invoke);
2067 2171
2068 if (len > 0) 2172 if (len > 0)
2069 { 2173 {
2070 av_fill (defav, len - 1); 2174 av_fill (defav, len - 1);
2071 for (i = 0; i < len; ++i) 2175 for (i = 0; i < len; ++i)
2072 av_store (defav, i, SvREFCNT_inc (AvARRAY (invoke_av)[i + 1])); 2176 av_store (defav, i, SvREFCNT_inc_NN (AvARRAY (invoke_av)[i + 1]));
2073 } 2177 }
2074 2178
2075 SvREFCNT_dec (invoke); 2179 SvREFCNT_dec (invoke);
2076} 2180}
2077 2181
2156#endif 2260#endif
2157 2261
2158 2262
2159MODULE = Coro::State PACKAGE = Coro::AIO 2263MODULE = Coro::State PACKAGE = Coro::AIO
2160 2264
2161SV * 2265void
2162_get_state () 2266_get_state (SV *self)
2163 CODE: 2267 PPCODE:
2164{ 2268{
2165 struct io_state *data; 2269 AV *defav = GvAV (PL_defgv);
2166 2270 AV *av = newAV ();
2271 int i;
2167 RETVAL = newSV (sizeof (struct io_state)); 2272 SV *data_sv = newSV (sizeof (struct io_state));
2168 data = (struct io_state *)SvPVX (RETVAL); 2273 struct io_state *data = (struct io_state *)SvPVX (data_sv);
2169 SvCUR_set (RETVAL, sizeof (struct io_state)); 2274 SvCUR_set (data_sv, sizeof (struct io_state));
2170 SvPOK_only (RETVAL); 2275 SvPOK_only (data_sv);
2171 2276
2172 data->errorno = errno; 2277 data->errorno = errno;
2173 data->laststype = PL_laststype; 2278 data->laststype = PL_laststype;
2174 data->laststatval = PL_laststatval; 2279 data->laststatval = PL_laststatval;
2175 data->statcache = PL_statcache; 2280 data->statcache = PL_statcache;
2281
2282 av_extend (av, AvFILLp (defav) + 1 + 1);
2283
2284 for (i = 0; i <= AvFILLp (defav); ++i)
2285 av_push (av, SvREFCNT_inc_NN (AvARRAY (defav)[i]));
2286
2287 av_push (av, data_sv);
2288
2289 XPUSHs (sv_2mortal (newRV_noinc ((SV *)av)));
2290
2291 api_ready (self);
2176} 2292}
2177 OUTPUT:
2178 RETVAL
2179 2293
2180void 2294void
2181_set_state (char *data_) 2295_set_state (SV *state)
2182 PROTOTYPE: $ 2296 PROTOTYPE: $
2183 CODE: 2297 PPCODE:
2184{ 2298{
2185 struct io_state *data = (void *)data_; 2299 AV *av = (AV *)SvRV (state);
2300 struct io_state *data = (struct io_state *)SvPVX (AvARRAY (av)[AvFILLp (av)]);
2301 int i;
2186 2302
2187 errno = data->errorno; 2303 errno = data->errorno;
2188 PL_laststype = data->laststype; 2304 PL_laststype = data->laststype;
2189 PL_laststatval = data->laststatval; 2305 PL_laststatval = data->laststatval;
2190 PL_statcache = data->statcache; 2306 PL_statcache = data->statcache;
2307
2308 EXTEND (SP, AvFILLp (av));
2309 for (i = 0; i < AvFILLp (av); ++i)
2310 PUSHs (sv_2mortal (SvREFCNT_inc_NN (AvARRAY (av)[i])));
2191} 2311}
2192 2312
2193 2313
2194MODULE = Coro::State PACKAGE = Coro::AnyEvent 2314MODULE = Coro::State PACKAGE = Coro::AnyEvent
2195 2315
2219 } 2339 }
2220 2340
2221 --incede; 2341 --incede;
2222} 2342}
2223 2343
2344
2345MODULE = Coro::State PACKAGE = PerlIO::cede
2346
2347BOOT:
2348 PerlIO_define_layer (aTHX_ &PerlIO_cede);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines