… | |
… | |
101 | # if CORO_PTHREAD |
101 | # if CORO_PTHREAD |
102 | static void *coro_thx; |
102 | static void *coro_thx; |
103 | # endif |
103 | # endif |
104 | #endif |
104 | #endif |
105 | |
105 | |
106 | /* used in state.h */ |
|
|
107 | #define VAR(name,type) VARx(name, PL_ ## name, type) |
|
|
108 | |
|
|
109 | #ifdef __linux |
106 | #ifdef __linux |
110 | # include <time.h> /* for timespec */ |
107 | # include <time.h> /* for timespec */ |
111 | # include <syscall.h> /* for SYS_* */ |
108 | # include <syscall.h> /* for SYS_* */ |
112 | # ifdef SYS_clock_gettime |
109 | # ifdef SYS_clock_gettime |
113 | # define coro_clock_gettime(id, ts) syscall (SYS_clock_gettime, (id), (ts)) |
110 | # define coro_clock_gettime(id, ts) syscall (SYS_clock_gettime, (id), (ts)) |
… | |
… | |
213 | }; |
210 | }; |
214 | |
211 | |
215 | /* the structure where most of the perl state is stored, overlaid on the cxstack */ |
212 | /* the structure where most of the perl state is stored, overlaid on the cxstack */ |
216 | typedef struct |
213 | typedef struct |
217 | { |
214 | { |
218 | #define VARx(name,expr,type) type name; |
215 | #define VARx(name,expr,type) type name; |
219 | # include "state.h" |
216 | #include "state.h" |
220 | #undef VARx |
|
|
221 | } perl_slots; |
217 | } perl_slots; |
222 | |
218 | |
223 | /* how many context stack entries do we need for perl_slots */ |
219 | /* how many context stack entries do we need for perl_slots */ |
224 | #define SLOT_COUNT ((sizeof (perl_slots) + sizeof (PERL_CONTEXT) - 1) / sizeof (PERL_CONTEXT)) |
220 | #define SLOT_COUNT ((sizeof (perl_slots) + sizeof (PERL_CONTEXT) - 1) / sizeof (PERL_CONTEXT)) |
225 | |
221 | |
… | |
… | |
710 | |
706 | |
711 | #if CORO_JIT |
707 | #if CORO_JIT |
712 | load_perl_slots (slot); |
708 | load_perl_slots (slot); |
713 | #else |
709 | #else |
714 | #define VARx(name,expr,type) expr = slot->name; |
710 | #define VARx(name,expr,type) expr = slot->name; |
715 | # include "state.h" |
711 | #include "state.h" |
716 | #undef VARx |
|
|
717 | #endif |
712 | #endif |
718 | |
713 | |
719 | { |
714 | { |
720 | dSP; |
715 | dSP; |
721 | |
716 | |
… | |
… | |
843 | |
838 | |
844 | #if CORO_JIT |
839 | #if CORO_JIT |
845 | save_perl_slots (slot); |
840 | save_perl_slots (slot); |
846 | #else |
841 | #else |
847 | #define VARx(name,expr,type) slot->name = expr; |
842 | #define VARx(name,expr,type) slot->name = expr; |
848 | # include "state.h" |
843 | #include "state.h" |
849 | #undef VARx |
|
|
850 | #endif |
844 | #endif |
851 | } |
845 | } |
852 | } |
846 | } |
853 | |
847 | |
854 | /* |
848 | /* |
… | |
… | |
1410 | |
1404 | |
1411 | slf_frame.prepare = slf_prepare_set_stacklevel; |
1405 | slf_frame.prepare = slf_prepare_set_stacklevel; |
1412 | slf_frame.check = slf_check_set_stacklevel; |
1406 | slf_frame.check = slf_check_set_stacklevel; |
1413 | } |
1407 | } |
1414 | |
1408 | |
|
|
1409 | /* the tail of transfer: execute stuff we can only do after a transfer */ |
|
|
1410 | ecb_inline void |
|
|
1411 | transfer_tail (pTHX) |
|
|
1412 | { |
|
|
1413 | free_coro_mortal (aTHX); |
|
|
1414 | } |
|
|
1415 | |
1415 | /* try to exit the same way perl's main function would do */ |
1416 | /* try to exit the same way perl's main function would do */ |
1416 | /* we do not bother resetting the environment or other things *7 |
1417 | /* we do not bother resetting the environment or other things *7 |
1417 | /* that are not, uhm, essential */ |
1418 | /* that are not, uhm, essential */ |
1418 | /* this obviously also doesn't work when perl is embedded */ |
1419 | /* this obviously also doesn't work when perl is embedded */ |
1419 | static void ecb_noinline ecb_cold |
1420 | static void ecb_noinline ecb_cold |
1420 | perlish_exit (void) |
1421 | perlish_exit (pTHX) |
1421 | { |
1422 | { |
1422 | int exitstatus = perl_destruct (PL_curinterp); |
1423 | int exitstatus = perl_destruct (PL_curinterp); |
1423 | perl_free (PL_curinterp); |
1424 | perl_free (PL_curinterp); |
1424 | exit (exitstatus); |
1425 | exit (exitstatus); |
1425 | } |
|
|
1426 | |
|
|
1427 | /* the tail of transfer: execute stuff we can only do after a transfer */ |
|
|
1428 | ecb_inline void |
|
|
1429 | transfer_tail (pTHX) |
|
|
1430 | { |
|
|
1431 | free_coro_mortal (aTHX); |
|
|
1432 | } |
1426 | } |
1433 | |
1427 | |
1434 | /* |
1428 | /* |
1435 | * this is a _very_ stripped down perl interpreter ;) |
1429 | * this is a _very_ stripped down perl interpreter ;) |
1436 | */ |
1430 | */ |
… | |
… | |
1468 | * If perl-run returns we assume exit() was being called or the coro |
1462 | * If perl-run returns we assume exit() was being called or the coro |
1469 | * fell off the end, which seems to be the only valid (non-bug) |
1463 | * fell off the end, which seems to be the only valid (non-bug) |
1470 | * reason for perl_run to return. We try to mimic whatever perl is normally |
1464 | * reason for perl_run to return. We try to mimic whatever perl is normally |
1471 | * doing in that case. YMMV. |
1465 | * doing in that case. YMMV. |
1472 | */ |
1466 | */ |
1473 | perlish_exit (); |
1467 | perlish_exit (aTHX); |
1474 | } |
1468 | } |
1475 | } |
1469 | } |
1476 | |
1470 | |
1477 | static coro_cctx * |
1471 | static coro_cctx * |
1478 | cctx_new (void) |
1472 | cctx_new (void) |
… | |
… | |
3401 | int count; |
3395 | int count; |
3402 | |
3396 | |
3403 | eval_pv ("require 'Coro/jit-" CORO_JIT_TYPE ".pl'", 1); |
3397 | eval_pv ("require 'Coro/jit-" CORO_JIT_TYPE ".pl'", 1); |
3404 | |
3398 | |
3405 | PUSHMARK (SP); |
3399 | PUSHMARK (SP); |
3406 | #define VARx(name,expr,type) pushav_4uv (aTHX_ (UV)&(expr), sizeof (expr), offsetof (perl_slots, name), sizeof (type)); |
3400 | #define VARx(name,expr,type) pushav_4uv (aTHX_ (UV)&(expr), sizeof (expr), offsetof (perl_slots, name), sizeof (type)); |
3407 | # include "state.h" |
3401 | #include "state.h" |
3408 | #undef VARx |
|
|
3409 | count = call_pv ("Coro::State::_jit", G_ARRAY); |
3402 | count = call_pv ("Coro::State::_jit", G_ARRAY); |
3410 | SPAGAIN; |
3403 | SPAGAIN; |
3411 | |
3404 | |
3412 | save = POPs; save_ptr = SvPVbyte (save, save_len); |
3405 | save = POPs; save_ptr = SvPVbyte (save, save_len); |
3413 | load = POPs; load_ptr = SvPVbyte (load, load_len); |
3406 | load = POPs; load_ptr = SvPVbyte (load, load_len); |