… | |
… | |
21 | # define GvCV_set(gv,cv) GvCV (gv) = cv |
21 | # define GvCV_set(gv,cv) GvCV (gv) = cv |
22 | #endif |
22 | #endif |
23 | |
23 | |
24 | #if EV_ENABLE_ASSERTIONS |
24 | #if EV_ENABLE_ASSERTIONS |
25 | # undef NDEBUG |
25 | # undef NDEBUG |
26 | # include <assert.h> |
26 | #else |
|
|
27 | # define NDEBUG 1 |
27 | #endif |
28 | #endif |
|
|
29 | |
|
|
30 | /* make sure we get a real assert, not perl's incompatible version */ |
|
|
31 | #undef assert |
|
|
32 | #include <assert.h> |
28 | |
33 | |
29 | #define EV_STANDALONE 1 |
34 | #define EV_STANDALONE 1 |
30 | #define EV_PROTOTYPES 1 |
35 | #define EV_PROTOTYPES 1 |
31 | #define EV_USE_NANOSLEEP EV_USE_MONOTONIC |
36 | #define EV_USE_NANOSLEEP EV_USE_MONOTONIC |
32 | #define EV_USE_FLOOR 1 |
37 | #define EV_USE_FLOOR 1 |
… | |
… | |
42 | # define fd_mask Perl_fd_mask |
47 | # define fd_mask Perl_fd_mask |
43 | #endif |
48 | #endif |
44 | /* due to bugs in OS X we have to use libev/ explicitly here */ |
49 | /* due to bugs in OS X we have to use libev/ explicitly here */ |
45 | #include "libev/ev.c" |
50 | #include "libev/ev.c" |
46 | |
51 | |
47 | #if !defined _WIN32 && !defined _MINIX && !EV_NO_ATFORK |
52 | #if !defined _WIN32 && !defined __minix && !EV_NO_ATFORK |
48 | # include <pthread.h> |
53 | # include <pthread.h> |
49 | #endif |
54 | #endif |
50 | |
55 | |
51 | #define e_loop(w) INT2PTR (struct ev_loop *, SvIVX (((ev_watcher *)(w))->loop)) |
56 | #define e_loop(w) INT2PTR (struct ev_loop *, SvIVX (((ev_watcher *)(w))->loop)) |
52 | #define e_flags(w) ((ev_watcher *)(w))->e_flags |
57 | #define e_flags(w) ((ev_watcher *)(w))->e_flags |
… | |
… | |
82 | do { \ |
87 | do { \ |
83 | REF (w); \ |
88 | REF (w); \ |
84 | ev_ ## type ## _stop (e_loop (w), w); \ |
89 | ev_ ## type ## _stop (e_loop (w), w); \ |
85 | } while (0) |
90 | } while (0) |
86 | |
91 | |
|
|
92 | #define PAUSE(type) \ |
|
|
93 | do { \ |
|
|
94 | int active = ev_is_active (w); \ |
|
|
95 | if (active) STOP (type, w) |
|
|
96 | |
|
|
97 | #define RESUME(type) \ |
|
|
98 | if (active) START (type, w); \ |
|
|
99 | } while (0) |
|
|
100 | |
|
|
101 | |
87 | #define RESET(type,w,seta) \ |
102 | #define RESET(type,w,seta) \ |
88 | do { \ |
103 | PAUSE (type); \ |
89 | int active = ev_is_active (w); \ |
|
|
90 | if (active) STOP (type, w); \ |
|
|
91 | ev_ ## type ## _set seta; \ |
104 | ev_ ## type ## _set seta; \ |
92 | if (active) START (type, w); \ |
105 | RESUME (type) |
93 | } while (0) |
|
|
94 | |
106 | |
95 | typedef int Signal; |
107 | typedef int Signal; |
96 | |
108 | |
97 | /* horrible... */ |
109 | /* horrible... */ |
98 | #define CHECK_SIGNAL_CAN_START(w) \ |
110 | #define CHECK_SIGNAL_CAN_START(w) \ |
… | |
… | |
862 | C_ARGS: e_loop (w), w |
874 | C_ARGS: e_loop (w), w |
863 | |
875 | |
864 | void ev_feed_event (ev_watcher *w, int revents = EV_NONE) |
876 | void ev_feed_event (ev_watcher *w, int revents = EV_NONE) |
865 | C_ARGS: e_loop (w), w, revents |
877 | C_ARGS: e_loop (w), w, revents |
866 | |
878 | |
867 | int keepalive (ev_watcher *w, int new_value = 0) |
879 | int keepalive (ev_watcher *w, SV *new_value = NO_INIT) |
868 | CODE: |
880 | CODE: |
869 | { |
881 | { |
870 | RETVAL = w->e_flags & WFLAG_KEEPALIVE; |
882 | RETVAL = w->e_flags & WFLAG_KEEPALIVE; |
871 | new_value = new_value ? WFLAG_KEEPALIVE : 0; |
|
|
872 | |
883 | |
873 | if (items > 1 && ((new_value ^ w->e_flags) & WFLAG_KEEPALIVE)) |
884 | if (items > 1) |
874 | { |
885 | { |
|
|
886 | int value = SvTRUE (new_value) ? WFLAG_KEEPALIVE : 0; |
|
|
887 | |
|
|
888 | if ((value ^ w->e_flags) & WFLAG_KEEPALIVE) |
|
|
889 | { |
875 | w->e_flags = (w->e_flags & ~WFLAG_KEEPALIVE) | new_value; |
890 | w->e_flags = (w->e_flags & ~WFLAG_KEEPALIVE) | value; |
876 | REF (w); |
891 | REF (w); |
877 | UNREF (w); |
892 | UNREF (w); |
|
|
893 | } |
878 | } |
894 | } |
879 | } |
895 | } |
880 | OUTPUT: |
896 | OUTPUT: |
881 | RETVAL |
897 | RETVAL |
882 | |
898 | |
883 | SV *cb (ev_watcher *w, SV *new_cb = 0) |
899 | SV *cb (ev_watcher *w, SV *new_cb = NO_INIT) |
884 | CODE: |
900 | CODE: |
885 | { |
901 | { |
886 | if (items > 1) |
902 | if (items > 1) |
887 | { |
903 | { |
888 | new_cb = s_get_cv_croak (new_cb); |
904 | new_cb = s_get_cv_croak (new_cb); |
… | |
… | |
893 | RETVAL = newRV_inc (w->cb_sv); |
909 | RETVAL = newRV_inc (w->cb_sv); |
894 | } |
910 | } |
895 | OUTPUT: |
911 | OUTPUT: |
896 | RETVAL |
912 | RETVAL |
897 | |
913 | |
898 | SV *data (ev_watcher *w, SV *new_data = 0) |
914 | SV *data (ev_watcher *w, SV *new_data = NO_INIT) |
899 | CODE: |
915 | CODE: |
900 | { |
916 | { |
901 | RETVAL = w->data ? newSVsv (w->data) : &PL_sv_undef; |
917 | RETVAL = w->data ? newSVsv (w->data) : &PL_sv_undef; |
902 | |
918 | |
903 | if (items > 1) |
919 | if (items > 1) |
… | |
… | |
913 | CODE: |
929 | CODE: |
914 | RETVAL = newRV_inc (w->loop); |
930 | RETVAL = newRV_inc (w->loop); |
915 | OUTPUT: |
931 | OUTPUT: |
916 | RETVAL |
932 | RETVAL |
917 | |
933 | |
918 | int priority (ev_watcher *w, int new_priority = 0) |
934 | int priority (ev_watcher *w, SV *new_priority = NO_INIT) |
919 | CODE: |
935 | CODE: |
920 | { |
936 | { |
921 | RETVAL = w->priority; |
937 | RETVAL = w->priority; |
922 | |
938 | |
923 | if (items > 1) |
939 | if (items > 1) |
… | |
… | |
931 | XPUSHs (ST (0)); |
947 | XPUSHs (ST (0)); |
932 | PUTBACK; |
948 | PUTBACK; |
933 | call_method ("stop", G_DISCARD | G_VOID); |
949 | call_method ("stop", G_DISCARD | G_VOID); |
934 | } |
950 | } |
935 | |
951 | |
936 | ev_set_priority (w, new_priority); |
952 | ev_set_priority (w, SvIV (new_priority)); |
937 | |
953 | |
938 | if (active) |
954 | if (active) |
939 | { |
955 | { |
940 | PUSHMARK (SP); |
956 | PUSHMARK (SP); |
941 | XPUSHs (ST (0)); |
957 | XPUSHs (ST (0)); |
… | |
… | |
970 | |
986 | |
971 | sv_setsv (e_fh (w), fh); |
987 | sv_setsv (e_fh (w), fh); |
972 | RESET (io, w, (w, fd, events)); |
988 | RESET (io, w, (w, fd, events)); |
973 | } |
989 | } |
974 | |
990 | |
975 | SV *fh (ev_io *w, SV *new_fh = 0) |
991 | SV *fh (ev_io *w, SV *new_fh = NO_INIT) |
976 | CODE: |
992 | CODE: |
977 | { |
993 | { |
978 | if (items > 1) |
994 | if (items > 1) |
979 | { |
995 | { |
980 | int fd = s_fileno (new_fh, w->events & EV_WRITE); |
996 | int fd = s_fileno (new_fh, w->events & EV_WRITE); |
… | |
… | |
989 | RETVAL = newSVsv (e_fh (w)); |
1005 | RETVAL = newSVsv (e_fh (w)); |
990 | } |
1006 | } |
991 | OUTPUT: |
1007 | OUTPUT: |
992 | RETVAL |
1008 | RETVAL |
993 | |
1009 | |
994 | int events (ev_io *w, int new_events = EV_UNDEF) |
1010 | int events (ev_io *w, int new_events = NO_INIT) |
995 | CODE: |
1011 | CODE: |
996 | { |
1012 | { |
997 | RETVAL = w->events; |
1013 | RETVAL = w->events; |
998 | |
1014 | |
999 | if (items > 1) |
1015 | if (items > 1 && (new_events ^ w->events) & (EV_READ | EV_WRITE)) |
1000 | RESET (io, w, (w, w->fd, new_events)); |
1016 | { |
|
|
1017 | PAUSE (io); |
|
|
1018 | ev_io_modify (w, new_events); |
|
|
1019 | RESUME (io); |
|
|
1020 | } |
1001 | } |
1021 | } |
1002 | OUTPUT: |
1022 | OUTPUT: |
1003 | RETVAL |
1023 | RETVAL |
1004 | |
1024 | |
1005 | MODULE = EV PACKAGE = EV::Signal PREFIX = ev_signal_ |
1025 | MODULE = EV PACKAGE = EV::Signal PREFIX = ev_signal_ |
… | |
… | |
1024 | CHECK_SIG (signal, signum); |
1044 | CHECK_SIG (signal, signum); |
1025 | |
1045 | |
1026 | RESET_SIGNAL (w, (w, signum)); |
1046 | RESET_SIGNAL (w, (w, signum)); |
1027 | } |
1047 | } |
1028 | |
1048 | |
1029 | int signal (ev_signal *w, SV *new_signal = 0) |
1049 | int signal (ev_signal *w, SV *new_signal = NO_INIT) |
1030 | CODE: |
1050 | CODE: |
1031 | { |
1051 | { |
1032 | RETVAL = w->signum; |
1052 | RETVAL = w->signum; |
1033 | |
1053 | |
1034 | if (items > 1) |
1054 | if (items > 1) |
1035 | { |
1055 | { |
1036 | Signal signum = s_signum (new_signal); |
1056 | Signal signum = s_signum (new_signal); |
1037 | CHECK_SIG (new_signal, signum); |
1057 | CHECK_SIG (new_signal, signum); |
1038 | |
|
|
1039 | RESET_SIGNAL (w, (w, signum)); |
1058 | RESET_SIGNAL (w, (w, signum)); |
1040 | } |
1059 | } |
1041 | } |
1060 | } |
1042 | OUTPUT: |
1061 | OUTPUT: |
1043 | RETVAL |
1062 | RETVAL |
… | |
… | |
1054 | CODE: |
1073 | CODE: |
1055 | STOP (timer, w); |
1074 | STOP (timer, w); |
1056 | |
1075 | |
1057 | void ev_timer_again (ev_timer *w, NV repeat = NO_INIT) |
1076 | void ev_timer_again (ev_timer *w, NV repeat = NO_INIT) |
1058 | CODE: |
1077 | CODE: |
|
|
1078 | { |
1059 | if (items > 1) |
1079 | if (items > 1) |
|
|
1080 | { |
|
|
1081 | CHECK_REPEAT (repeat); |
1060 | w->repeat = repeat; |
1082 | w->repeat = repeat; |
1061 | CHECK_REPEAT (w->repeat); |
1083 | } |
|
|
1084 | |
1062 | ev_timer_again (e_loop (w), w); |
1085 | ev_timer_again (e_loop (w), w); |
1063 | UNREF (w); |
1086 | UNREF (w); |
|
|
1087 | } |
1064 | |
1088 | |
1065 | NV ev_timer_remaining (ev_timer *w) |
1089 | NV ev_timer_remaining (ev_timer *w) |
1066 | C_ARGS: e_loop (w), w |
1090 | C_ARGS: e_loop (w), w |
1067 | |
1091 | |
1068 | void DESTROY (ev_timer *w) |
1092 | void DESTROY (ev_timer *w) |
… | |
… | |
1074 | INIT: |
1098 | INIT: |
1075 | CHECK_REPEAT (repeat); |
1099 | CHECK_REPEAT (repeat); |
1076 | CODE: |
1100 | CODE: |
1077 | RESET (timer, w, (w, after, repeat)); |
1101 | RESET (timer, w, (w, after, repeat)); |
1078 | |
1102 | |
|
|
1103 | NV repeat (ev_timer *w, SV *new_repeat = NO_INIT) |
|
|
1104 | CODE: |
|
|
1105 | RETVAL = w->repeat; |
|
|
1106 | if (items > 1) |
|
|
1107 | { |
|
|
1108 | NV repeat = SvNV (new_repeat); |
|
|
1109 | CHECK_REPEAT (repeat); |
|
|
1110 | w->repeat = repeat; |
|
|
1111 | } |
|
|
1112 | OUTPUT: |
|
|
1113 | RETVAL |
|
|
1114 | |
1079 | MODULE = EV PACKAGE = EV::Periodic PREFIX = ev_periodic_ |
1115 | MODULE = EV PACKAGE = EV::Periodic PREFIX = ev_periodic_ |
1080 | |
1116 | |
1081 | void ev_periodic_start (ev_periodic *w) |
1117 | void ev_periodic_start (ev_periodic *w) |
1082 | INIT: |
1118 | INIT: |
1083 | CHECK_REPEAT (w->interval); |
1119 | CHECK_REPEAT (w->interval); |
… | |
… | |
1113 | CODE: |
1149 | CODE: |
1114 | RETVAL = ev_periodic_at (w); |
1150 | RETVAL = ev_periodic_at (w); |
1115 | OUTPUT: |
1151 | OUTPUT: |
1116 | RETVAL |
1152 | RETVAL |
1117 | |
1153 | |
|
|
1154 | NV offset (ev_periodic *w, SV *new_offset = NO_INIT) |
|
|
1155 | CODE: |
|
|
1156 | RETVAL = w->offset; |
|
|
1157 | if (items > 1) |
|
|
1158 | w->offset = SvNV (new_offset); |
|
|
1159 | OUTPUT: |
|
|
1160 | RETVAL |
|
|
1161 | |
|
|
1162 | NV interval (ev_periodic *w, SV *new_interval = NO_INIT) |
|
|
1163 | CODE: |
|
|
1164 | RETVAL = w->interval; |
|
|
1165 | if (items > 1) |
|
|
1166 | { |
|
|
1167 | NV interval = SvNV (new_interval); |
|
|
1168 | CHECK_REPEAT (interval); |
|
|
1169 | w->interval = interval; |
|
|
1170 | } |
|
|
1171 | OUTPUT: |
|
|
1172 | RETVAL |
|
|
1173 | |
|
|
1174 | SV *reschedule_cb (ev_periodic *w, SV *new_reschedule_cb = NO_INIT) |
|
|
1175 | CODE: |
|
|
1176 | RETVAL = e_fh (w) ? e_fh (w) : &PL_sv_undef; |
|
|
1177 | if (items > 1) |
|
|
1178 | { |
|
|
1179 | sv_2mortal (RETVAL); |
|
|
1180 | e_fh (w) = SvTRUE (new_reschedule_cb) ? newSVsv (new_reschedule_cb) : 0; |
|
|
1181 | } |
|
|
1182 | OUTPUT: |
|
|
1183 | RETVAL |
|
|
1184 | |
1118 | MODULE = EV PACKAGE = EV::Idle PREFIX = ev_idle_ |
1185 | MODULE = EV PACKAGE = EV::Idle PREFIX = ev_idle_ |
1119 | |
1186 | |
1120 | void ev_idle_start (ev_idle *w) |
1187 | void ev_idle_start (ev_idle *w) |
1121 | CODE: |
1188 | CODE: |
1122 | START (idle, w); |
1189 | START (idle, w); |
… | |
… | |
1255 | { |
1322 | { |
1256 | sv_setsv (e_fh (w), path); |
1323 | sv_setsv (e_fh (w), path); |
1257 | RESET (stat, w, (w, SvPVbyte_nolen (e_fh (w)), interval)); |
1324 | RESET (stat, w, (w, SvPVbyte_nolen (e_fh (w)), interval)); |
1258 | } |
1325 | } |
1259 | |
1326 | |
1260 | SV *path (ev_stat *w, SV *new_path = 0) |
1327 | SV *path (ev_stat *w, SV *new_path = NO_INIT) |
1261 | CODE: |
1328 | CODE: |
1262 | { |
1329 | { |
1263 | RETVAL = SvREFCNT_inc (e_fh (w)); |
1330 | RETVAL = e_fh (w) ? e_fh (w) : &PL_sv_undef; |
1264 | |
1331 | |
1265 | if (items > 1) |
1332 | if (items > 1) |
1266 | { |
1333 | { |
1267 | SvREFCNT_dec (e_fh (w)); |
1334 | sv_2mortal (RETVAL); |
1268 | e_fh (w) = newSVsv (new_path); |
1335 | e_fh (w) = newSVsv (new_path); |
1269 | RESET (stat, w, (w, SvPVbyte_nolen (e_fh (w)), w->interval)); |
1336 | RESET (stat, w, (w, SvPVbyte_nolen (e_fh (w)), w->interval)); |
1270 | } |
1337 | } |
1271 | } |
1338 | } |
1272 | OUTPUT: |
1339 | OUTPUT: |
1273 | RETVAL |
1340 | RETVAL |
1274 | |
1341 | |
1275 | NV interval (ev_stat *w, NV new_interval = 0.) |
1342 | NV interval (ev_stat *w, SV *new_interval = NO_INIT) |
1276 | CODE: |
1343 | CODE: |
1277 | { |
|
|
1278 | RETVAL = w->interval; |
1344 | RETVAL = w->interval; |
1279 | |
|
|
1280 | if (items > 1) |
1345 | if (items > 1) |
1281 | RESET (stat, w, (w, SvPVbyte_nolen (e_fh (w)), new_interval)); |
1346 | { |
1282 | } |
1347 | PAUSE (stat); |
|
|
1348 | w->interval = SvNV (new_interval); |
|
|
1349 | RESUME (stat); |
|
|
1350 | } |
1283 | OUTPUT: |
1351 | OUTPUT: |
1284 | RETVAL |
1352 | RETVAL |
1285 | |
1353 | |
1286 | void prev (ev_stat *w) |
1354 | void prev (ev_stat *w) |
1287 | ALIAS: |
1355 | ALIAS: |