… | |
… | |
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 */ |
57 | static int cctx_max_idle = 4; |
54 | static int cctx_max_idle = 4; |
58 | |
55 | |
… | |
… | |
126 | |
123 | |
127 | #define IN_DESTRUCT (PL_main_cv == Nullcv) |
124 | #define IN_DESTRUCT (PL_main_cv == Nullcv) |
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") |
|
|
132 | # define expect(expr,value) __builtin_expect ((expr),(value)) |
128 | # define expect(expr,value) __builtin_expect ((expr),(value)) |
|
|
129 | # define INLINE static inline |
133 | #else |
130 | #else |
134 | # define attribute(x) |
131 | # define attribute(x) |
135 | # define BARRIER |
|
|
136 | # define expect(expr,value) (expr) |
132 | # define expect(expr,value) (expr) |
|
|
133 | # define INLINE static |
137 | #endif |
134 | #endif |
138 | |
135 | |
139 | #define expect_false(expr) expect ((expr) != 0, 0) |
136 | #define expect_false(expr) expect ((expr) != 0, 0) |
140 | #define expect_true(expr) expect ((expr) != 0, 1) |
137 | #define expect_true(expr) expect ((expr) != 0, 1) |
141 | |
138 | |
… | |
… | |
181 | static struct CoroAPI coroapi; |
178 | static struct CoroAPI coroapi; |
182 | static AV *main_mainstack; /* used to differentiate between $main and others */ |
179 | static AV *main_mainstack; /* used to differentiate between $main and others */ |
183 | static JMPENV *main_top_env; |
180 | static JMPENV *main_top_env; |
184 | static HV *coro_state_stash, *coro_stash; |
181 | static HV *coro_state_stash, *coro_stash; |
185 | static volatile SV *coro_mortal; /* will be freed/thrown after next transfer */ |
182 | static volatile SV *coro_mortal; /* will be freed/thrown after next transfer */ |
186 | static volatile char next_has_throw; /* speedup flag for next->throw check */ |
183 | static volatile struct coro *transfer_next; |
|
|
184 | |
|
|
185 | struct transfer_args |
|
|
186 | { |
|
|
187 | struct coro *prev, *next; |
|
|
188 | }; |
187 | |
189 | |
188 | static GV *irsgv; /* $/ */ |
190 | static GV *irsgv; /* $/ */ |
189 | static GV *stdoutgv; /* *STDOUT */ |
191 | static GV *stdoutgv; /* *STDOUT */ |
190 | static SV *rv_diehook; |
192 | static SV *rv_diehook; |
191 | static SV *rv_warnhook; |
193 | static SV *rv_warnhook; |
… | |
… | |
408 | : 0 |
410 | : 0 |
409 | |
411 | |
410 | #define CORO_MAGIC_cv(cv) CORO_MAGIC (((SV *)(cv)), CORO_MAGIC_type_cv) |
412 | #define CORO_MAGIC_cv(cv) CORO_MAGIC (((SV *)(cv)), CORO_MAGIC_type_cv) |
411 | #define CORO_MAGIC_state(sv) CORO_MAGIC (((SV *)(sv)), CORO_MAGIC_type_state) |
413 | #define CORO_MAGIC_state(sv) CORO_MAGIC (((SV *)(sv)), CORO_MAGIC_type_state) |
412 | |
414 | |
413 | static struct coro * |
415 | INLINE struct coro * |
414 | SvSTATE_ (pTHX_ SV *coro) |
416 | SvSTATE_ (pTHX_ SV *coro) |
415 | { |
417 | { |
416 | HV *stash; |
418 | HV *stash; |
417 | MAGIC *mg; |
419 | MAGIC *mg; |
418 | |
420 | |
… | |
… | |
709 | } |
711 | } |
710 | |
712 | |
711 | return rss; |
713 | return rss; |
712 | } |
714 | } |
713 | |
715 | |
|
|
716 | /** set stacklevel support **************************************************/ |
|
|
717 | |
|
|
718 | /* we sometimes need to create the effect of pp_set_stacklevel calling us */ |
|
|
719 | #define SSL_HEAD (void)0 |
|
|
720 | /* we somtimes need to create the effect of leaving via pp_set_stacklevel */ |
|
|
721 | #define SSL_TAIL set_stacklevel_tail (aTHX) |
|
|
722 | |
|
|
723 | INLINE void |
|
|
724 | set_stacklevel_tail (pTHX) |
|
|
725 | { |
|
|
726 | dSP; |
|
|
727 | int gimme = GIMME_V; |
|
|
728 | |
|
|
729 | if (gimme == G_SCALAR) |
|
|
730 | XPUSHs (&PL_sv_undef); |
|
|
731 | |
|
|
732 | PUTBACK; |
|
|
733 | } |
|
|
734 | |
714 | /** coroutine stack handling ************************************************/ |
735 | /** coroutine stack handling ************************************************/ |
715 | |
736 | |
716 | static int (*orig_sigelem_get) (pTHX_ SV *sv, MAGIC *mg); |
737 | static int (*orig_sigelem_get) (pTHX_ SV *sv, MAGIC *mg); |
717 | static int (*orig_sigelem_set) (pTHX_ SV *sv, MAGIC *mg); |
738 | static int (*orig_sigelem_set) (pTHX_ SV *sv, MAGIC *mg); |
718 | static int (*orig_sigelem_clr) (pTHX_ SV *sv, MAGIC *mg); |
739 | static int (*orig_sigelem_clr) (pTHX_ SV *sv, MAGIC *mg); |
… | |
… | |
835 | PL_rs = newSVsv (GvSV (irsgv)); |
856 | PL_rs = newSVsv (GvSV (irsgv)); |
836 | PL_defoutgv = (GV *)SvREFCNT_inc_NN (stdoutgv); |
857 | PL_defoutgv = (GV *)SvREFCNT_inc_NN (stdoutgv); |
837 | |
858 | |
838 | { |
859 | { |
839 | dSP; |
860 | dSP; |
840 | LOGOP myop; |
861 | UNOP myop; |
841 | |
862 | |
842 | Zero (&myop, 1, LOGOP); |
863 | Zero (&myop, 1, UNOP); |
843 | myop.op_next = Nullop; |
864 | myop.op_next = Nullop; |
844 | myop.op_flags = OPf_WANT_VOID; |
865 | myop.op_flags = OPf_WANT_VOID; |
845 | |
866 | |
846 | PUSHMARK (SP); |
867 | PUSHMARK (SP); |
847 | XPUSHs (sv_2mortal (av_shift (GvAV (PL_defgv)))); |
868 | XPUSHs (sv_2mortal (av_shift (GvAV (PL_defgv)))); |
… | |
… | |
850 | PL_op = PL_ppaddr[OP_ENTERSUB](aTHX); |
871 | PL_op = PL_ppaddr[OP_ENTERSUB](aTHX); |
851 | SPAGAIN; |
872 | SPAGAIN; |
852 | } |
873 | } |
853 | |
874 | |
854 | /* this newly created coroutine might be run on an existing cctx which most |
875 | /* this newly created coroutine might be run on an existing cctx which most |
855 | * likely was suspended in set_stacklevel, called from entersub. |
876 | * likely was suspended in set_stacklevel, called from pp_set_stacklevel, |
856 | * set_stacklevl doesn't do anything on return, but entersub does LEAVE, |
877 | * so we have to emulate entering pp_set_stacklevel here. |
857 | * so we ENTER here for symmetry |
|
|
858 | */ |
878 | */ |
859 | ENTER; |
879 | SSL_HEAD; |
860 | } |
880 | } |
861 | |
881 | |
862 | static void |
882 | static void |
863 | coro_destruct (pTHX_ struct coro *coro) |
883 | coro_destruct (pTHX_ struct coro *coro) |
864 | { |
884 | { |
… | |
… | |
893 | SvREFCNT_dec (coro->throw); |
913 | SvREFCNT_dec (coro->throw); |
894 | |
914 | |
895 | coro_destruct_stacks (aTHX); |
915 | coro_destruct_stacks (aTHX); |
896 | } |
916 | } |
897 | |
917 | |
898 | static void |
918 | INLINE void |
899 | free_coro_mortal (pTHX) |
919 | free_coro_mortal (pTHX) |
900 | { |
920 | { |
901 | if (expect_true (coro_mortal)) |
921 | if (expect_true (coro_mortal)) |
902 | { |
922 | { |
903 | SvREFCNT_dec (coro_mortal); |
923 | SvREFCNT_dec (coro_mortal); |
… | |
… | |
1027 | |
1047 | |
1028 | TAINT_NOT; |
1048 | TAINT_NOT; |
1029 | return 0; |
1049 | return 0; |
1030 | } |
1050 | } |
1031 | |
1051 | |
|
|
1052 | static void |
|
|
1053 | prepare_set_stacklevel (struct transfer_args *ta, struct coro_cctx *cctx) |
|
|
1054 | { |
|
|
1055 | ta->prev = (struct coro *)cctx; |
|
|
1056 | ta->next = 0; |
|
|
1057 | } |
|
|
1058 | |
1032 | /* inject a fake call to Coro::State::_cctx_init into the execution */ |
1059 | /* inject a fake call to Coro::State::_cctx_init into the execution */ |
1033 | /* _cctx_init should be careful, as it could be called at almost any time */ |
1060 | /* _cctx_init should be careful, as it could be called at almost any time */ |
1034 | /* during execution of a perl program */ |
1061 | /* during execution of a perl program */ |
1035 | /* also initialises PL_top_env */ |
1062 | /* also initialises PL_top_env */ |
1036 | static void NOINLINE |
1063 | static void NOINLINE |
1037 | cctx_prepare (pTHX_ coro_cctx *cctx) |
1064 | cctx_prepare (pTHX_ coro_cctx *cctx) |
1038 | { |
1065 | { |
1039 | dSP; |
1066 | dSP; |
1040 | LOGOP myop; |
1067 | UNOP myop; |
1041 | |
1068 | |
1042 | PL_top_env = &PL_start_env; |
1069 | PL_top_env = &PL_start_env; |
1043 | |
1070 | |
1044 | if (cctx->flags & CC_TRACE) |
1071 | if (cctx->flags & CC_TRACE) |
1045 | PL_runops = runops_trace; |
1072 | PL_runops = runops_trace; |
1046 | |
1073 | |
1047 | Zero (&myop, 1, LOGOP); |
1074 | Zero (&myop, 1, UNOP); |
1048 | myop.op_next = PL_op; |
1075 | myop.op_next = PL_op; |
1049 | myop.op_flags = OPf_WANT_VOID | OPf_STACKED; |
1076 | myop.op_flags = OPf_WANT_VOID | OPf_STACKED; |
1050 | |
1077 | |
1051 | PUSHMARK (SP); |
1078 | PUSHMARK (SP); |
1052 | EXTEND (SP, 2); |
1079 | EXTEND (SP, 2); |
1053 | PUSHs (sv_2mortal (newSViv (PTR2IV (cctx)))); |
1080 | PUSHs (sv_2mortal (newSViv ((IV)cctx))); |
1054 | PUSHs ((SV *)get_cv ("Coro::State::_cctx_init", FALSE)); |
1081 | PUSHs ((SV *)get_cv ("Coro::State::_cctx_init", FALSE)); |
1055 | PUTBACK; |
1082 | PUTBACK; |
1056 | PL_op = (OP *)&myop; |
1083 | PL_op = (OP *)&myop; |
1057 | PL_op = PL_ppaddr[OP_ENTERSUB](aTHX); |
1084 | PL_op = PL_ppaddr[OP_ENTERSUB](aTHX); |
1058 | SPAGAIN; |
1085 | SPAGAIN; |
1059 | } |
1086 | } |
1060 | |
1087 | |
1061 | /* the tail of transfer: execute stuff we can onyl do afetr a transfer */ |
1088 | /* the tail of transfer: execute stuff we can only do after a transfer */ |
1062 | static void |
1089 | INLINE void |
1063 | transfer_tail (void) |
1090 | transfer_tail (pTHX) |
1064 | { |
1091 | { |
|
|
1092 | struct coro *next = (struct coro *)transfer_next; |
|
|
1093 | assert (!(transfer_next = 0)); /* just used for the side effect when asserts are enabled */ |
|
|
1094 | assert (("FATAL: next coroutine was zero in transfer_tail (please report)", next)); |
|
|
1095 | |
|
|
1096 | free_coro_mortal (aTHX); |
1065 | UNLOCK; |
1097 | UNLOCK; |
1066 | |
1098 | |
1067 | if (expect_false (next_has_throw)) |
1099 | if (expect_false (next->throw)) |
1068 | { |
1100 | { |
1069 | struct coro *coro = SvSTATE (coro_current); |
|
|
1070 | |
|
|
1071 | if (coro->throw) |
|
|
1072 | { |
|
|
1073 | SV *exception = coro->throw; |
1101 | SV *exception = sv_2mortal (next->throw); |
|
|
1102 | |
1074 | coro->throw = 0; |
1103 | next->throw = 0; |
1075 | sv_setsv (ERRSV, exception); |
1104 | sv_setsv (ERRSV, exception); |
1076 | croak (0); |
1105 | croak (0); |
1077 | } |
|
|
1078 | } |
1106 | } |
1079 | } |
1107 | } |
1080 | |
1108 | |
1081 | /* |
1109 | /* |
1082 | * this is a _very_ stripped down perl interpreter ;) |
1110 | * this is a _very_ stripped down perl interpreter ;) |
… | |
… | |
1090 | # endif |
1118 | # endif |
1091 | #endif |
1119 | #endif |
1092 | { |
1120 | { |
1093 | dTHX; |
1121 | dTHX; |
1094 | |
1122 | |
|
|
1123 | /* we are the alternative tail to pp_set_stacklevel */ |
|
|
1124 | /* so do the same things here */ |
|
|
1125 | SSL_TAIL; |
|
|
1126 | |
1095 | /* we now skip the entersub that lead to transfer () */ |
1127 | /* we now skip the op that did lead to transfer() */ |
1096 | PL_op = PL_op->op_next; |
1128 | PL_op = PL_op->op_next; |
1097 | |
1129 | |
1098 | /* inject a fake subroutine call to cctx_init */ |
1130 | /* inject a fake subroutine call to cctx_init */ |
1099 | cctx_prepare (aTHX_ (coro_cctx *)arg); |
1131 | cctx_prepare (aTHX_ (coro_cctx *)arg); |
1100 | |
1132 | |
1101 | /* cctx_run is the alternative tail of transfer () */ |
1133 | /* cctx_run is the alternative tail of transfer() */ |
1102 | transfer_tail (); |
1134 | transfer_tail (aTHX); |
1103 | |
1135 | |
1104 | /* somebody or something will hit me for both perl_run and PL_restartop */ |
1136 | /* somebody or something will hit me for both perl_run and PL_restartop */ |
1105 | PL_restartop = PL_op; |
1137 | PL_restartop = PL_op; |
1106 | perl_run (PL_curinterp); |
1138 | perl_run (PL_curinterp); |
1107 | |
1139 | |
… | |
… | |
1125 | ++cctx_count; |
1157 | ++cctx_count; |
1126 | New (0, cctx, 1, coro_cctx); |
1158 | New (0, cctx, 1, coro_cctx); |
1127 | |
1159 | |
1128 | cctx->gen = cctx_gen; |
1160 | cctx->gen = cctx_gen; |
1129 | cctx->flags = 0; |
1161 | cctx->flags = 0; |
1130 | cctx->idle_sp = 0; /* can be accessed by transfer between cctx_run and set_stacklevel */ |
1162 | cctx->idle_sp = 0; /* can be accessed by transfer between cctx_run and set_stacklevel, on throw */ |
1131 | |
1163 | |
1132 | return cctx; |
1164 | return cctx; |
1133 | } |
1165 | } |
1134 | |
1166 | |
1135 | /* create a new cctx only suitable as source */ |
1167 | /* create a new cctx only suitable as source */ |
… | |
… | |
1157 | /* mmap supposedly does allocate-on-write for us */ |
1189 | /* mmap supposedly does allocate-on-write for us */ |
1158 | cctx->sptr = mmap (0, cctx->ssize, PROT_EXEC|PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, 0, 0); |
1190 | cctx->sptr = mmap (0, cctx->ssize, PROT_EXEC|PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, 0, 0); |
1159 | |
1191 | |
1160 | if (cctx->sptr != (void *)-1) |
1192 | if (cctx->sptr != (void *)-1) |
1161 | { |
1193 | { |
1162 | # if CORO_STACKGUARD |
1194 | #if CORO_STACKGUARD |
1163 | mprotect (cctx->sptr, CORO_STACKGUARD * PAGESIZE, PROT_NONE); |
1195 | mprotect (cctx->sptr, CORO_STACKGUARD * PAGESIZE, PROT_NONE); |
1164 | # endif |
1196 | #endif |
1165 | stack_start = CORO_STACKGUARD * PAGESIZE + (char *)cctx->sptr; |
1197 | stack_start = (char *)cctx->sptr + CORO_STACKGUARD * PAGESIZE; |
1166 | stack_size = cctx->ssize - CORO_STACKGUARD * PAGESIZE; |
1198 | stack_size = cctx->ssize - CORO_STACKGUARD * PAGESIZE; |
1167 | cctx->flags |= CC_MAPPED; |
1199 | cctx->flags |= CC_MAPPED; |
1168 | } |
1200 | } |
1169 | else |
1201 | else |
1170 | #endif |
1202 | #endif |
1171 | { |
1203 | { |
1172 | cctx->ssize = cctx_stacksize * (long)sizeof (long); |
1204 | cctx->ssize = cctx_stacksize * (long)sizeof (long); |
1173 | New (0, cctx->sptr, cctx_stacksize, long); |
1205 | New (0, cctx->sptr, cctx_stacksize, long); |
1174 | |
1206 | |
1175 | if (!cctx->sptr) |
1207 | if (!cctx->sptr) |
1176 | { |
1208 | { |
1177 | perror ("FATAL: unable to allocate stack for coroutine"); |
1209 | perror ("FATAL: unable to allocate stack for coroutine, exiting."); |
1178 | _exit (EXIT_FAILURE); |
1210 | _exit (EXIT_FAILURE); |
1179 | } |
1211 | } |
1180 | |
1212 | |
1181 | stack_start = cctx->sptr; |
1213 | stack_start = cctx->sptr; |
1182 | stack_size = cctx->ssize; |
1214 | stack_size = cctx->ssize; |
1183 | } |
1215 | } |
1184 | |
1216 | |
1185 | REGISTER_STACK (cctx, (char *)stack_start, (char *)stack_start + stack_size); |
1217 | #if CORO_USE_VALGRIND |
|
|
1218 | cctx->valgrind_id = VALGRIND_STACK_REGISTER ((char *)stack_start, (char *)stack_start + stack_size); |
|
|
1219 | #endif |
|
|
1220 | |
1186 | coro_create (&cctx->cctx, cctx_run, (void *)cctx, stack_start, stack_size); |
1221 | coro_create (&cctx->cctx, cctx_run, (void *)cctx, stack_start, stack_size); |
1187 | |
1222 | |
1188 | return cctx; |
1223 | return cctx; |
1189 | } |
1224 | } |
1190 | |
1225 | |
… | |
… | |
1198 | coro_destroy (&cctx->cctx); |
1233 | coro_destroy (&cctx->cctx); |
1199 | |
1234 | |
1200 | /* coro_transfer creates new, empty cctx's */ |
1235 | /* coro_transfer creates new, empty cctx's */ |
1201 | if (cctx->sptr) |
1236 | if (cctx->sptr) |
1202 | { |
1237 | { |
1203 | #if CORO_USE_VALGRIND |
1238 | #if CORO_USE_VALGRIND |
1204 | VALGRIND_STACK_DEREGISTER (cctx->valgrind_id); |
1239 | VALGRIND_STACK_DEREGISTER (cctx->valgrind_id); |
1205 | #endif |
1240 | #endif |
1206 | |
1241 | |
1207 | #if HAVE_MMAP |
1242 | #if HAVE_MMAP |
1208 | if (cctx->flags & CC_MAPPED) |
1243 | if (cctx->flags & CC_MAPPED) |
1209 | munmap (cctx->sptr, cctx->ssize); |
1244 | munmap (cctx->sptr, cctx->ssize); |
1210 | else |
1245 | else |
… | |
… | |
1237 | } |
1272 | } |
1238 | |
1273 | |
1239 | static void |
1274 | static void |
1240 | cctx_put (coro_cctx *cctx) |
1275 | cctx_put (coro_cctx *cctx) |
1241 | { |
1276 | { |
1242 | assert (("cctx_put called on non-initialised cctx", cctx->sptr)); |
1277 | assert (("FATAL: cctx_put called on non-initialised cctx in Coro (please report)", cctx->sptr)); |
1243 | |
1278 | |
1244 | /* free another cctx if overlimit */ |
1279 | /* free another cctx if overlimit */ |
1245 | if (expect_false (cctx_idle >= cctx_max_idle)) |
1280 | if (expect_false (cctx_idle >= cctx_max_idle)) |
1246 | { |
1281 | { |
1247 | coro_cctx *first = cctx_first; |
1282 | coro_cctx *first = cctx_first; |
… | |
… | |
1321 | else |
1356 | else |
1322 | load_perl (aTHX_ next); |
1357 | load_perl (aTHX_ next); |
1323 | |
1358 | |
1324 | prev__cctx = prev->cctx; |
1359 | prev__cctx = prev->cctx; |
1325 | |
1360 | |
1326 | if (prev__cctx->idle_sp == STACKLEVEL) asm volatile("");//D |
|
|
1327 | |
|
|
1328 | /* possibly "free" the cctx */ |
1361 | /* possibly untie and reuse the cctx */ |
1329 | if (expect_true ( |
1362 | if (expect_true ( |
1330 | prev__cctx->idle_sp == STACKLEVEL |
1363 | prev__cctx->idle_sp == STACKLEVEL |
1331 | && !(prev__cctx->flags & CC_TRACE) |
1364 | && !(prev__cctx->flags & CC_TRACE) |
1332 | && !force_cctx |
1365 | && !force_cctx |
1333 | )) |
1366 | )) |
1334 | { |
1367 | { |
1335 | /* I assume that STACKLEVEL is a stronger indicator than PL_top_env changes */ |
1368 | /* I assume that STACKLEVEL is a stronger indicator than PL_top_env changes */ |
1336 | assert (("ERROR: current top_env must equal previous top_env", PL_top_env == prev__cctx->idle_te)); |
1369 | assert (("FATAL: current top_env must equal previous top_env in Coro (please report)", PL_top_env == prev__cctx->idle_te)); |
1337 | |
1370 | |
1338 | prev->cctx = 0; |
1371 | prev->cctx = 0; |
1339 | |
1372 | |
1340 | /* if the cctx is about to be destroyed we need to make sure we won't see it in cctx_get */ |
1373 | /* if the cctx is about to be destroyed we need to make sure we won't see it in cctx_get */ |
1341 | /* without this the next cctx_get might destroy the prev__cctx while still in use */ |
1374 | /* without this the next cctx_get might destroy the prev__cctx while still in use */ |
… | |
… | |
1349 | ++next->usecount; |
1382 | ++next->usecount; |
1350 | |
1383 | |
1351 | if (expect_true (!next->cctx)) |
1384 | if (expect_true (!next->cctx)) |
1352 | next->cctx = cctx_get (aTHX); |
1385 | next->cctx = cctx_get (aTHX); |
1353 | |
1386 | |
1354 | next_has_throw = !!next->throw; |
1387 | assert (("FATAL: transfer_next already nonzero in Coro (please report)", !transfer_next)); |
|
|
1388 | transfer_next = next; |
1355 | |
1389 | |
1356 | if (expect_false (prev__cctx != next->cctx)) |
1390 | if (expect_false (prev__cctx != next->cctx)) |
1357 | { |
1391 | { |
1358 | prev__cctx->top_env = PL_top_env; |
1392 | prev__cctx->top_env = PL_top_env; |
1359 | PL_top_env = next->cctx->top_env; |
1393 | PL_top_env = next->cctx->top_env; |
1360 | coro_transfer (&prev__cctx->cctx, &next->cctx->cctx); |
1394 | coro_transfer (&prev__cctx->cctx, &next->cctx->cctx); |
1361 | } |
1395 | } |
1362 | |
1396 | |
1363 | free_coro_mortal (aTHX); |
|
|
1364 | UNLOCK; |
|
|
1365 | |
|
|
1366 | transfer_tail (); |
1397 | transfer_tail (aTHX); |
1367 | } |
1398 | } |
1368 | } |
1399 | } |
1369 | |
|
|
1370 | struct transfer_args |
|
|
1371 | { |
|
|
1372 | struct coro *prev, *next; |
|
|
1373 | }; |
|
|
1374 | |
1400 | |
1375 | #define TRANSFER(ta, force_cctx) transfer (aTHX_ (ta).prev, (ta).next, (force_cctx)) |
1401 | #define TRANSFER(ta, force_cctx) transfer (aTHX_ (ta).prev, (ta).next, (force_cctx)) |
1376 | #define TRANSFER_CHECK(ta) transfer_check (aTHX_ (ta).prev, (ta).next) |
1402 | #define TRANSFER_CHECK(ta) transfer_check (aTHX_ (ta).prev, (ta).next) |
1377 | |
1403 | |
1378 | /** high level stuff ********************************************************/ |
1404 | /** high level stuff ********************************************************/ |
… | |
… | |
1551 | |
1577 | |
1552 | static int |
1578 | static int |
1553 | api_is_ready (SV *coro_sv) |
1579 | api_is_ready (SV *coro_sv) |
1554 | { |
1580 | { |
1555 | dTHX; |
1581 | dTHX; |
|
|
1582 | |
1556 | return !!(SvSTATE (coro_sv)->flags & CF_READY); |
1583 | return !!(SvSTATE (coro_sv)->flags & CF_READY); |
1557 | } |
1584 | } |
1558 | |
1585 | |
1559 | static void |
1586 | INLINE void |
1560 | prepare_schedule (pTHX_ struct transfer_args *ta) |
1587 | prepare_schedule (pTHX_ struct transfer_args *ta) |
1561 | { |
1588 | { |
1562 | SV *prev_sv, *next_sv; |
1589 | SV *prev_sv, *next_sv; |
1563 | |
1590 | |
1564 | for (;;) |
1591 | for (;;) |
… | |
… | |
1590 | /* cannot transfer to destroyed coros, skip and look for next */ |
1617 | /* cannot transfer to destroyed coros, skip and look for next */ |
1591 | if (expect_false (ta->next->flags & CF_DESTROYED)) |
1618 | if (expect_false (ta->next->flags & CF_DESTROYED)) |
1592 | { |
1619 | { |
1593 | UNLOCK; |
1620 | UNLOCK; |
1594 | SvREFCNT_dec (next_sv); |
1621 | SvREFCNT_dec (next_sv); |
1595 | /* coro_nready is already taken care of by destroy */ |
1622 | /* coro_nready has already been taken care of by destroy */ |
1596 | continue; |
1623 | continue; |
1597 | } |
1624 | } |
1598 | |
1625 | |
1599 | --coro_nready; |
1626 | --coro_nready; |
1600 | UNLOCK; |
1627 | UNLOCK; |
… | |
… | |
1603 | |
1630 | |
1604 | /* free this only after the transfer */ |
1631 | /* free this only after the transfer */ |
1605 | prev_sv = SvRV (coro_current); |
1632 | prev_sv = SvRV (coro_current); |
1606 | ta->prev = SvSTATE (prev_sv); |
1633 | ta->prev = SvSTATE (prev_sv); |
1607 | TRANSFER_CHECK (*ta); |
1634 | TRANSFER_CHECK (*ta); |
1608 | assert (ta->next->flags & CF_READY); |
1635 | assert (("FATAL: next coroutine isn't marked as ready in Coro (please report)", ta->next->flags & CF_READY)); |
1609 | ta->next->flags &= ~CF_READY; |
1636 | ta->next->flags &= ~CF_READY; |
1610 | SvRV_set (coro_current, next_sv); |
1637 | SvRV_set (coro_current, next_sv); |
1611 | |
1638 | |
1612 | LOCK; |
1639 | LOCK; |
1613 | free_coro_mortal (aTHX); |
1640 | free_coro_mortal (aTHX); |
1614 | coro_mortal = prev_sv; |
1641 | coro_mortal = prev_sv; |
1615 | UNLOCK; |
1642 | UNLOCK; |
1616 | } |
1643 | } |
1617 | |
1644 | |
1618 | static void |
1645 | INLINE void |
1619 | prepare_cede (pTHX_ struct transfer_args *ta) |
1646 | prepare_cede (pTHX_ struct transfer_args *ta) |
1620 | { |
1647 | { |
1621 | api_ready (coro_current); |
1648 | api_ready (coro_current); |
1622 | prepare_schedule (aTHX_ ta); |
1649 | prepare_schedule (aTHX_ ta); |
1623 | } |
1650 | } |
… | |
… | |
1795 | PerlIOBuf_get_ptr, |
1822 | PerlIOBuf_get_ptr, |
1796 | PerlIOBuf_get_cnt, |
1823 | PerlIOBuf_get_cnt, |
1797 | PerlIOBuf_set_ptrcnt, |
1824 | PerlIOBuf_set_ptrcnt, |
1798 | }; |
1825 | }; |
1799 | |
1826 | |
|
|
1827 | /*****************************************************************************/ |
|
|
1828 | |
|
|
1829 | static const CV *ssl_cv; /* for quick consistency check */ |
|
|
1830 | |
|
|
1831 | static UNOP ssl_restore; /* restore stack as entersub did, for first-re-run */ |
|
|
1832 | static SV *ssl_arg0; |
|
|
1833 | static SV *ssl_arg1; |
|
|
1834 | |
|
|
1835 | /* this restores the stack in the case we patched the entersub, to */ |
|
|
1836 | /* recreate the stack frame as perl will on following calls */ |
|
|
1837 | /* since entersub cleared the stack */ |
|
|
1838 | static OP * |
|
|
1839 | pp_restore (pTHX) |
|
|
1840 | { |
|
|
1841 | dSP; |
|
|
1842 | |
|
|
1843 | PUSHMARK (SP); |
|
|
1844 | |
|
|
1845 | EXTEND (SP, 3); |
|
|
1846 | if (ssl_arg0) PUSHs (sv_2mortal (ssl_arg0)), ssl_arg0 = 0; |
|
|
1847 | if (ssl_arg1) PUSHs (sv_2mortal (ssl_arg1)), ssl_arg1 = 0; |
|
|
1848 | PUSHs ((SV *)CvGV (ssl_cv)); |
|
|
1849 | |
|
|
1850 | RETURNOP (ssl_restore.op_first); |
|
|
1851 | } |
|
|
1852 | |
|
|
1853 | /* declare prototype */ |
|
|
1854 | XS(XS_Coro__State__set_stacklevel); |
|
|
1855 | |
|
|
1856 | static OP * |
|
|
1857 | pp_set_stacklevel (pTHX) |
|
|
1858 | { |
|
|
1859 | dSP; |
|
|
1860 | struct transfer_args ta; |
|
|
1861 | SV **arg = PL_stack_base + TOPMARK + 1; |
|
|
1862 | int items = SP - arg; /* args without function object */ |
|
|
1863 | |
|
|
1864 | /* do a quick consistency check on the "function" object, and if it isn't */ |
|
|
1865 | /* for us, divert to the real entersub */ |
|
|
1866 | if (SvTYPE (*sp) != SVt_PVGV || CvXSUB (GvCV (*sp)) != XS_Coro__State__set_stacklevel) |
|
|
1867 | return PL_ppaddr[OP_ENTERSUB](aTHX); |
|
|
1868 | |
|
|
1869 | /* pop args */ |
|
|
1870 | SP = PL_stack_base + POPMARK; |
|
|
1871 | |
|
|
1872 | if (!(PL_op->op_flags & OPf_STACKED)) |
|
|
1873 | { |
|
|
1874 | /* ampersand-form of call, use @_ instead of stack */ |
|
|
1875 | AV *av = GvAV (PL_defgv); |
|
|
1876 | arg = AvARRAY (av); |
|
|
1877 | items = AvFILLp (av) + 1; |
|
|
1878 | } |
|
|
1879 | |
|
|
1880 | PUTBACK; |
|
|
1881 | switch (PL_op->op_private & 7) |
|
|
1882 | { |
|
|
1883 | case 0: |
|
|
1884 | prepare_set_stacklevel (&ta, (struct coro_cctx *)SvIV (arg [0])); |
|
|
1885 | break; |
|
|
1886 | |
|
|
1887 | case 1: |
|
|
1888 | if (items != 2) |
|
|
1889 | croak ("Coro::State::transfer (prev, next) expects two arguments, not %d.", items); |
|
|
1890 | |
|
|
1891 | prepare_transfer (aTHX_ &ta, arg [0], arg [1]); |
|
|
1892 | break; |
|
|
1893 | |
|
|
1894 | case 2: |
|
|
1895 | prepare_schedule (aTHX_ &ta); |
|
|
1896 | break; |
|
|
1897 | |
|
|
1898 | case 3: |
|
|
1899 | prepare_cede (aTHX_ &ta); |
|
|
1900 | break; |
|
|
1901 | |
|
|
1902 | case 4: |
|
|
1903 | if (!prepare_cede_notself (aTHX_ &ta)) |
|
|
1904 | goto skip; |
|
|
1905 | |
|
|
1906 | break; |
|
|
1907 | } |
|
|
1908 | |
|
|
1909 | TRANSFER (ta, 0); |
|
|
1910 | SPAGAIN; |
|
|
1911 | |
|
|
1912 | skip: |
|
|
1913 | PUTBACK; |
|
|
1914 | SSL_TAIL; |
|
|
1915 | SPAGAIN; |
|
|
1916 | RETURN; |
|
|
1917 | } |
1800 | |
1918 | |
1801 | MODULE = Coro::State PACKAGE = Coro::State PREFIX = api_ |
1919 | MODULE = Coro::State PACKAGE = Coro::State PREFIX = api_ |
1802 | |
1920 | |
1803 | PROTOTYPES: DISABLE |
1921 | PROTOTYPES: DISABLE |
1804 | |
|
|
1805 | BOOT: |
|
|
1806 | { |
|
|
1807 | #ifdef USE_ITHREADS |
|
|
1808 | MUTEX_INIT (&coro_lock); |
|
|
1809 | # if CORO_PTHREAD |
|
|
1810 | coro_thx = PERL_GET_CONTEXT; |
|
|
1811 | # endif |
|
|
1812 | #endif |
|
|
1813 | BOOT_PAGESIZE; |
|
|
1814 | |
|
|
1815 | irsgv = gv_fetchpv ("/" , GV_ADD|GV_NOTQUAL, SVt_PV); |
|
|
1816 | stdoutgv = gv_fetchpv ("STDOUT", GV_ADD|GV_NOTQUAL, SVt_PVIO); |
|
|
1817 | |
|
|
1818 | orig_sigelem_get = PL_vtbl_sigelem.svt_get; PL_vtbl_sigelem.svt_get = coro_sigelem_get; |
|
|
1819 | orig_sigelem_set = PL_vtbl_sigelem.svt_set; PL_vtbl_sigelem.svt_set = coro_sigelem_set; |
|
|
1820 | orig_sigelem_clr = PL_vtbl_sigelem.svt_clear; PL_vtbl_sigelem.svt_clear = coro_sigelem_clr; |
|
|
1821 | |
|
|
1822 | hv_sig = coro_get_hv (aTHX_ "SIG", TRUE); |
|
|
1823 | rv_diehook = newRV_inc ((SV *)gv_fetchpv ("Coro::State::diehook" , 0, SVt_PVCV)); |
|
|
1824 | rv_warnhook = newRV_inc ((SV *)gv_fetchpv ("Coro::State::warnhook", 0, SVt_PVCV)); |
|
|
1825 | |
|
|
1826 | coro_state_stash = gv_stashpv ("Coro::State", TRUE); |
|
|
1827 | |
|
|
1828 | newCONSTSUB (coro_state_stash, "CC_TRACE" , newSViv (CC_TRACE)); |
|
|
1829 | newCONSTSUB (coro_state_stash, "CC_TRACE_SUB" , newSViv (CC_TRACE_SUB)); |
|
|
1830 | newCONSTSUB (coro_state_stash, "CC_TRACE_LINE", newSViv (CC_TRACE_LINE)); |
|
|
1831 | newCONSTSUB (coro_state_stash, "CC_TRACE_ALL" , newSViv (CC_TRACE_ALL)); |
|
|
1832 | |
|
|
1833 | main_mainstack = PL_mainstack; |
|
|
1834 | main_top_env = PL_top_env; |
|
|
1835 | |
|
|
1836 | while (main_top_env->je_prev) |
|
|
1837 | main_top_env = main_top_env->je_prev; |
|
|
1838 | |
|
|
1839 | coroapi.ver = CORO_API_VERSION; |
|
|
1840 | coroapi.rev = CORO_API_REVISION; |
|
|
1841 | coroapi.transfer = api_transfer; |
|
|
1842 | |
|
|
1843 | { |
|
|
1844 | SV **svp = hv_fetch (PL_modglobal, "Time::NVtime", 12, 0); |
|
|
1845 | |
|
|
1846 | if (!svp) croak ("Time::HiRes is required"); |
|
|
1847 | if (!SvIOK (*svp)) croak ("Time::NVtime isn't a function pointer"); |
|
|
1848 | |
|
|
1849 | nvtime = INT2PTR (double (*)(), SvIV (*svp)); |
|
|
1850 | } |
|
|
1851 | |
|
|
1852 | assert (("PRIO_NORMAL must be 0", !PRIO_NORMAL)); |
|
|
1853 | } |
|
|
1854 | |
|
|
1855 | SV * |
|
|
1856 | new (char *klass, ...) |
|
|
1857 | CODE: |
|
|
1858 | { |
|
|
1859 | struct coro *coro; |
|
|
1860 | MAGIC *mg; |
|
|
1861 | HV *hv; |
|
|
1862 | int i; |
|
|
1863 | |
|
|
1864 | Newz (0, coro, 1, struct coro); |
|
|
1865 | coro->args = newAV (); |
|
|
1866 | coro->flags = CF_NEW; |
|
|
1867 | |
|
|
1868 | if (coro_first) coro_first->prev = coro; |
|
|
1869 | coro->next = coro_first; |
|
|
1870 | coro_first = coro; |
|
|
1871 | |
|
|
1872 | coro->hv = hv = newHV (); |
|
|
1873 | mg = sv_magicext ((SV *)hv, 0, CORO_MAGIC_type_state, &coro_state_vtbl, (char *)coro, 0); |
|
|
1874 | mg->mg_flags |= MGf_DUP; |
|
|
1875 | RETVAL = sv_bless (newRV_noinc ((SV *)hv), gv_stashpv (klass, 1)); |
|
|
1876 | |
|
|
1877 | av_extend (coro->args, items - 1); |
|
|
1878 | for (i = 1; i < items; i++) |
|
|
1879 | av_push (coro->args, newSVsv (ST (i))); |
|
|
1880 | } |
|
|
1881 | OUTPUT: |
|
|
1882 | RETVAL |
|
|
1883 | |
1922 | |
1884 | # these not obviously related functions are all rolled into the same xs |
1923 | # these not obviously related functions are all rolled into the same xs |
1885 | # function to increase chances that they all will call transfer with the same |
1924 | # function to increase chances that they all will call transfer with the same |
1886 | # stack offset |
1925 | # stack offset |
1887 | void |
1926 | void |
… | |
… | |
1891 | Coro::schedule = 2 |
1930 | Coro::schedule = 2 |
1892 | Coro::cede = 3 |
1931 | Coro::cede = 3 |
1893 | Coro::cede_notself = 4 |
1932 | Coro::cede_notself = 4 |
1894 | CODE: |
1933 | CODE: |
1895 | { |
1934 | { |
1896 | struct transfer_args ta; |
1935 | assert (("FATAL: ssl call recursion in Coro module (please report)", PL_op->op_ppaddr != pp_set_stacklevel)); |
1897 | |
1936 | |
1898 | PUTBACK; |
1937 | /* we patch the op, and then re-run the whole call */ |
1899 | switch (ix) |
1938 | /* we have to put some dummy argument on the stack for this to work */ |
|
|
1939 | /* TODO: walk back the opcode chain (but how?), nuke the pp_gv etc. */ |
|
|
1940 | ssl_restore.op_next = (OP *)&ssl_restore; |
|
|
1941 | ssl_restore.op_type = OP_NULL; |
|
|
1942 | ssl_restore.op_ppaddr = pp_restore; |
|
|
1943 | ssl_restore.op_first = PL_op; |
|
|
1944 | |
|
|
1945 | ssl_arg0 = items > 0 ? SvREFCNT_inc (ST (0)) : 0; |
|
|
1946 | ssl_arg1 = items > 1 ? SvREFCNT_inc (ST (1)) : 0; |
|
|
1947 | |
|
|
1948 | PL_op->op_ppaddr = pp_set_stacklevel; |
|
|
1949 | PL_op->op_private = PL_op->op_private & ~7 | ix; /* we potentially share our private flags with entersub */ |
|
|
1950 | |
|
|
1951 | PL_op = (OP *)&ssl_restore; |
|
|
1952 | } |
|
|
1953 | |
|
|
1954 | BOOT: |
|
|
1955 | { |
|
|
1956 | #ifdef USE_ITHREADS |
|
|
1957 | MUTEX_INIT (&coro_lock); |
|
|
1958 | # if CORO_PTHREAD |
|
|
1959 | coro_thx = PERL_GET_CONTEXT; |
|
|
1960 | # endif |
|
|
1961 | #endif |
|
|
1962 | BOOT_PAGESIZE; |
|
|
1963 | |
|
|
1964 | ssl_cv = get_cv ("Coro::State::_set_stacklevel", 0); |
|
|
1965 | |
|
|
1966 | irsgv = gv_fetchpv ("/" , GV_ADD|GV_NOTQUAL, SVt_PV); |
|
|
1967 | stdoutgv = gv_fetchpv ("STDOUT", GV_ADD|GV_NOTQUAL, SVt_PVIO); |
|
|
1968 | |
|
|
1969 | orig_sigelem_get = PL_vtbl_sigelem.svt_get; PL_vtbl_sigelem.svt_get = coro_sigelem_get; |
|
|
1970 | orig_sigelem_set = PL_vtbl_sigelem.svt_set; PL_vtbl_sigelem.svt_set = coro_sigelem_set; |
|
|
1971 | orig_sigelem_clr = PL_vtbl_sigelem.svt_clear; PL_vtbl_sigelem.svt_clear = coro_sigelem_clr; |
|
|
1972 | |
|
|
1973 | hv_sig = coro_get_hv (aTHX_ "SIG", TRUE); |
|
|
1974 | rv_diehook = newRV_inc ((SV *)gv_fetchpv ("Coro::State::diehook" , 0, SVt_PVCV)); |
|
|
1975 | rv_warnhook = newRV_inc ((SV *)gv_fetchpv ("Coro::State::warnhook", 0, SVt_PVCV)); |
|
|
1976 | |
|
|
1977 | coro_state_stash = gv_stashpv ("Coro::State", TRUE); |
|
|
1978 | |
|
|
1979 | newCONSTSUB (coro_state_stash, "CC_TRACE" , newSViv (CC_TRACE)); |
|
|
1980 | newCONSTSUB (coro_state_stash, "CC_TRACE_SUB" , newSViv (CC_TRACE_SUB)); |
|
|
1981 | newCONSTSUB (coro_state_stash, "CC_TRACE_LINE", newSViv (CC_TRACE_LINE)); |
|
|
1982 | newCONSTSUB (coro_state_stash, "CC_TRACE_ALL" , newSViv (CC_TRACE_ALL)); |
|
|
1983 | |
|
|
1984 | main_mainstack = PL_mainstack; |
|
|
1985 | main_top_env = PL_top_env; |
|
|
1986 | |
|
|
1987 | while (main_top_env->je_prev) |
|
|
1988 | main_top_env = main_top_env->je_prev; |
|
|
1989 | |
|
|
1990 | coroapi.ver = CORO_API_VERSION; |
|
|
1991 | coroapi.rev = CORO_API_REVISION; |
|
|
1992 | coroapi.transfer = api_transfer; |
|
|
1993 | |
1900 | { |
1994 | { |
1901 | case 0: |
1995 | SV **svp = hv_fetch (PL_modglobal, "Time::NVtime", 12, 0); |
1902 | ta.prev = (struct coro *)INT2PTR (coro_cctx *, SvIV (ST (0))); |
|
|
1903 | ta.next = 0; |
|
|
1904 | break; |
|
|
1905 | |
1996 | |
1906 | case 1: |
1997 | if (!svp) croak ("Time::HiRes is required"); |
1907 | if (items != 2) |
1998 | if (!SvIOK (*svp)) croak ("Time::NVtime isn't a function pointer"); |
1908 | croak ("Coro::State::transfer (prev, next) expects two arguments, not %d", items); |
|
|
1909 | |
1999 | |
1910 | prepare_transfer (aTHX_ &ta, ST (0), ST (1)); |
2000 | nvtime = INT2PTR (double (*)(), SvIV (*svp)); |
1911 | break; |
|
|
1912 | |
|
|
1913 | case 2: |
|
|
1914 | prepare_schedule (aTHX_ &ta); |
|
|
1915 | break; |
|
|
1916 | |
|
|
1917 | case 3: |
|
|
1918 | prepare_cede (aTHX_ &ta); |
|
|
1919 | break; |
|
|
1920 | |
|
|
1921 | case 4: |
|
|
1922 | if (!prepare_cede_notself (aTHX_ &ta)) |
|
|
1923 | XSRETURN_EMPTY; |
|
|
1924 | |
|
|
1925 | break; |
|
|
1926 | } |
2001 | } |
1927 | SPAGAIN; |
|
|
1928 | |
2002 | |
1929 | BARRIER; |
2003 | assert (("PRIO_NORMAL must be 0", !PRIO_NORMAL)); |
1930 | PUTBACK; |
|
|
1931 | TRANSFER (ta, 0); |
|
|
1932 | SPAGAIN; /* might be the sp of a different coroutine now */ |
|
|
1933 | /* be extra careful not to ever do anything after TRANSFER */ |
|
|
1934 | } |
2004 | } |
|
|
2005 | |
|
|
2006 | SV * |
|
|
2007 | new (char *klass, ...) |
|
|
2008 | CODE: |
|
|
2009 | { |
|
|
2010 | struct coro *coro; |
|
|
2011 | MAGIC *mg; |
|
|
2012 | HV *hv; |
|
|
2013 | int i; |
|
|
2014 | |
|
|
2015 | Newz (0, coro, 1, struct coro); |
|
|
2016 | coro->args = newAV (); |
|
|
2017 | coro->flags = CF_NEW; |
|
|
2018 | |
|
|
2019 | if (coro_first) coro_first->prev = coro; |
|
|
2020 | coro->next = coro_first; |
|
|
2021 | coro_first = coro; |
|
|
2022 | |
|
|
2023 | coro->hv = hv = newHV (); |
|
|
2024 | mg = sv_magicext ((SV *)hv, 0, CORO_MAGIC_type_state, &coro_state_vtbl, (char *)coro, 0); |
|
|
2025 | mg->mg_flags |= MGf_DUP; |
|
|
2026 | RETVAL = sv_bless (newRV_noinc ((SV *)hv), gv_stashpv (klass, 1)); |
|
|
2027 | |
|
|
2028 | av_extend (coro->args, items - 1); |
|
|
2029 | for (i = 1; i < items; i++) |
|
|
2030 | av_push (coro->args, newSVsv (ST (i))); |
|
|
2031 | } |
|
|
2032 | OUTPUT: |
|
|
2033 | RETVAL |
1935 | |
2034 | |
1936 | bool |
2035 | bool |
1937 | _destroy (SV *coro_sv) |
2036 | _destroy (SV *coro_sv) |
1938 | CODE: |
2037 | CODE: |
1939 | RETVAL = coro_state_destroy (aTHX_ SvSTATE (coro_sv)); |
2038 | RETVAL = coro_state_destroy (aTHX_ SvSTATE (coro_sv)); |
… | |
… | |
2047 | is_destroyed = CF_DESTROYED |
2146 | is_destroyed = CF_DESTROYED |
2048 | CODE: |
2147 | CODE: |
2049 | RETVAL = boolSV (coro->flags & ix); |
2148 | RETVAL = boolSV (coro->flags & ix); |
2050 | OUTPUT: |
2149 | OUTPUT: |
2051 | RETVAL |
2150 | RETVAL |
|
|
2151 | |
|
|
2152 | void |
|
|
2153 | throw (Coro::State self, SV *throw = &PL_sv_undef) |
|
|
2154 | PROTOTYPE: $;$ |
|
|
2155 | CODE: |
|
|
2156 | SvREFCNT_dec (self->throw); |
|
|
2157 | self->throw = SvOK (throw) ? newSVsv (throw) : 0; |
2052 | |
2158 | |
2053 | void |
2159 | void |
2054 | api_trace (SV *coro, int flags = CC_TRACE | CC_TRACE_SUB) |
2160 | api_trace (SV *coro, int flags = CC_TRACE | CC_TRACE_SUB) |
2055 | |
2161 | |
2056 | SV * |
2162 | SV * |
… | |
… | |
2129 | |
2235 | |
2130 | for (i = PRIO_MAX - PRIO_MIN + 1; i--; ) |
2236 | for (i = PRIO_MAX - PRIO_MIN + 1; i--; ) |
2131 | coro_ready[i] = newAV (); |
2237 | coro_ready[i] = newAV (); |
2132 | |
2238 | |
2133 | { |
2239 | { |
2134 | SV *sv = perl_get_sv ("Coro::API", TRUE); |
2240 | SV *sv = coro_get_sv (aTHX_ "Coro::API", TRUE); |
2135 | perl_get_sv ("Coro::API", TRUE); /* silence 5.10 warning */ |
|
|
2136 | |
2241 | |
2137 | coroapi.schedule = api_schedule; |
2242 | coroapi.schedule = api_schedule; |
2138 | coroapi.cede = api_cede; |
2243 | coroapi.cede = api_cede; |
2139 | coroapi.cede_notself = api_cede_notself; |
2244 | coroapi.cede_notself = api_cede_notself; |
2140 | coroapi.ready = api_ready; |
2245 | coroapi.ready = api_ready; |
… | |
… | |
2200 | CODE: |
2305 | CODE: |
2201 | RETVAL = coro_nready; |
2306 | RETVAL = coro_nready; |
2202 | OUTPUT: |
2307 | OUTPUT: |
2203 | RETVAL |
2308 | RETVAL |
2204 | |
2309 | |
2205 | void |
|
|
2206 | throw (Coro::State self, SV *throw = &PL_sv_undef) |
|
|
2207 | PROTOTYPE: $;$ |
|
|
2208 | CODE: |
|
|
2209 | SvREFCNT_dec (self->throw); |
|
|
2210 | self->throw = SvOK (throw) ? newSVsv (throw) : 0; |
|
|
2211 | |
|
|
2212 | # for async_pool speedup |
2310 | # for async_pool speedup |
2213 | void |
2311 | void |
2214 | _pool_1 (SV *cb) |
2312 | _pool_1 (SV *cb) |
2215 | CODE: |
2313 | CODE: |
2216 | { |
2314 | { |
… | |
… | |
2415 | |
2513 | |
2416 | MODULE = Coro::State PACKAGE = PerlIO::cede |
2514 | MODULE = Coro::State PACKAGE = PerlIO::cede |
2417 | |
2515 | |
2418 | BOOT: |
2516 | BOOT: |
2419 | PerlIO_define_layer (aTHX_ &PerlIO_cede); |
2517 | PerlIO_define_layer (aTHX_ &PerlIO_cede); |
|
|
2518 | |