… | |
… | |
888 | |
888 | |
889 | /* inject a fake call to Coro::State::_cctx_init into the execution */ |
889 | /* inject a fake call to Coro::State::_cctx_init into the execution */ |
890 | /* _cctx_init should be careful, as it could be called at almost any time */ |
890 | /* _cctx_init should be careful, as it could be called at almost any time */ |
891 | /* during execution of a perl program */ |
891 | /* during execution of a perl program */ |
892 | static void NOINLINE |
892 | static void NOINLINE |
893 | prepare_cctx (pTHX_ coro_cctx *cctx) |
893 | cctx_prepare (pTHX_ coro_cctx *cctx) |
894 | { |
894 | { |
895 | dSP; |
895 | dSP; |
896 | LOGOP myop; |
896 | LOGOP myop; |
897 | |
897 | |
898 | PL_top_env = &PL_start_env; |
898 | PL_top_env = &PL_start_env; |
… | |
… | |
916 | |
916 | |
917 | /* |
917 | /* |
918 | * this is a _very_ stripped down perl interpreter ;) |
918 | * this is a _very_ stripped down perl interpreter ;) |
919 | */ |
919 | */ |
920 | static void |
920 | static void |
921 | coro_run (void *arg) |
921 | cctx_run (void *arg) |
922 | { |
922 | { |
923 | dTHX; |
923 | dTHX; |
924 | |
924 | |
925 | /* coro_run is the alternative tail of transfer(), so unlock here. */ |
925 | /* cctx_run is the alternative tail of transfer(), so unlock here. */ |
926 | UNLOCK; |
926 | UNLOCK; |
927 | |
927 | |
928 | /* we now skip the entersub that lead to transfer() */ |
928 | /* we now skip the entersub that lead to transfer() */ |
929 | PL_op = PL_op->op_next; |
929 | PL_op = PL_op->op_next; |
930 | |
930 | |
931 | /* inject a fake subroutine call to cctx_init */ |
931 | /* inject a fake subroutine call to cctx_init */ |
932 | prepare_cctx (aTHX_ (coro_cctx *)arg); |
932 | cctx_prepare (aTHX_ (coro_cctx *)arg); |
933 | |
933 | |
934 | /* somebody or something will hit me for both perl_run and PL_restartop */ |
934 | /* somebody or something will hit me for both perl_run and PL_restartop */ |
935 | PL_restartop = PL_op; |
935 | PL_restartop = PL_op; |
936 | perl_run (PL_curinterp); |
936 | perl_run (PL_curinterp); |
937 | |
937 | |
… | |
… | |
956 | ++cctx_count; |
956 | ++cctx_count; |
957 | |
957 | |
958 | Newz (0, cctx, 1, coro_cctx); |
958 | Newz (0, cctx, 1, coro_cctx); |
959 | |
959 | |
960 | #if HAVE_MMAP |
960 | #if HAVE_MMAP |
961 | |
|
|
962 | cctx->ssize = ((coro_stacksize * sizeof (long) + PAGESIZE - 1) / PAGESIZE + CORO_STACKGUARD) * PAGESIZE; |
961 | cctx->ssize = ((coro_stacksize * sizeof (long) + PAGESIZE - 1) / PAGESIZE + CORO_STACKGUARD) * PAGESIZE; |
963 | /* mmap supposedly does allocate-on-write for us */ |
962 | /* mmap supposedly does allocate-on-write for us */ |
964 | cctx->sptr = mmap (0, cctx->ssize, PROT_EXEC|PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, 0, 0); |
963 | cctx->sptr = mmap (0, cctx->ssize, PROT_EXEC|PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, 0, 0); |
965 | |
964 | |
966 | if (cctx->sptr != (void *)-1) |
965 | if (cctx->sptr != (void *)-1) |
… | |
… | |
987 | stack_start = cctx->sptr; |
986 | stack_start = cctx->sptr; |
988 | stack_size = cctx->ssize; |
987 | stack_size = cctx->ssize; |
989 | } |
988 | } |
990 | |
989 | |
991 | REGISTER_STACK (cctx, (char *)stack_start, (char *)stack_start + stack_size); |
990 | REGISTER_STACK (cctx, (char *)stack_start, (char *)stack_start + stack_size); |
992 | coro_create (&cctx->cctx, coro_run, (void *)cctx, stack_start, stack_size); |
991 | coro_create (&cctx->cctx, cctx_run, (void *)cctx, stack_start, stack_size); |
993 | |
992 | |
994 | return cctx; |
993 | return cctx; |
995 | } |
994 | } |
996 | |
995 | |
997 | static void |
996 | static void |
… | |
… | |
1138 | prev->cctx = 0; |
1137 | prev->cctx = 0; |
1139 | |
1138 | |
1140 | /* if the cctx is about to be destroyed we need to make sure we won't see it in cctx_get */ |
1139 | /* if the cctx is about to be destroyed we need to make sure we won't see it in cctx_get */ |
1141 | /* without this the next cctx_get might destroy the prev__cctx while still in use */ |
1140 | /* without this the next cctx_get might destroy the prev__cctx while still in use */ |
1142 | if (expect_false (CCTX_EXPIRED (prev__cctx))) |
1141 | if (expect_false (CCTX_EXPIRED (prev__cctx))) |
|
|
1142 | if (!next->cctx) |
1143 | next->cctx = cctx_get (aTHX); |
1143 | next->cctx = cctx_get (aTHX); |
1144 | |
1144 | |
1145 | cctx_put (prev__cctx); |
1145 | cctx_put (prev__cctx); |
1146 | } |
1146 | } |
1147 | |
1147 | |
1148 | ++next->usecount; |
1148 | ++next->usecount; |