… | |
… | |
938 | /* copy throw, in case it was set before coro_setup */ |
938 | /* copy throw, in case it was set before coro_setup */ |
939 | CORO_THROW = coro->except; |
939 | CORO_THROW = coro->except; |
940 | } |
940 | } |
941 | |
941 | |
942 | static void |
942 | static void |
943 | coro_destruct_perl (pTHX_ struct coro *coro) |
943 | coro_unwind_stacks (pTHX) |
944 | { |
944 | { |
945 | if (!IN_DESTRUCT) |
945 | if (!IN_DESTRUCT) |
946 | { |
946 | { |
947 | /* restore all saved variables and stuff */ |
947 | /* restore all saved variables and stuff */ |
948 | LEAVE_SCOPE (0); |
948 | LEAVE_SCOPE (0); |
… | |
… | |
956 | POPSTACK_TO (PL_mainstack); |
956 | POPSTACK_TO (PL_mainstack); |
957 | |
957 | |
958 | /* unwind main stack */ |
958 | /* unwind main stack */ |
959 | dounwind (-1); |
959 | dounwind (-1); |
960 | } |
960 | } |
|
|
961 | } |
|
|
962 | |
|
|
963 | static void |
|
|
964 | coro_destruct_perl (pTHX_ struct coro *coro) |
|
|
965 | { |
|
|
966 | coro_unwind_stacks (aTHX); |
961 | |
967 | |
962 | SvREFCNT_dec (GvSV (PL_defgv)); |
968 | SvREFCNT_dec (GvSV (PL_defgv)); |
963 | SvREFCNT_dec (GvAV (PL_defgv)); |
969 | SvREFCNT_dec (GvAV (PL_defgv)); |
964 | SvREFCNT_dec (GvSV (PL_errgv)); |
970 | SvREFCNT_dec (GvSV (PL_errgv)); |
965 | SvREFCNT_dec (PL_defoutgv); |
971 | SvREFCNT_dec (PL_defoutgv); |
… | |
… | |
1277 | cctx_destroy (coro_cctx *cctx) |
1283 | cctx_destroy (coro_cctx *cctx) |
1278 | { |
1284 | { |
1279 | if (!cctx) |
1285 | if (!cctx) |
1280 | return; |
1286 | return; |
1281 | |
1287 | |
1282 | assert (cctx != cctx_current);//D temporary |
1288 | assert (("FATAL: tried to destroy current cctx", cctx != cctx_current));//D temporary? |
1283 | |
1289 | |
1284 | --cctx_count; |
1290 | --cctx_count; |
1285 | coro_destroy (&cctx->cctx); |
1291 | coro_destroy (&cctx->cctx); |
1286 | |
1292 | |
1287 | /* coro_transfer creates new, empty cctx's */ |
1293 | /* coro_transfer creates new, empty cctx's */ |
… | |
… | |
1405 | coro_setup (aTHX_ next); |
1411 | coro_setup (aTHX_ next); |
1406 | } |
1412 | } |
1407 | else |
1413 | else |
1408 | load_perl (aTHX_ next); |
1414 | load_perl (aTHX_ next); |
1409 | |
1415 | |
1410 | assert (!prev->cctx);//D temporary |
|
|
1411 | |
|
|
1412 | /* possibly untie and reuse the cctx */ |
1416 | /* possibly untie and reuse the cctx */ |
1413 | if (expect_true ( |
1417 | if (expect_true ( |
1414 | cctx_current->idle_sp == STACKLEVEL |
1418 | cctx_current->idle_sp == STACKLEVEL |
1415 | && !(cctx_current->flags & CC_TRACE) |
1419 | && !(cctx_current->flags & CC_TRACE) |
1416 | && !force_cctx |
1420 | && !force_cctx |
… | |
… | |
1473 | else |
1477 | else |
1474 | coro->flags |= CF_READY; /* make sure it is NOT put into the readyqueue */ |
1478 | coro->flags |= CF_READY; /* make sure it is NOT put into the readyqueue */ |
1475 | |
1479 | |
1476 | if (coro->mainstack |
1480 | if (coro->mainstack |
1477 | && coro->mainstack != main_mainstack |
1481 | && coro->mainstack != main_mainstack |
|
|
1482 | && coro->slot |
1478 | && !PL_dirty) |
1483 | && !PL_dirty) |
1479 | { |
1484 | { |
1480 | struct coro temp; |
1485 | struct coro temp; |
1481 | |
1486 | |
1482 | assert (("FATAL: tried to destroy currently running coroutine (please report)", !(coro->flags & CF_RUNNING))); |
1487 | assert (("FATAL: tried to destroy currently running coroutine", coro->mainstack != PL_mainstack)); |
1483 | |
1488 | |
1484 | save_perl (aTHX_ &temp); |
1489 | save_perl (aTHX_ &temp); |
1485 | load_perl (aTHX_ coro); |
1490 | load_perl (aTHX_ coro); |
1486 | |
1491 | |
1487 | coro_destruct_perl (aTHX_ coro); |
1492 | coro_destruct_perl (aTHX_ coro); |
… | |
… | |
1864 | av_push (av_destroy, (SV *)newRV_inc ((SV *)hv)); /* RVinc for perl */ |
1869 | av_push (av_destroy, (SV *)newRV_inc ((SV *)hv)); /* RVinc for perl */ |
1865 | api_ready (aTHX_ sv_manager); |
1870 | api_ready (aTHX_ sv_manager); |
1866 | |
1871 | |
1867 | frame->prepare = prepare_schedule; |
1872 | frame->prepare = prepare_schedule; |
1868 | frame->check = slf_check_repeat; |
1873 | frame->check = slf_check_repeat; |
|
|
1874 | |
|
|
1875 | /* as a minor optimisation, we could unwind all stacks here */ |
|
|
1876 | /* but that puts extra pressure on pp_slf, and is not worth much */ |
|
|
1877 | /*coro_unwind_stacks (aTHX);*/ |
1869 | } |
1878 | } |
1870 | |
1879 | |
1871 | /*****************************************************************************/ |
1880 | /*****************************************************************************/ |
1872 | /* async pool handler */ |
1881 | /* async pool handler */ |
1873 | |
1882 | |
… | |
… | |
3128 | { |
3137 | { |
3129 | int i; |
3138 | int i; |
3130 | |
3139 | |
3131 | sv_pool_rss = coro_get_sv (aTHX_ "Coro::POOL_RSS" , TRUE); |
3140 | sv_pool_rss = coro_get_sv (aTHX_ "Coro::POOL_RSS" , TRUE); |
3132 | sv_pool_size = coro_get_sv (aTHX_ "Coro::POOL_SIZE" , TRUE); |
3141 | sv_pool_size = coro_get_sv (aTHX_ "Coro::POOL_SIZE" , TRUE); |
3133 | cv_coro_run = get_cv ( "Coro::_terminate", GV_ADD); |
3142 | cv_coro_run = get_cv ( "Coro::_coro_run" , GV_ADD); |
3134 | cv_coro_terminate = get_cv ( "Coro::terminate" , GV_ADD); |
3143 | cv_coro_terminate = get_cv ( "Coro::terminate" , GV_ADD); |
3135 | coro_current = coro_get_sv (aTHX_ "Coro::current" , FALSE); SvREADONLY_on (coro_current); |
3144 | coro_current = coro_get_sv (aTHX_ "Coro::current" , FALSE); SvREADONLY_on (coro_current); |
3136 | av_async_pool = coro_get_av (aTHX_ "Coro::async_pool", TRUE); |
3145 | av_async_pool = coro_get_av (aTHX_ "Coro::async_pool", TRUE); |
3137 | av_destroy = coro_get_av (aTHX_ "Coro::destroy" , TRUE); |
3146 | av_destroy = coro_get_av (aTHX_ "Coro::destroy" , TRUE); |
3138 | sv_manager = coro_get_sv (aTHX_ "Coro::manager" , TRUE); |
3147 | sv_manager = coro_get_sv (aTHX_ "Coro::manager" , TRUE); |