… | |
… | |
142 | #define NOINLINE attribute ((noinline)) |
142 | #define NOINLINE attribute ((noinline)) |
143 | |
143 | |
144 | #include "CoroAPI.h" |
144 | #include "CoroAPI.h" |
145 | |
145 | |
146 | #ifdef USE_ITHREADS |
146 | #ifdef USE_ITHREADS |
|
|
147 | |
147 | static perl_mutex coro_lock; |
148 | static perl_mutex coro_lock; |
148 | # define LOCK do { MUTEX_LOCK (&coro_lock); } while (0) |
149 | # define LOCK do { MUTEX_LOCK (&coro_lock); } while (0) |
149 | # define UNLOCK do { MUTEX_UNLOCK (&coro_lock); } while (0) |
150 | # define UNLOCK do { MUTEX_UNLOCK (&coro_lock); } while (0) |
|
|
151 | # if CORO_PTHREAD |
|
|
152 | static void *coro_thx; |
|
|
153 | # endif |
|
|
154 | |
150 | #else |
155 | #else |
|
|
156 | |
151 | # define LOCK (void)0 |
157 | # define LOCK (void)0 |
152 | # define UNLOCK (void)0 |
158 | # define UNLOCK (void)0 |
|
|
159 | |
153 | #endif |
160 | #endif |
|
|
161 | |
|
|
162 | # undef LOCK |
|
|
163 | # define LOCK (void)0 |
|
|
164 | # undef UNLOCK |
|
|
165 | # define UNLOCK (void)0 |
154 | |
166 | |
155 | /* helper storage struct for Coro::AIO */ |
167 | /* helper storage struct for Coro::AIO */ |
156 | struct io_state |
168 | struct io_state |
157 | { |
169 | { |
158 | AV *res; |
170 | AV *res; |
… | |
… | |
1048 | * this is a _very_ stripped down perl interpreter ;) |
1060 | * this is a _very_ stripped down perl interpreter ;) |
1049 | */ |
1061 | */ |
1050 | static void |
1062 | static void |
1051 | cctx_run (void *arg) |
1063 | cctx_run (void *arg) |
1052 | { |
1064 | { |
|
|
1065 | #ifdef USE_ITHREADS |
|
|
1066 | # if CORO_PTHREAD |
|
|
1067 | PERL_SET_CONTEXT (coro_thx); |
|
|
1068 | # endif |
|
|
1069 | #endif |
|
|
1070 | { |
1053 | dTHX; |
1071 | dTHX; |
1054 | |
1072 | |
1055 | /* cctx_run is the alternative tail of transfer(), so unlock here. */ |
1073 | /* cctx_run is the alternative tail of transfer(), so unlock here. */ |
1056 | UNLOCK; |
1074 | UNLOCK; |
1057 | |
1075 | |
1058 | /* we now skip the entersub that lead to transfer() */ |
1076 | /* we now skip the entersub that lead to transfer() */ |
1059 | PL_op = PL_op->op_next; |
1077 | PL_op = PL_op->op_next; |
1060 | |
1078 | |
1061 | /* inject a fake subroutine call to cctx_init */ |
1079 | /* inject a fake subroutine call to cctx_init */ |
1062 | cctx_prepare (aTHX_ (coro_cctx *)arg); |
1080 | cctx_prepare (aTHX_ (coro_cctx *)arg); |
1063 | |
1081 | |
1064 | /* somebody or something will hit me for both perl_run and PL_restartop */ |
1082 | /* somebody or something will hit me for both perl_run and PL_restartop */ |
1065 | PL_restartop = PL_op; |
1083 | PL_restartop = PL_op; |
1066 | perl_run (PL_curinterp); |
1084 | perl_run (PL_curinterp); |
1067 | |
1085 | |
1068 | /* |
1086 | /* |
1069 | * If perl-run returns we assume exit() was being called or the coro |
1087 | * If perl-run returns we assume exit() was being called or the coro |
1070 | * fell off the end, which seems to be the only valid (non-bug) |
1088 | * fell off the end, which seems to be the only valid (non-bug) |
1071 | * reason for perl_run to return. We try to exit by jumping to the |
1089 | * reason for perl_run to return. We try to exit by jumping to the |
1072 | * bootstrap-time "top" top_env, as we cannot restore the "main" |
1090 | * bootstrap-time "top" top_env, as we cannot restore the "main" |
1073 | * coroutine as Coro has no such concept |
1091 | * coroutine as Coro has no such concept |
1074 | */ |
1092 | */ |
1075 | PL_top_env = main_top_env; |
1093 | PL_top_env = main_top_env; |
1076 | JMPENV_JUMP (2); /* I do not feel well about the hardcoded 2 at all */ |
1094 | JMPENV_JUMP (2); /* I do not feel well about the hardcoded 2 at all */ |
|
|
1095 | } |
1077 | } |
1096 | } |
1078 | |
1097 | |
1079 | static coro_cctx * |
1098 | static coro_cctx * |
1080 | cctx_new () |
1099 | cctx_new () |
1081 | { |
1100 | { |
… | |
… | |
1754 | |
1773 | |
1755 | BOOT: |
1774 | BOOT: |
1756 | { |
1775 | { |
1757 | #ifdef USE_ITHREADS |
1776 | #ifdef USE_ITHREADS |
1758 | MUTEX_INIT (&coro_lock); |
1777 | MUTEX_INIT (&coro_lock); |
|
|
1778 | # if CORO_PTHREAD |
|
|
1779 | coro_thx = PERL_GET_CONTEXT; |
|
|
1780 | # endif |
1759 | #endif |
1781 | #endif |
1760 | BOOT_PAGESIZE; |
1782 | BOOT_PAGESIZE; |
1761 | |
1783 | |
1762 | irsgv = gv_fetchpv ("/" , GV_ADD|GV_NOTQUAL, SVt_PV); |
1784 | irsgv = gv_fetchpv ("/" , GV_ADD|GV_NOTQUAL, SVt_PV); |
1763 | stdoutgv = gv_fetchpv ("STDOUT", GV_ADD|GV_NOTQUAL, SVt_PVIO); |
1785 | stdoutgv = gv_fetchpv ("STDOUT", GV_ADD|GV_NOTQUAL, SVt_PVIO); |