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.427 by root, Wed Dec 5 14:35:34 2012 UTC vs.
Revision 1.447 by root, Tue Oct 14 21:53:32 2014 UTC

1/* this works around a bug in mingw32 providing a non-working setjmp */ 1/* this works around a bug in mingw32 providing a non-working setjmp */
2#define USE_NO_MINGW_SETJMP_TWO_ARGS 2#define USE_NO_MINGW_SETJMP_TWO_ARGS
3 3
4#define NDEBUG 1 4#define NDEBUG 1 /* perl usually disables NDEBUG later */
5 5
6#include "libcoro/coro.c" 6#include "libcoro/coro.c"
7 7
8#define PERL_NO_GET_CONTEXT 8#define PERL_NO_GET_CONTEXT
9#define PERL_EXT 9#define PERL_EXT
14#include "perliol.h" 14#include "perliol.h"
15 15
16#include "schmorp.h" 16#include "schmorp.h"
17 17
18#define ECB_NO_THREADS 1 18#define ECB_NO_THREADS 1
19#define ECB_NO_LIBM 1
19#include "ecb.h" 20#include "ecb.h"
20 21
21#include <stddef.h> 22#include <stddef.h>
22#include <stdio.h> 23#include <stdio.h>
23#include <errno.h> 24#include <errno.h>
26#ifndef SVs_PADSTALE 27#ifndef SVs_PADSTALE
27# define SVs_PADSTALE 0 28# define SVs_PADSTALE 0
28#endif 29#endif
29 30
30#ifdef PadARRAY 31#ifdef PadARRAY
31# define NEWPADAPI 32# define NEWPADAPI 1
32# define newPADLIST(var) (Newz (0, var, 1, PADLIST), Newx (PadlistARRAY (var), 2, PAD *)) 33# define newPADLIST(var) (Newz (0, var, 1, PADLIST), Newx (PadlistARRAY (var), 2, PAD *))
33#else 34#else
34typedef AV PADNAMELIST; 35typedef AV PADNAMELIST;
35# if !PERL_VERSION_ATLEAST(5,8,0) 36# if !PERL_VERSION_ATLEAST(5,8,0)
36typedef AV PADLIST; 37typedef AV PADLIST;
42# define PadARRAY AvARRAY 43# define PadARRAY AvARRAY
43# define PadMAX AvFILLp 44# define PadMAX AvFILLp
44# define newPADLIST(var) ((var) = newAV (), av_extend (var, 1)) 45# define newPADLIST(var) ((var) = newAV (), av_extend (var, 1))
45#endif 46#endif
46 47
48/* 5.19.something has replaced SVt_BIND by SVt_INVLIST */
49/* we just alias it to SVt_IV, as that is sufficient for swap_sv for now */
50#if PERL_VERSION_ATLEAST(5,19,0)
51# define SVt_BIND SVt_IV
52#endif
53
47#if defined(_WIN32) 54#if defined(_WIN32)
48# undef HAS_GETTIMEOFDAY 55# undef HAS_GETTIMEOFDAY
49# undef setjmp 56# undef setjmp
50# undef longjmp 57# undef longjmp
51# undef _exit 58# undef _exit
52# define setjmp _setjmp /* deep magic */ 59# define setjmp _setjmp /* deep magic */
53#else 60#else
54# include <inttypes.h> /* most portable stdint.h */ 61# include <inttypes.h> /* most portable stdint.h */
55#endif 62#endif
56 63
57#if HAVE_MMAP
58# include <unistd.h>
59# include <sys/mman.h>
60# ifndef MAP_ANONYMOUS
61# ifdef MAP_ANON
62# define MAP_ANONYMOUS MAP_ANON
63# else
64# undef HAVE_MMAP
65# endif
66# endif
67# include <limits.h>
68# ifndef PAGESIZE
69# define PAGESIZE pagesize
70# define BOOT_PAGESIZE pagesize = sysconf (_SC_PAGESIZE)
71static long pagesize;
72# else
73# define BOOT_PAGESIZE (void)0
74# endif
75#else
76# define PAGESIZE 0
77# define BOOT_PAGESIZE (void)0
78#endif
79
80#if CORO_USE_VALGRIND
81# include <valgrind/valgrind.h>
82#endif
83
84/* the maximum number of idle cctx that will be pooled */ 64/* the maximum number of idle cctx that will be pooled */
85static int cctx_max_idle = 4; 65static int cctx_max_idle = 4;
86 66
87#if defined(DEBUGGING) && PERL_VERSION_ATLEAST(5,12,0) 67#if defined(DEBUGGING) && PERL_VERSION_ATLEAST(5,12,0)
88# define HAS_SCOPESTACK_NAME 1 68# define HAS_SCOPESTACK_NAME 1
89#endif
90
91#if !__i386 && !__x86_64 && !__powerpc && !__m68k && !__alpha && !__mips && !__sparc64
92# undef CORO_STACKGUARD
93#endif
94
95#ifndef CORO_STACKGUARD
96# define CORO_STACKGUARD 0
97#endif 69#endif
98 70
99/* prefer perl internal functions over our own? */ 71/* prefer perl internal functions over our own? */
100#ifndef CORO_PREFER_PERL_FUNCTIONS 72#ifndef CORO_PREFER_PERL_FUNCTIONS
101# define CORO_PREFER_PERL_FUNCTIONS 0 73# define CORO_PREFER_PERL_FUNCTIONS 0
192typedef struct coro_cctx 164typedef struct coro_cctx
193{ 165{
194 struct coro_cctx *next; 166 struct coro_cctx *next;
195 167
196 /* the stack */ 168 /* the stack */
197 void *sptr; 169 struct coro_stack stack;
198 size_t ssize;
199 170
200 /* cpu state */ 171 /* cpu state */
201 void *idle_sp; /* sp of top-level transfer/schedule/cede call */ 172 void *idle_sp; /* sp of top-level transfer/schedule/cede call */
202#ifndef NDEBUG 173#ifndef NDEBUG
203 JMPENV *idle_te; /* same as idle_sp, but for top_env */ 174 JMPENV *idle_te; /* same as idle_sp, but for top_env */
312#define coro_nready coroapi.nready 283#define coro_nready coroapi.nready
313 284
314/** JIT *********************************************************************/ 285/** JIT *********************************************************************/
315 286
316#if CORO_JIT 287#if CORO_JIT
317 /* APPLE doesn't have HAVE_MMAP though */ 288 /* APPLE doesn't have mmap though */
318 #define CORO_JIT_UNIXY (__linux || __FreeBSD__ || __OpenBSD__ || __NetBSD__ || __solaris || __APPLE__) 289 #define CORO_JIT_UNIXY (__linux || __FreeBSD__ || __OpenBSD__ || __NetBSD__ || __solaris || __APPLE__)
319 #ifndef CORO_JIT_TYPE 290 #ifndef CORO_JIT_TYPE
320 #if __x86_64 && CORO_JIT_UNIXY 291 #if ECB_AMD64 && CORO_JIT_UNIXY
321 #define CORO_JIT_TYPE "amd64-unix" 292 #define CORO_JIT_TYPE "amd64-unix"
322 #elif __i386 && CORO_JIT_UNIXY 293 #elif __i386 && CORO_JIT_UNIXY
323 #define CORO_JIT_TYPE "x86-unix" 294 #define CORO_JIT_TYPE "x86-unix"
324 #endif 295 #endif
325 #endif 296 #endif
326#endif 297#endif
327 298
328#if !defined(CORO_JIT_TYPE) || !HAVE_MMAP 299#if !defined(CORO_JIT_TYPE) || _POSIX_MEMORY_PROTECTION <= 0
329 #undef CORO_JIT 300 #undef CORO_JIT
330#endif 301#endif
331 302
332#if CORO_JIT 303#if CORO_JIT
333 typedef void (*load_save_perl_slots_type)(perl_slots *); 304 typedef void (*load_save_perl_slots_type)(perl_slots *);
547coro_derive_padlist (pTHX_ CV *cv) 518coro_derive_padlist (pTHX_ CV *cv)
548{ 519{
549 PADLIST *padlist = CvPADLIST (cv); 520 PADLIST *padlist = CvPADLIST (cv);
550 PADLIST *newpadlist; 521 PADLIST *newpadlist;
551 PAD *newpad; 522 PAD *newpad;
552 PADOFFSET const off = PadlistMAX (padlist) + 1; 523 PADOFFSET off = PadlistMAX (padlist) + 1;
553 524
554 newPADLIST(newpadlist); 525#if NEWPADAPI
555#if !PERL_VERSION_ATLEAST(5,15,3) 526
556 /* Padlists are AvREAL as of 5.15.3. See perl bug #98092 and perl commit 7d953ba. */ 527 /* if we had the original CvDEPTH, we might be able to steal the CvDEPTH+1 entry instead */
557 AvREAL_off (newpadlist); 528 /* 20131102194744.GA6705@schmorp.de, 20131102195825.2013.qmail@lists-nntp.develooper.com */
558#endif 529 while (!PadlistARRAY (padlist)[off - 1])
530 --off;
531
532 Perl_pad_push (aTHX_ padlist, off);
533
534 newpad = PadlistARRAY (padlist)[off];
535 PadlistARRAY (padlist)[off] = 0;
536
537#else
538
559#if PERL_VERSION_ATLEAST (5,10,0) 539#if PERL_VERSION_ATLEAST (5,10,0)
560 Perl_pad_push (aTHX_ padlist, off); 540 Perl_pad_push (aTHX_ padlist, off);
561#else 541#else
562 Perl_pad_push (aTHX_ padlist, off, 1); 542 Perl_pad_push (aTHX_ padlist, off, 1);
563#endif 543#endif
544
564 newpad = PadlistARRAY (padlist)[off]; 545 newpad = PadlistARRAY (padlist)[off];
565 PadlistMAX (padlist) = off - 1; 546 PadlistMAX (padlist) = off - 1;
547
548#endif
549
550 newPADLIST (newpadlist);
551#if !PERL_VERSION_ATLEAST(5,15,3)
552 /* Padlists are AvREAL as of 5.15.3. See perl bug #98092 and perl commit 7d953ba. */
553 AvREAL_off (newpadlist);
554#endif
566 555
567 /* Already extended to 2 elements by newPADLIST. */ 556 /* Already extended to 2 elements by newPADLIST. */
568 PadlistMAX (newpadlist) = 1; 557 PadlistMAX (newpadlist) = 1;
569 PadlistNAMES (newpadlist) = (PADNAMELIST *)SvREFCNT_inc_NN (PadlistNAMES (padlist)); 558 PadlistNAMES (newpadlist) = (PADNAMELIST *)SvREFCNT_inc_NN (PadlistNAMES (padlist));
570 PadlistARRAY (newpadlist)[1] = newpad; 559 PadlistARRAY (newpadlist)[1] = newpad;
582 571
583 while (i > 0) /* special-case index 0 */ 572 while (i > 0) /* special-case index 0 */
584 { 573 {
585 /* we try to be extra-careful here */ 574 /* we try to be extra-careful here */
586 PAD *pad = PadlistARRAY (padlist)[i--]; 575 PAD *pad = PadlistARRAY (padlist)[i--];
576
577 if (pad)
578 {
587 I32 j = PadMAX (pad); 579 I32 j = PadMAX (pad);
588 580
589 while (j >= 0) 581 while (j >= 0)
590 SvREFCNT_dec (PadARRAY (pad)[j--]); 582 SvREFCNT_dec (PadARRAY (pad)[j--]);
591 583
592 PadMAX (pad) = -1; 584 PadMAX (pad) = -1;
593 SvREFCNT_dec (pad); 585 SvREFCNT_dec (pad);
586 }
594 } 587 }
595 588
596 SvREFCNT_dec (PadlistNAMES (padlist)); 589 SvREFCNT_dec (PadlistNAMES (padlist));
597 590
598#ifdef NEWPADAPI 591#if NEWPADAPI
599 Safefree (PadlistARRAY (padlist)); 592 Safefree (PadlistARRAY (padlist));
600 Safefree (padlist); 593 Safefree (padlist);
601#else 594#else
602 AvFILLp (padlist) = -1; 595 AvFILLp (padlist) = -1;
603 AvREAL_off (padlist); 596 AvREAL_off (padlist);
1145 1138
1146 GvSV (PL_defgv) = newSV (0); 1139 GvSV (PL_defgv) = newSV (0);
1147 GvAV (PL_defgv) = coro->args; coro->args = 0; 1140 GvAV (PL_defgv) = coro->args; coro->args = 0;
1148 GvSV (PL_errgv) = newSV (0); 1141 GvSV (PL_errgv) = newSV (0);
1149 GvSV (irsgv) = newSVpvn ("\n", 1); sv_magic (GvSV (irsgv), (SV *)irsgv, PERL_MAGIC_sv, "/", 0); 1142 GvSV (irsgv) = newSVpvn ("\n", 1); sv_magic (GvSV (irsgv), (SV *)irsgv, PERL_MAGIC_sv, "/", 0);
1150 GvHV (PL_hintgv) = 0; 1143 GvHV (PL_hintgv) = newHV ();
1144#if PERL_VERSION_ATLEAST (5,10,0)
1145 hv_magic (GvHV (PL_hintgv), 0, PERL_MAGIC_hints);
1146#endif
1151 PL_rs = newSVsv (GvSV (irsgv)); 1147 PL_rs = newSVsv (GvSV (irsgv));
1152 PL_defoutgv = (GV *)SvREFCNT_inc_NN (stdoutgv); 1148 PL_defoutgv = (GV *)SvREFCNT_inc_NN (stdoutgv);
1153 1149
1154 { 1150 {
1155 dSP; 1151 dSP;
1519static coro_cctx * 1515static coro_cctx *
1520cctx_new_empty (void) 1516cctx_new_empty (void)
1521{ 1517{
1522 coro_cctx *cctx = cctx_new (); 1518 coro_cctx *cctx = cctx_new ();
1523 1519
1524 cctx->sptr = 0; 1520 cctx->stack.sptr = 0;
1525 coro_create (&cctx->cctx, 0, 0, 0, 0); 1521 coro_create (&cctx->cctx, 0, 0, 0, 0);
1526 1522
1527 return cctx; 1523 return cctx;
1528} 1524}
1529 1525
1530/* create a new cctx suitable as destination/running a perl interpreter */ 1526/* create a new cctx suitable as destination/running a perl interpreter */
1531static coro_cctx * 1527static coro_cctx *
1532cctx_new_run (void) 1528cctx_new_run (void)
1533{ 1529{
1534 coro_cctx *cctx = cctx_new (); 1530 coro_cctx *cctx = cctx_new ();
1535 void *stack_start;
1536 size_t stack_size;
1537 1531
1538#if CORO_FIBER 1532 if (!coro_stack_alloc (&cctx->stack, cctx_stacksize))
1539
1540 cctx->ssize = cctx_stacksize * sizeof (long);
1541 cctx->sptr = 0;
1542
1543#else
1544
1545 #if HAVE_MMAP
1546 cctx->ssize = ((cctx_stacksize * sizeof (long) + PAGESIZE - 1) / PAGESIZE + CORO_STACKGUARD) * PAGESIZE;
1547 /* mmap supposedly does allocate-on-write for us */
1548 cctx->sptr = mmap (0, cctx->ssize, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_ANONYMOUS, -1, 0);
1549
1550 if (cctx->sptr != (void *)-1)
1551 { 1533 {
1552 #if CORO_STACKGUARD
1553 mprotect (cctx->sptr, CORO_STACKGUARD * PAGESIZE, PROT_NONE);
1554 #endif
1555 stack_start = (char *)cctx->sptr + CORO_STACKGUARD * PAGESIZE;
1556 stack_size = cctx->ssize - CORO_STACKGUARD * PAGESIZE;
1557 cctx->flags |= CC_MAPPED;
1558 }
1559 else
1560 #endif
1561 {
1562 cctx->ssize = cctx_stacksize * (long)sizeof (long);
1563 New (0, cctx->sptr, cctx_stacksize, long);
1564
1565 if (!cctx->sptr)
1566 {
1567 perror ("FATAL: unable to allocate stack for coroutine, exiting."); 1534 perror ("FATAL: unable to allocate stack for coroutine, exiting.");
1568 _exit (EXIT_FAILURE); 1535 _exit (EXIT_FAILURE);
1569 }
1570
1571 stack_start = cctx->sptr;
1572 stack_size = cctx->ssize;
1573 } 1536 }
1574 #endif
1575 1537
1576 #if CORO_USE_VALGRIND
1577 cctx->valgrind_id = VALGRIND_STACK_REGISTER ((char *)stack_start, (char *)stack_start + stack_size);
1578 #endif
1579
1580 coro_create (&cctx->cctx, cctx_run, (void *)cctx, stack_start, stack_size); 1538 coro_create (&cctx->cctx, cctx_run, (void *)cctx, cctx->stack.sptr, cctx->stack.ssze);
1581 1539
1582 return cctx; 1540 return cctx;
1583} 1541}
1584 1542
1585static void 1543static void
1591 assert (("FATAL: tried to destroy current cctx", cctx != cctx_current)); 1549 assert (("FATAL: tried to destroy current cctx", cctx != cctx_current));
1592 1550
1593 --cctx_count; 1551 --cctx_count;
1594 coro_destroy (&cctx->cctx); 1552 coro_destroy (&cctx->cctx);
1595 1553
1596 /* coro_transfer creates new, empty cctx's */ 1554 coro_stack_free (&cctx->stack);
1597 if (cctx->sptr)
1598 {
1599 #if CORO_USE_VALGRIND
1600 VALGRIND_STACK_DEREGISTER (cctx->valgrind_id);
1601 #endif
1602
1603#if HAVE_MMAP
1604 if (cctx->flags & CC_MAPPED)
1605 munmap (cctx->sptr, cctx->ssize);
1606 else
1607#endif
1608 Safefree (cctx->sptr);
1609 }
1610 1555
1611 Safefree (cctx); 1556 Safefree (cctx);
1612} 1557}
1613 1558
1614/* wether this cctx should be destructed */ 1559/* wether this cctx should be destructed */
1633} 1578}
1634 1579
1635static void 1580static void
1636cctx_put (coro_cctx *cctx) 1581cctx_put (coro_cctx *cctx)
1637{ 1582{
1638 assert (("FATAL: cctx_put called on non-initialised cctx in Coro (please report)", cctx->sptr)); 1583 assert (("FATAL: cctx_put called on non-initialised cctx in Coro (please report)", cctx->stack.sptr));
1639 1584
1640 /* free another cctx if overlimit */ 1585 /* free another cctx if overlimit */
1641 if (ecb_expect_false (cctx_idle >= cctx_max_idle)) 1586 if (ecb_expect_false (cctx_idle >= cctx_max_idle))
1642 { 1587 {
1643 coro_cctx *first = cctx_first; 1588 coro_cctx *first = cctx_first;
1975 /* nothing to schedule: call the idle handler */ 1920 /* nothing to schedule: call the idle handler */
1976 if (SvROK (sv_idle) 1921 if (SvROK (sv_idle)
1977 && SvOBJECT (SvRV (sv_idle))) 1922 && SvOBJECT (SvRV (sv_idle)))
1978 { 1923 {
1979 if (SvRV (sv_idle) == SvRV (coro_current)) 1924 if (SvRV (sv_idle) == SvRV (coro_current))
1925 {
1926 require_pv ("Carp");
1927
1928 {
1929 dSP;
1930
1931 ENTER;
1932 SAVETMPS;
1933
1934 PUSHMARK (SP);
1980 croak ("FATAL: $Coro::IDLE blocked itself - did you try to block inside an event loop callback? Caught"); 1935 XPUSHs (sv_2mortal (newSVpv ("FATAL: $Coro::idle blocked itself - did you try to block inside an event loop callback? Caught", 0)));
1936 PUTBACK;
1937 call_pv ("Carp::confess", G_VOID | G_DISCARD);
1938
1939 FREETMPS;
1940 LEAVE;
1941 }
1942 }
1981 1943
1982 ++coro_nready; /* hack so that api_ready doesn't invoke ready hook */ 1944 ++coro_nready; /* hack so that api_ready doesn't invoke ready hook */
1983 api_ready (aTHX_ SvRV (sv_idle)); 1945 api_ready (aTHX_ SvRV (sv_idle));
1984 --coro_nready; 1946 --coro_nready;
1985 } 1947 }
2183 AV *od = coro->on_destroy; 2145 AV *od = coro->on_destroy;
2184 2146
2185 if (!od) 2147 if (!od)
2186 return; 2148 return;
2187 2149
2150 coro->on_destroy = 0;
2151 sv_2mortal ((SV *)od);
2152
2188 while (AvFILLp (od) >= 0) 2153 while (AvFILLp (od) >= 0)
2189 { 2154 {
2190 SV *cb = sv_2mortal (av_pop (od)); 2155 SV *cb = sv_2mortal (av_pop (od));
2191 2156
2192 /* coro hv's (and only hv's at the moment) are supported as well */ 2157 /* coro hv's (and only hv's at the moment) are supported as well */
2286 slf_init_terminate_cancel_common (aTHX_ frame, coro_hv); 2251 slf_init_terminate_cancel_common (aTHX_ frame, coro_hv);
2287 } 2252 }
2288 else 2253 else
2289 { 2254 {
2290 struct coro *self = SvSTATE_current; 2255 struct coro *self = SvSTATE_current;
2256
2257 if (!self)
2258 croak ("Coro::cancel called outside of thread content,");
2291 2259
2292 /* otherwise we cancel directly, purely for speed reasons 2260 /* otherwise we cancel directly, purely for speed reasons
2293 * unfortunately, this requires some magic trickery, as 2261 * unfortunately, this requires some magic trickery, as
2294 * somebody else could cancel us, so we have to fight the cancellation. 2262 * somebody else could cancel us, so we have to fight the cancellation.
2295 * this is ugly, and hopefully fully worth the extra speed. 2263 * this is ugly, and hopefully fully worth the extra speed.
2637 2605
2638/* "undo"/cancel a running slf call - used when cancelling a coro, mainly */ 2606/* "undo"/cancel a running slf call - used when cancelling a coro, mainly */
2639static void 2607static void
2640slf_destroy (pTHX_ struct coro *coro) 2608slf_destroy (pTHX_ struct coro *coro)
2641{ 2609{
2642 /* this callback is reserved for slf functions needing to do cleanup */ 2610 struct CoroSLF frame = coro->slf_frame;
2643 if (coro->slf_frame.destroy && coro->slf_frame.prepare && !PL_dirty)
2644 coro->slf_frame.destroy (aTHX_ &coro->slf_frame);
2645 2611
2646 /* 2612 /*
2647 * The on_destroy above most likely is from an SLF call. 2613 * The on_destroy below most likely is from an SLF call.
2648 * Since by definition the SLF call will not finish when we destroy 2614 * Since by definition the SLF call will not finish when we destroy
2649 * the coro, we will have to force-finish it here, otherwise 2615 * the coro, we will have to force-finish it here, otherwise
2650 * cleanup functions cannot call SLF functions. 2616 * cleanup functions cannot call SLF functions.
2651 */ 2617 */
2652 coro->slf_frame.prepare = 0; 2618 coro->slf_frame.prepare = 0;
2619
2620 /* this callback is reserved for slf functions needing to do cleanup */
2621 if (frame.destroy && frame.prepare && !PL_dirty)
2622 frame.destroy (aTHX_ &frame);
2653} 2623}
2654 2624
2655/* 2625/*
2656 * these not obviously related functions are all rolled into one 2626 * these not obviously related functions are all rolled into one
2657 * function to increase chances that they all will call transfer with the same 2627 * function to increase chances that they all will call transfer with the same
2997{ 2967{
2998 AV *av = (AV *)frame->data; 2968 AV *av = (AV *)frame->data;
2999 SV *count_sv = AvARRAY (av)[0]; 2969 SV *count_sv = AvARRAY (av)[0];
3000 SV *coro_hv = SvRV (coro_current); 2970 SV *coro_hv = SvRV (coro_current);
3001 2971
2972 frame->destroy = 0;
2973
3002 /* if we are about to throw, don't actually acquire the lock, just throw */ 2974 /* if we are about to throw, don't actually acquire the lock, just throw */
3003 if (CORO_THROW) 2975 if (ecb_expect_false (CORO_THROW))
2976 {
2977 /* we still might be responsible for the semaphore, so wake up others */
2978 coro_semaphore_adjust (aTHX_ av, 0);
2979
3004 return 0; 2980 return 0;
2981 }
3005 else if (SvIVX (count_sv) > 0) 2982 else if (SvIVX (count_sv) > 0)
3006 { 2983 {
3007 frame->destroy = 0;
3008
3009 if (acquire) 2984 if (acquire)
3010 SvIVX (count_sv) = SvIVX (count_sv) - 1; 2985 SvIVX (count_sv) = SvIVX (count_sv) - 1;
3011 else 2986 else
3012 coro_semaphore_adjust (aTHX_ av, 0); 2987 coro_semaphore_adjust (aTHX_ av, 0);
3013 2988
3235 /* it quickly returns */ 3210 /* it quickly returns */
3236 if (CORO_THROW) 3211 if (CORO_THROW)
3237 return 0; 3212 return 0;
3238 3213
3239 /* one element that is an RV? repeat! */ 3214 /* one element that is an RV? repeat! */
3240 if (AvFILLp (state) == 0 && SvROK (AvARRAY (state)[0])) 3215 if (AvFILLp (state) == 0 && SvTYPE (AvARRAY (state)[0]) != SVt_PV)
3241 return 1; 3216 return 1;
3242 3217
3243 /* restore status */ 3218 /* restore status */
3244 { 3219 {
3245 SV *data_sv = av_pop (state); 3220 SV *data_sv = av_pop (state);
3473 3448
3474PROTOTYPES: DISABLE 3449PROTOTYPES: DISABLE
3475 3450
3476BOOT: 3451BOOT:
3477{ 3452{
3453#define VARx(name,expr,type) if (sizeof (type) < sizeof (expr)) croak ("FATAL: Coro thread context slot '" # name "' too small for this version of perl.");
3454#include "state.h"
3478#ifdef USE_ITHREADS 3455#ifdef USE_ITHREADS
3479# if CORO_PTHREAD 3456# if CORO_PTHREAD
3480 coro_thx = PERL_GET_CONTEXT; 3457 coro_thx = PERL_GET_CONTEXT;
3481# endif 3458# endif
3482#endif 3459#endif
3483 BOOT_PAGESIZE;
3484
3485 /* perl defines these to check for existance first, but why it doesn't */ 3460 /* perl defines these to check for existance first, but why it doesn't */
3486 /* just create them one at init time is not clear to me, except for */ 3461 /* just create them one at init time is not clear to me, except for */
3487 /* programs trying to delete them, but... */ 3462 /* programs trying to delete them, but... */
3488 /* anyway, we declare this as invalid and make sure they are initialised here */ 3463 /* anyway, we declare this as invalid and make sure they are initialised here */
3489 DEFSV; 3464 DEFSV;
3559void 3534void
3560transfer (...) 3535transfer (...)
3561 PROTOTYPE: $$ 3536 PROTOTYPE: $$
3562 CODE: 3537 CODE:
3563 CORO_EXECUTE_SLF_XS (slf_init_transfer); 3538 CORO_EXECUTE_SLF_XS (slf_init_transfer);
3564
3565void
3566_exit (int code)
3567 PROTOTYPE: $
3568 CODE:
3569 _exit (code);
3570 3539
3571SV * 3540SV *
3572clone (Coro::State coro) 3541clone (Coro::State coro)
3573 CODE: 3542 CODE:
3574{ 3543{
4326 { 4295 {
4327 PL_ppaddr [OP_SSELECT] = coro_old_pp_sselect; 4296 PL_ppaddr [OP_SSELECT] = coro_old_pp_sselect;
4328 coro_old_pp_sselect = 0; 4297 coro_old_pp_sselect = 0;
4329 } 4298 }
4330 4299
4300MODULE = Coro::State PACKAGE = Coro::Util
4301
4302void
4303_exit (int code)
4304 CODE:
4305 _exit (code);
4306
4307NV
4308time ()
4309 CODE:
4310 RETVAL = nvtime (aTHX);
4311 OUTPUT:
4312 RETVAL
4313
4314NV
4315gettimeofday ()
4316 PPCODE:
4317{
4318 UV tv [2];
4319 u2time (aTHX_ tv);
4320 EXTEND (SP, 2);
4321 PUSHs (sv_2mortal (newSVuv (tv [0])));
4322 PUSHs (sv_2mortal (newSVuv (tv [1])));
4323}
4324

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines