… | |
… | |
614 | PL_exit_flags |= PERL_EXIT_DESTRUCT_END; |
614 | PL_exit_flags |= PERL_EXIT_DESTRUCT_END; |
615 | |
615 | |
616 | const char *argv[] = { |
616 | const char *argv[] = { |
617 | settings.argv [0], |
617 | settings.argv [0], |
618 | "-e" |
618 | "-e" |
619 | "use Event; use Coro;" // required for bootstrap |
619 | "use EV; use Coro;" // required for bootstrap |
620 | "cf->bootstrap;" // required for datadir :*> |
620 | "cf->bootstrap;" // required for datadir :*> |
621 | "unshift @INC, cf::datadir ();" |
621 | "unshift @INC, cf::datadir ();" |
622 | "require cf;" |
622 | "require cf;" |
623 | }; |
623 | }; |
624 | |
624 | |
625 | if (perl_parse (perl, xs_init, 2, (char **)argv, (char **)NULL) |
625 | if (perl_parse (perl, xs_init, 2, (char **)argv, (char **)NULL) |
… | |
… | |
1099 | #endif |
1099 | #endif |
1100 | } |
1100 | } |
1101 | |
1101 | |
1102 | ///////////////////////////////////////////////////////////////////////////// |
1102 | ///////////////////////////////////////////////////////////////////////////// |
1103 | |
1103 | |
1104 | struct EventAPI *watcher_base::GEventAPI; |
1104 | struct EVAPI *evapi::GEVAPI; |
1105 | struct CoroAPI *coroapi::GCoroAPI; |
1105 | struct CoroAPI *coroapi::GCoroAPI; |
1106 | |
1106 | |
1107 | int coroapi::cede_counter; |
1107 | int coroapi::cede_counter; |
1108 | tstamp coroapi::next_cede; |
1108 | tstamp coroapi::next_cede; |
1109 | |
1109 | |
1110 | void coroapi::do_cede_to_tick () |
1110 | void coroapi::do_cede_to_tick () |
… | |
… | |
1147 | CALL_BEGIN (0); |
1147 | CALL_BEGIN (0); |
1148 | CALL_CALL ("cf::wait_for_tick_begin", G_DISCARD); |
1148 | CALL_CALL ("cf::wait_for_tick_begin", G_DISCARD); |
1149 | CALL_END; |
1149 | CALL_END; |
1150 | } |
1150 | } |
1151 | |
1151 | |
1152 | static void |
|
|
1153 | iw_dispatch (pe_event *ev) |
|
|
1154 | { |
|
|
1155 | iw *w = (iw *)ev->ext_data; |
|
|
1156 | w->call (*w); |
|
|
1157 | } |
|
|
1158 | |
|
|
1159 | void |
|
|
1160 | iw::alloc () |
|
|
1161 | { |
|
|
1162 | pe = GEventAPI->new_idle (0, 0); |
|
|
1163 | |
|
|
1164 | WaREENTRANT_off (pe); |
|
|
1165 | pe->base.callback = (void *)iw_dispatch; |
|
|
1166 | pe->base.ext_data = (void *)this; |
|
|
1167 | } |
|
|
1168 | |
|
|
1169 | static void iow_dispatch (pe_event *ev) |
|
|
1170 | { |
|
|
1171 | iow *w = (iow *)ev->ext_data; |
|
|
1172 | w->call (*w, ((pe_ioevent *)ev)->got); |
|
|
1173 | } |
|
|
1174 | |
|
|
1175 | void |
|
|
1176 | iow::alloc () |
|
|
1177 | { |
|
|
1178 | pe = GEventAPI->new_io (0, 0); |
|
|
1179 | |
|
|
1180 | WaREENTRANT_off (pe); |
|
|
1181 | pe->base.callback = (void *)iow_dispatch; |
|
|
1182 | pe->base.ext_data = (void *)this; |
|
|
1183 | |
|
|
1184 | pe->fd = -1; |
|
|
1185 | pe->poll = 0; |
|
|
1186 | } |
|
|
1187 | |
|
|
1188 | void |
|
|
1189 | iow::fd (int fd) |
|
|
1190 | { |
|
|
1191 | pe->fd = fd; |
|
|
1192 | } |
|
|
1193 | |
|
|
1194 | int |
|
|
1195 | iow::poll () |
|
|
1196 | { |
|
|
1197 | return pe->poll; |
|
|
1198 | } |
|
|
1199 | |
|
|
1200 | void |
1152 | void |
1201 | iow::poll (int events) |
1153 | iow::poll (int events) |
1202 | { |
1154 | { |
1203 | if (pe->poll != events) |
1155 | if (events != this->events) |
1204 | { |
1156 | { |
|
|
1157 | int active = ev_is_active ((ev_io *)this); |
1205 | if (pe->poll) stop (); |
1158 | if (active) stop (); |
1206 | pe->poll = events; |
1159 | ev_io_set ((ev_io *)this, fd, events); |
1207 | if (pe->poll) start (); |
1160 | if (active) start (); |
1208 | } |
1161 | } |
1209 | } |
1162 | } |
1210 | |
1163 | |
1211 | void |
1164 | void |
1212 | _connect_to_perl () |
1165 | _connect_to_perl () |
… | |
… | |
1237 | |
1190 | |
1238 | MODULE = cf PACKAGE = cf PREFIX = cf_ |
1191 | MODULE = cf PACKAGE = cf PREFIX = cf_ |
1239 | |
1192 | |
1240 | BOOT: |
1193 | BOOT: |
1241 | { |
1194 | { |
1242 | I_EVENT_API (PACKAGE); watcher_base::GEventAPI = GEventAPI; |
1195 | I_EV_API (PACKAGE); evapi::GEVAPI = GEVAPI; |
1243 | I_CORO_API (PACKAGE); coroapi::GCoroAPI = GCoroAPI; |
1196 | I_CORO_API (PACKAGE); coroapi::GCoroAPI = GCoroAPI; |
1244 | |
1197 | |
1245 | _connect_to_perl (); |
1198 | _connect_to_perl (); |
1246 | |
1199 | |
1247 | newCONSTSUB (stash_cf, "VERSION", newSVpv (VERSION, sizeof (VERSION) - 1)); |
1200 | newCONSTSUB (stash_cf, "VERSION", newSVpv (VERSION, sizeof (VERSION) - 1)); |
1248 | |
1201 | |
… | |
… | |
1712 | |
1665 | |
1713 | void emergency_save () |
1666 | void emergency_save () |
1714 | |
1667 | |
1715 | void _exit (int status = EXIT_SUCCESS) |
1668 | void _exit (int status = EXIT_SUCCESS) |
1716 | |
1669 | |
1717 | UV sv_2watcher (SV *w) |
|
|
1718 | CODE: |
|
|
1719 | RETVAL = (UV)GEventAPI->sv_2watcher (w); |
|
|
1720 | OUTPUT: |
|
|
1721 | RETVAL |
|
|
1722 | |
|
|
1723 | #if _POSIX_MEMLOCK |
1670 | #if _POSIX_MEMLOCK |
1724 | |
1671 | |
1725 | int mlockall (int flags = MCL_CURRENT | MCL_FUTURE) |
1672 | int mlockall (int flags = MCL_CURRENT | MCL_FUTURE) |
1726 | |
1673 | |
1727 | int munlockall () |
1674 | int munlockall () |