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.258 by root, Sun Nov 9 23:08:49 2008 UTC vs.
Revision 1.263 by root, Wed Nov 12 04:49:06 2008 UTC

46# define BOOT_PAGESIZE (void)0 46# define BOOT_PAGESIZE (void)0
47#endif 47#endif
48 48
49#if CORO_USE_VALGRIND 49#if CORO_USE_VALGRIND
50# include <valgrind/valgrind.h> 50# include <valgrind/valgrind.h>
51# define REGISTER_STACK(cctx,start,end) (cctx)->valgrind_id = VALGRIND_STACK_REGISTER ((start), (end))
52#else
53# define REGISTER_STACK(cctx,start,end)
54#endif 51#endif
55 52
56/* the maximum number of idle cctx that will be pooled */ 53/* the maximum number of idle cctx that will be pooled */
57static int cctx_max_idle = 4; 54static int cctx_max_idle = 4;
58 55
128 125
129#if __GNUC__ >= 3 126#if __GNUC__ >= 3
130# define attribute(x) __attribute__(x) 127# define attribute(x) __attribute__(x)
131# define BARRIER __asm__ __volatile__ ("" : : : "memory") 128# define BARRIER __asm__ __volatile__ ("" : : : "memory")
132# define expect(expr,value) __builtin_expect ((expr),(value)) 129# define expect(expr,value) __builtin_expect ((expr),(value))
130# define INLINE static inline
133#else 131#else
134# define attribute(x) 132# define attribute(x)
135# define BARRIER 133# define BARRIER
136# define expect(expr,value) (expr) 134# define expect(expr,value) (expr)
135# define INLINE static
137#endif 136#endif
138 137
139#define expect_false(expr) expect ((expr) != 0, 0) 138#define expect_false(expr) expect ((expr) != 0, 0)
140#define expect_true(expr) expect ((expr) != 0, 1) 139#define expect_true(expr) expect ((expr) != 0, 1)
141 140
181static struct CoroAPI coroapi; 180static struct CoroAPI coroapi;
182static AV *main_mainstack; /* used to differentiate between $main and others */ 181static AV *main_mainstack; /* used to differentiate between $main and others */
183static JMPENV *main_top_env; 182static JMPENV *main_top_env;
184static HV *coro_state_stash, *coro_stash; 183static HV *coro_state_stash, *coro_stash;
185static volatile SV *coro_mortal; /* will be freed/thrown after next transfer */ 184static volatile SV *coro_mortal; /* will be freed/thrown after next transfer */
185static volatile struct coro *transfer_next;
186
187struct transfer_args
188{
189 struct coro *prev, *next;
190};
186 191
187static GV *irsgv; /* $/ */ 192static GV *irsgv; /* $/ */
188static GV *stdoutgv; /* *STDOUT */ 193static GV *stdoutgv; /* *STDOUT */
189static SV *rv_diehook; 194static SV *rv_diehook;
190static SV *rv_warnhook; 195static SV *rv_warnhook;
407 : 0 412 : 0
408 413
409#define CORO_MAGIC_cv(cv) CORO_MAGIC (((SV *)(cv)), CORO_MAGIC_type_cv) 414#define CORO_MAGIC_cv(cv) CORO_MAGIC (((SV *)(cv)), CORO_MAGIC_type_cv)
410#define CORO_MAGIC_state(sv) CORO_MAGIC (((SV *)(sv)), CORO_MAGIC_type_state) 415#define CORO_MAGIC_state(sv) CORO_MAGIC (((SV *)(sv)), CORO_MAGIC_type_state)
411 416
412static struct coro * 417INLINE struct coro *
413SvSTATE_ (pTHX_ SV *coro) 418SvSTATE_ (pTHX_ SV *coro)
414{ 419{
415 HV *stash; 420 HV *stash;
416 MAGIC *mg; 421 MAGIC *mg;
417 422
721#define MgPV_nolen_const(mg) (((((int)(mg)->mg_len)) == HEf_SVKEY) ? \ 726#define MgPV_nolen_const(mg) (((((int)(mg)->mg_len)) == HEf_SVKEY) ? \
722 SvPV_nolen((SV*)((mg)->mg_ptr)) : \ 727 SvPV_nolen((SV*)((mg)->mg_ptr)) : \
723 (const char*)(mg)->mg_ptr) 728 (const char*)(mg)->mg_ptr)
724#endif 729#endif
725 730
731/* we sometimes need to create the effect of entersub calling us */
732#define ENTERSUB_HEAD ENTER; SAVETMPS
733/* we somtimes need to create the effect of leaving via entersub */
734#define ENTERSUB_TAIL LEAVE
735
726/* 736/*
727 * This overrides the default magic get method of %SIG elements. 737 * This overrides the default magic get method of %SIG elements.
728 * The original one doesn't provide for reading back of PL_diehook/PL_warnhook 738 * The original one doesn't provide for reading back of PL_diehook/PL_warnhook
729 * and instead of tryign to save and restore the hash elements, we just provide 739 * and instead of tryign to save and restore the hash elements, we just provide
730 * readback here. 740 * readback here.
834 PL_rs = newSVsv (GvSV (irsgv)); 844 PL_rs = newSVsv (GvSV (irsgv));
835 PL_defoutgv = (GV *)SvREFCNT_inc_NN (stdoutgv); 845 PL_defoutgv = (GV *)SvREFCNT_inc_NN (stdoutgv);
836 846
837 { 847 {
838 dSP; 848 dSP;
839 LOGOP myop; 849 UNOP myop;
840 850
841 Zero (&myop, 1, LOGOP); 851 Zero (&myop, 1, UNOP);
842 myop.op_next = Nullop; 852 myop.op_next = Nullop;
843 myop.op_flags = OPf_WANT_VOID; 853 myop.op_flags = OPf_WANT_VOID;
844 854
845 PUSHMARK (SP); 855 PUSHMARK (SP);
846 XPUSHs (sv_2mortal (av_shift (GvAV (PL_defgv)))); 856 XPUSHs (sv_2mortal (av_shift (GvAV (PL_defgv))));
850 SPAGAIN; 860 SPAGAIN;
851 } 861 }
852 862
853 /* this newly created coroutine might be run on an existing cctx which most 863 /* this newly created coroutine might be run on an existing cctx which most
854 * likely was suspended in set_stacklevel, called from entersub. 864 * likely was suspended in set_stacklevel, called from entersub.
855 * set_stacklevl doesn't do anything on return, but entersub does LEAVE, 865 * set_stacklevel doesn't do anything on return, but entersub does LEAVE,
856 * so we ENTER here for symmetry 866 * so we ENTER here for symmetry.
857 */ 867 */
858 ENTER; 868 ENTERSUB_HEAD;
859} 869}
860 870
861static void 871static void
862coro_destruct (pTHX_ struct coro *coro) 872coro_destruct (pTHX_ struct coro *coro)
863{ 873{
892 SvREFCNT_dec (coro->throw); 902 SvREFCNT_dec (coro->throw);
893 903
894 coro_destruct_stacks (aTHX); 904 coro_destruct_stacks (aTHX);
895} 905}
896 906
897static void 907INLINE void
898free_coro_mortal (pTHX) 908free_coro_mortal (pTHX)
899{ 909{
900 if (expect_true (coro_mortal)) 910 if (expect_true (coro_mortal))
901 { 911 {
902 SvREFCNT_dec (coro_mortal); 912 SvREFCNT_dec (coro_mortal);
1026 1036
1027 TAINT_NOT; 1037 TAINT_NOT;
1028 return 0; 1038 return 0;
1029} 1039}
1030 1040
1041static void
1042prepare_set_stacklevel (struct transfer_args *ta, struct coro_cctx *cctx)
1043{
1044 ta->prev = (struct coro *)cctx;
1045 ta->next = 0;
1046}
1047
1031/* inject a fake call to Coro::State::_cctx_init into the execution */ 1048/* inject a fake call to Coro::State::_cctx_init into the execution */
1032/* _cctx_init should be careful, as it could be called at almost any time */ 1049/* _cctx_init should be careful, as it could be called at almost any time */
1033/* during execution of a perl program */ 1050/* during execution of a perl program */
1051/* also initialises PL_top_env */
1034static void NOINLINE 1052static void NOINLINE
1035cctx_prepare (pTHX_ coro_cctx *cctx) 1053cctx_prepare (pTHX_ coro_cctx *cctx)
1036{ 1054{
1037 dSP; 1055 dSP;
1038 LOGOP myop; 1056 UNOP myop;
1039 1057
1040 PL_top_env = &PL_start_env; 1058 PL_top_env = &PL_start_env;
1041 1059
1042 if (cctx->flags & CC_TRACE) 1060 if (cctx->flags & CC_TRACE)
1043 PL_runops = runops_trace; 1061 PL_runops = runops_trace;
1044 1062
1045 Zero (&myop, 1, LOGOP); 1063 Zero (&myop, 1, UNOP);
1046 myop.op_next = PL_op; 1064 myop.op_next = PL_op;
1047 myop.op_flags = OPf_WANT_VOID | OPf_STACKED; 1065 myop.op_flags = OPf_WANT_VOID | OPf_STACKED;
1048 1066
1049 PUSHMARK (SP); 1067 PUSHMARK (SP);
1050 EXTEND (SP, 2); 1068 EXTEND (SP, 2);
1051 PUSHs (sv_2mortal (newSViv (PTR2IV (cctx)))); 1069 PUSHs (sv_2mortal (newSViv ((IV)cctx)));
1052 PUSHs ((SV *)get_cv ("Coro::State::_cctx_init", FALSE)); 1070 PUSHs ((SV *)get_cv ("Coro::State::_cctx_init", FALSE));
1053 PUTBACK; 1071 PUTBACK;
1054 PL_op = (OP *)&myop; 1072 PL_op = (OP *)&myop;
1055 PL_op = PL_ppaddr[OP_ENTERSUB](aTHX); 1073 PL_op = PL_ppaddr[OP_ENTERSUB](aTHX);
1056 SPAGAIN; 1074 SPAGAIN;
1057} 1075}
1058 1076
1077/* the tail of transfer: execute stuff we can only do after a transfer */
1078INLINE void
1079transfer_tail (pTHX)
1080{
1081 struct coro *next = (struct coro *)transfer_next;
1082 assert (!(transfer_next = 0)); /* just used for the side effect when asserts are enabled */
1083 assert (("FATAL: transfer_next was zero in transfer_tail (please report)", next));
1084
1085 free_coro_mortal (aTHX);
1086 UNLOCK;
1087
1088 if (expect_false (next->throw))
1089 {
1090 SV *exception = sv_2mortal (next->throw);
1091
1092 next->throw = 0;
1093 sv_setsv (ERRSV, exception);
1094 croak (0);
1095 }
1096}
1097
1059/* 1098/*
1060 * this is a _very_ stripped down perl interpreter ;) 1099 * this is a _very_ stripped down perl interpreter ;)
1061 */ 1100 */
1062static void 1101static void
1063cctx_run (void *arg) 1102cctx_run (void *arg)
1068# endif 1107# endif
1069#endif 1108#endif
1070 { 1109 {
1071 dTHX; 1110 dTHX;
1072 1111
1073 /* cctx_run is the alternative tail of transfer(), so unlock here. */ 1112 /* entersub called ENTER, but we never 'returned', undo that here */
1074 UNLOCK; 1113 ENTERSUB_TAIL;
1075 1114
1076 /* we now skip the entersub that lead to transfer() */ 1115 /* we now skip the entersub that did lead to transfer() */
1077 PL_op = PL_op->op_next; 1116 PL_op = PL_op->op_next;
1078 1117
1079 /* inject a fake subroutine call to cctx_init */ 1118 /* inject a fake subroutine call to cctx_init */
1080 cctx_prepare (aTHX_ (coro_cctx *)arg); 1119 cctx_prepare (aTHX_ (coro_cctx *)arg);
1120
1121 /* cctx_run is the alternative tail of transfer() */
1122 transfer_tail (aTHX);
1081 1123
1082 /* somebody or something will hit me for both perl_run and PL_restartop */ 1124 /* somebody or something will hit me for both perl_run and PL_restartop */
1083 PL_restartop = PL_op; 1125 PL_restartop = PL_op;
1084 perl_run (PL_curinterp); 1126 perl_run (PL_curinterp);
1085 1127
1101 coro_cctx *cctx; 1143 coro_cctx *cctx;
1102 1144
1103 ++cctx_count; 1145 ++cctx_count;
1104 New (0, cctx, 1, coro_cctx); 1146 New (0, cctx, 1, coro_cctx);
1105 1147
1106 cctx->gen = cctx_gen; 1148 cctx->gen = cctx_gen;
1107 cctx->flags = 0; 1149 cctx->flags = 0;
1150 cctx->idle_sp = 0; /* can be accessed by transfer between cctx_run and set_stacklevel, on throw */
1108 1151
1109 return cctx; 1152 return cctx;
1110} 1153}
1111 1154
1112/* create a new cctx only suitable as source */ 1155/* create a new cctx only suitable as source */
1113static coro_cctx * 1156static coro_cctx *
1114cctx_new_empty () 1157cctx_new_empty ()
1115{ 1158{
1116 coro_cctx *cctx = cctx_new (); 1159 coro_cctx *cctx = cctx_new ();
1117 1160
1118 cctx->sptr = 0; 1161 cctx->sptr = 0;
1119 cctx->idle_sp = 0; /* should never be a valid address */
1120 coro_create (&cctx->cctx, 0, 0, 0, 0); 1162 coro_create (&cctx->cctx, 0, 0, 0, 0);
1121 1163
1122 return cctx; 1164 return cctx;
1123} 1165}
1124 1166
1135 /* mmap supposedly does allocate-on-write for us */ 1177 /* mmap supposedly does allocate-on-write for us */
1136 cctx->sptr = mmap (0, cctx->ssize, PROT_EXEC|PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, 0, 0); 1178 cctx->sptr = mmap (0, cctx->ssize, PROT_EXEC|PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, 0, 0);
1137 1179
1138 if (cctx->sptr != (void *)-1) 1180 if (cctx->sptr != (void *)-1)
1139 { 1181 {
1140# if CORO_STACKGUARD 1182 #if CORO_STACKGUARD
1141 mprotect (cctx->sptr, CORO_STACKGUARD * PAGESIZE, PROT_NONE); 1183 mprotect (cctx->sptr, CORO_STACKGUARD * PAGESIZE, PROT_NONE);
1142# endif 1184 #endif
1143 stack_start = CORO_STACKGUARD * PAGESIZE + (char *)cctx->sptr; 1185 stack_start = (char *)cctx->sptr + CORO_STACKGUARD * PAGESIZE;
1144 stack_size = cctx->ssize - CORO_STACKGUARD * PAGESIZE; 1186 stack_size = cctx->ssize - CORO_STACKGUARD * PAGESIZE;
1145 cctx->flags |= CC_MAPPED; 1187 cctx->flags |= CC_MAPPED;
1146 } 1188 }
1147 else 1189 else
1148#endif 1190#endif
1149 { 1191 {
1158 1200
1159 stack_start = cctx->sptr; 1201 stack_start = cctx->sptr;
1160 stack_size = cctx->ssize; 1202 stack_size = cctx->ssize;
1161 } 1203 }
1162 1204
1163 REGISTER_STACK (cctx, (char *)stack_start, (char *)stack_start + stack_size); 1205 #if CORO_USE_VALGRIND
1206 cctx->valgrind_id = VALGRIND_STACK_REGISTER ((char *)stack_start, (char *)stack_start + stack_size);
1207 #endif
1208
1164 coro_create (&cctx->cctx, cctx_run, (void *)cctx, stack_start, stack_size); 1209 coro_create (&cctx->cctx, cctx_run, (void *)cctx, stack_start, stack_size);
1165 1210
1166 return cctx; 1211 return cctx;
1167} 1212}
1168 1213
1176 coro_destroy (&cctx->cctx); 1221 coro_destroy (&cctx->cctx);
1177 1222
1178 /* coro_transfer creates new, empty cctx's */ 1223 /* coro_transfer creates new, empty cctx's */
1179 if (cctx->sptr) 1224 if (cctx->sptr)
1180 { 1225 {
1181#if CORO_USE_VALGRIND 1226 #if CORO_USE_VALGRIND
1182 VALGRIND_STACK_DEREGISTER (cctx->valgrind_id); 1227 VALGRIND_STACK_DEREGISTER (cctx->valgrind_id);
1183#endif 1228 #endif
1184 1229
1185#if HAVE_MMAP 1230#if HAVE_MMAP
1186 if (cctx->flags & CC_MAPPED) 1231 if (cctx->flags & CC_MAPPED)
1187 munmap (cctx->sptr, cctx->ssize); 1232 munmap (cctx->sptr, cctx->ssize);
1188 else 1233 else
1215} 1260}
1216 1261
1217static void 1262static void
1218cctx_put (coro_cctx *cctx) 1263cctx_put (coro_cctx *cctx)
1219{ 1264{
1220 assert (("cctx_put called on non-initialised cctx", cctx->sptr)); 1265 assert (("FATAL: cctx_put called on non-initialised cctx in Coro (please report)", cctx->sptr));
1221 1266
1222 /* free another cctx if overlimit */ 1267 /* free another cctx if overlimit */
1223 if (expect_false (cctx_idle >= cctx_max_idle)) 1268 if (expect_false (cctx_idle >= cctx_max_idle))
1224 { 1269 {
1225 coro_cctx *first = cctx_first; 1270 coro_cctx *first = cctx_first;
1269 ((coro_cctx *)prev)->idle_sp = STACKLEVEL; 1314 ((coro_cctx *)prev)->idle_sp = STACKLEVEL;
1270 assert (((coro_cctx *)prev)->idle_te = PL_top_env); /* just for the side-effect when asserts are enabled */ 1315 assert (((coro_cctx *)prev)->idle_te = PL_top_env); /* just for the side-effect when asserts are enabled */
1271 } 1316 }
1272 else if (expect_true (prev != next)) 1317 else if (expect_true (prev != next))
1273 { 1318 {
1274 static volatile int has_throw;
1275 coro_cctx *prev__cctx; 1319 coro_cctx *prev__cctx;
1276 1320
1277 if (expect_false (prev->flags & CF_NEW)) 1321 if (expect_false (prev->flags & CF_NEW))
1278 { 1322 {
1279 /* create a new empty/source context */ 1323 /* create a new empty/source context */
1300 else 1344 else
1301 load_perl (aTHX_ next); 1345 load_perl (aTHX_ next);
1302 1346
1303 prev__cctx = prev->cctx; 1347 prev__cctx = prev->cctx;
1304 1348
1305 /* possibly "free" the cctx */ 1349 /* possibly untie and reuse the cctx */
1306 if (expect_true ( 1350 if (expect_true (
1307 prev__cctx->idle_sp == STACKLEVEL 1351 prev__cctx->idle_sp == STACKLEVEL
1308 && !(prev__cctx->flags & CC_TRACE) 1352 && !(prev__cctx->flags & CC_TRACE)
1309 && !force_cctx 1353 && !force_cctx
1310 )) 1354 ))
1311 { 1355 {
1312 /* I assume that STACKLEVEL is a stronger indicator than PL_top_env changes */ 1356 /* I assume that STACKLEVEL is a stronger indicator than PL_top_env changes */
1313 assert (("ERROR: current top_env must equal previous top_env", PL_top_env == prev__cctx->idle_te)); 1357 assert (("FATAL: current top_env must equal previous top_env in Coro (please report)", PL_top_env == prev__cctx->idle_te));
1314 1358
1315 prev->cctx = 0; 1359 prev->cctx = 0;
1316 1360
1317 /* if the cctx is about to be destroyed we need to make sure we won't see it in cctx_get */ 1361 /* if the cctx is about to be destroyed we need to make sure we won't see it in cctx_get */
1318 /* without this the next cctx_get might destroy the prev__cctx while still in use */ 1362 /* without this the next cctx_get might destroy the prev__cctx while still in use */
1326 ++next->usecount; 1370 ++next->usecount;
1327 1371
1328 if (expect_true (!next->cctx)) 1372 if (expect_true (!next->cctx))
1329 next->cctx = cctx_get (aTHX); 1373 next->cctx = cctx_get (aTHX);
1330 1374
1331 has_throw = !!next->throw; 1375 assert (("FATAL: transfer_next already nonzero in Coro (please report)", !transfer_next));
1376 transfer_next = next;
1332 1377
1333 if (expect_false (prev__cctx != next->cctx)) 1378 if (expect_false (prev__cctx != next->cctx))
1334 { 1379 {
1335 prev__cctx->top_env = PL_top_env; 1380 prev__cctx->top_env = PL_top_env;
1336 PL_top_env = next->cctx->top_env; 1381 PL_top_env = next->cctx->top_env;
1337 coro_transfer (&prev__cctx->cctx, &next->cctx->cctx); 1382 coro_transfer (&prev__cctx->cctx, &next->cctx->cctx);
1338 } 1383 }
1339 1384
1340 free_coro_mortal (aTHX); 1385 transfer_tail (aTHX);
1341 UNLOCK;
1342
1343 if (expect_false (has_throw))
1344 {
1345 struct coro *coro = SvSTATE (coro_current);
1346
1347 if (coro->throw)
1348 {
1349 SV *exception = coro->throw;
1350 coro->throw = 0;
1351 sv_setsv (ERRSV, exception);
1352 croak (0);
1353 }
1354 }
1355 } 1386 }
1356} 1387}
1357
1358struct transfer_args
1359{
1360 struct coro *prev, *next;
1361};
1362 1388
1363#define TRANSFER(ta, force_cctx) transfer (aTHX_ (ta).prev, (ta).next, (force_cctx)) 1389#define TRANSFER(ta, force_cctx) transfer (aTHX_ (ta).prev, (ta).next, (force_cctx))
1364#define TRANSFER_CHECK(ta) transfer_check (aTHX_ (ta).prev, (ta).next) 1390#define TRANSFER_CHECK(ta) transfer_check (aTHX_ (ta).prev, (ta).next)
1365 1391
1366/** high level stuff ********************************************************/ 1392/** high level stuff ********************************************************/
1539 1565
1540static int 1566static int
1541api_is_ready (SV *coro_sv) 1567api_is_ready (SV *coro_sv)
1542{ 1568{
1543 dTHX; 1569 dTHX;
1570
1544 return !!(SvSTATE (coro_sv)->flags & CF_READY); 1571 return !!(SvSTATE (coro_sv)->flags & CF_READY);
1545} 1572}
1546 1573
1547static void 1574INLINE void
1548prepare_schedule (pTHX_ struct transfer_args *ta) 1575prepare_schedule (pTHX_ struct transfer_args *ta)
1549{ 1576{
1550 SV *prev_sv, *next_sv; 1577 SV *prev_sv, *next_sv;
1551 1578
1552 for (;;) 1579 for (;;)
1578 /* cannot transfer to destroyed coros, skip and look for next */ 1605 /* cannot transfer to destroyed coros, skip and look for next */
1579 if (expect_false (ta->next->flags & CF_DESTROYED)) 1606 if (expect_false (ta->next->flags & CF_DESTROYED))
1580 { 1607 {
1581 UNLOCK; 1608 UNLOCK;
1582 SvREFCNT_dec (next_sv); 1609 SvREFCNT_dec (next_sv);
1583 /* coro_nready is already taken care of by destroy */ 1610 /* coro_nready has already been taken care of by destroy */
1584 continue; 1611 continue;
1585 } 1612 }
1586 1613
1587 --coro_nready; 1614 --coro_nready;
1588 UNLOCK; 1615 UNLOCK;
1591 1618
1592 /* free this only after the transfer */ 1619 /* free this only after the transfer */
1593 prev_sv = SvRV (coro_current); 1620 prev_sv = SvRV (coro_current);
1594 ta->prev = SvSTATE (prev_sv); 1621 ta->prev = SvSTATE (prev_sv);
1595 TRANSFER_CHECK (*ta); 1622 TRANSFER_CHECK (*ta);
1596 assert (ta->next->flags & CF_READY); 1623 assert (("FATAL: next coroutine isn't marked as ready in Coro (please report)", ta->next->flags & CF_READY));
1597 ta->next->flags &= ~CF_READY; 1624 ta->next->flags &= ~CF_READY;
1598 SvRV_set (coro_current, next_sv); 1625 SvRV_set (coro_current, next_sv);
1599 1626
1600 LOCK; 1627 LOCK;
1601 free_coro_mortal (aTHX); 1628 free_coro_mortal (aTHX);
1602 coro_mortal = prev_sv; 1629 coro_mortal = prev_sv;
1603 UNLOCK; 1630 UNLOCK;
1604} 1631}
1605 1632
1606static void 1633INLINE void
1607prepare_cede (pTHX_ struct transfer_args *ta) 1634prepare_cede (pTHX_ struct transfer_args *ta)
1608{ 1635{
1609 api_ready (coro_current); 1636 api_ready (coro_current);
1610 prepare_schedule (aTHX_ ta); 1637 prepare_schedule (aTHX_ ta);
1611} 1638}
1885 1912
1886 PUTBACK; 1913 PUTBACK;
1887 switch (ix) 1914 switch (ix)
1888 { 1915 {
1889 case 0: 1916 case 0:
1890 ta.prev = (struct coro *)INT2PTR (coro_cctx *, SvIV (ST (0))); 1917 prepare_set_stacklevel (&ta, (struct coro_cctx *)SvIV (ST (0)));
1891 ta.next = 0;
1892 break; 1918 break;
1893 1919
1894 case 1: 1920 case 1:
1895 if (items != 2) 1921 if (items != 2)
1896 croak ("Coro::State::transfer (prev, next) expects two arguments, not %d", items); 1922 croak ("Coro::State::transfer (prev, next) expects two arguments, not %d", items);
2035 is_destroyed = CF_DESTROYED 2061 is_destroyed = CF_DESTROYED
2036 CODE: 2062 CODE:
2037 RETVAL = boolSV (coro->flags & ix); 2063 RETVAL = boolSV (coro->flags & ix);
2038 OUTPUT: 2064 OUTPUT:
2039 RETVAL 2065 RETVAL
2066
2067void
2068throw (Coro::State self, SV *throw = &PL_sv_undef)
2069 PROTOTYPE: $;$
2070 CODE:
2071 SvREFCNT_dec (self->throw);
2072 self->throw = SvOK (throw) ? newSVsv (throw) : 0;
2040 2073
2041void 2074void
2042api_trace (SV *coro, int flags = CC_TRACE | CC_TRACE_SUB) 2075api_trace (SV *coro, int flags = CC_TRACE | CC_TRACE_SUB)
2043 2076
2044SV * 2077SV *
2117 2150
2118 for (i = PRIO_MAX - PRIO_MIN + 1; i--; ) 2151 for (i = PRIO_MAX - PRIO_MIN + 1; i--; )
2119 coro_ready[i] = newAV (); 2152 coro_ready[i] = newAV ();
2120 2153
2121 { 2154 {
2122 SV *sv = perl_get_sv ("Coro::API", TRUE); 2155 SV *sv = coro_get_sv (aTHX_ "Coro::API", TRUE);
2123 perl_get_sv ("Coro::API", TRUE); /* silence 5.10 warning */
2124 2156
2125 coroapi.schedule = api_schedule; 2157 coroapi.schedule = api_schedule;
2126 coroapi.cede = api_cede; 2158 coroapi.cede = api_cede;
2127 coroapi.cede_notself = api_cede_notself; 2159 coroapi.cede_notself = api_cede_notself;
2128 coroapi.ready = api_ready; 2160 coroapi.ready = api_ready;
2188 CODE: 2220 CODE:
2189 RETVAL = coro_nready; 2221 RETVAL = coro_nready;
2190 OUTPUT: 2222 OUTPUT:
2191 RETVAL 2223 RETVAL
2192 2224
2193void
2194throw (Coro::State self, SV *throw = &PL_sv_undef)
2195 PROTOTYPE: $;$
2196 CODE:
2197 SvREFCNT_dec (self->throw);
2198 self->throw = SvOK (throw) ? newSVsv (throw) : 0;
2199
2200# for async_pool speedup 2225# for async_pool speedup
2201void 2226void
2202_pool_1 (SV *cb) 2227_pool_1 (SV *cb)
2203 CODE: 2228 CODE:
2204{ 2229{
2403 2428
2404MODULE = Coro::State PACKAGE = PerlIO::cede 2429MODULE = Coro::State PACKAGE = PerlIO::cede
2405 2430
2406BOOT: 2431BOOT:
2407 PerlIO_define_layer (aTHX_ &PerlIO_cede); 2432 PerlIO_define_layer (aTHX_ &PerlIO_cede);
2433

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines