ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/EV/EV.xs
(Generate patch)

Comparing EV/EV.xs (file contents):
Revision 1.177 by root, Wed Jan 22 02:10:13 2020 UTC vs.
Revision 1.181 by root, Tue Feb 18 16:49:07 2020 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines