… | |
… | |
145 | typedef struct ev_watcher_list *WL; |
145 | typedef struct ev_watcher_list *WL; |
146 | typedef struct ev_watcher_time *WT; |
146 | typedef struct ev_watcher_time *WT; |
147 | |
147 | |
148 | static int have_monotonic; /* did clock_gettime (CLOCK_MONOTONIC) work? */ |
148 | static int have_monotonic; /* did clock_gettime (CLOCK_MONOTONIC) work? */ |
149 | |
149 | |
|
|
150 | #if WIN32 |
|
|
151 | /* note: the comment below could not be substantiated, but what would I care */ |
|
|
152 | /* MSDN says this is required to handle SIGFPE */ |
|
|
153 | volatile double SIGFPE_REQ = 0.0f; |
|
|
154 | #endif |
|
|
155 | |
150 | /*****************************************************************************/ |
156 | /*****************************************************************************/ |
151 | |
157 | |
152 | typedef struct |
158 | typedef struct |
153 | { |
159 | { |
154 | struct ev_watcher_list *head; |
160 | WL head; |
155 | unsigned char events; |
161 | unsigned char events; |
156 | unsigned char reify; |
162 | unsigned char reify; |
157 | } ANFD; |
163 | } ANFD; |
158 | |
164 | |
159 | typedef struct |
165 | typedef struct |
… | |
… | |
232 | base = realloc (base, sizeof (*base) * (newcnt)); \ |
238 | base = realloc (base, sizeof (*base) * (newcnt)); \ |
233 | init (base + cur, newcnt - cur); \ |
239 | init (base + cur, newcnt - cur); \ |
234 | cur = newcnt; \ |
240 | cur = newcnt; \ |
235 | } |
241 | } |
236 | |
242 | |
|
|
243 | #define array_slim(stem) \ |
|
|
244 | if (stem ## max < array_roundsize (stem ## cnt >> 2)) \ |
|
|
245 | { \ |
|
|
246 | stem ## max = array_roundsize (stem ## cnt >> 1); \ |
|
|
247 | base = realloc (base, sizeof (*base) * (stem ## max)); \ |
|
|
248 | fprintf (stderr, "slimmed down " # stem " to %d\n", stem ## max);/*D*/\ |
|
|
249 | } |
|
|
250 | |
237 | #define array_free(stem, idx) \ |
251 | #define array_free(stem, idx) \ |
238 | free (stem ## s idx); stem ## cnt idx = stem ## max idx = 0; |
252 | free (stem ## s idx); stem ## cnt idx = stem ## max idx = 0; |
239 | |
253 | |
240 | /*****************************************************************************/ |
254 | /*****************************************************************************/ |
241 | |
255 | |
… | |
… | |
362 | int fd; |
376 | int fd; |
363 | |
377 | |
364 | for (fd = anfdmax; fd--; ) |
378 | for (fd = anfdmax; fd--; ) |
365 | if (anfds [fd].events) |
379 | if (anfds [fd].events) |
366 | { |
380 | { |
367 | close (fd); |
|
|
368 | fd_kill (EV_A_ fd); |
381 | fd_kill (EV_A_ fd); |
369 | return; |
382 | return; |
370 | } |
383 | } |
371 | } |
384 | } |
372 | |
385 | |
… | |
… | |
430 | |
443 | |
431 | /*****************************************************************************/ |
444 | /*****************************************************************************/ |
432 | |
445 | |
433 | typedef struct |
446 | typedef struct |
434 | { |
447 | { |
435 | struct ev_watcher_list *head; |
448 | WL head; |
436 | sig_atomic_t volatile gotsig; |
449 | sig_atomic_t volatile gotsig; |
437 | } ANSIG; |
450 | } ANSIG; |
438 | |
451 | |
439 | static ANSIG *signals; |
452 | static ANSIG *signals; |
440 | static int signalmax; |
453 | static int signalmax; |
… | |
… | |
456 | } |
469 | } |
457 | |
470 | |
458 | static void |
471 | static void |
459 | sighandler (int signum) |
472 | sighandler (int signum) |
460 | { |
473 | { |
|
|
474 | #if WIN32 |
|
|
475 | signal (signum, sighandler); |
|
|
476 | #endif |
|
|
477 | |
461 | signals [signum - 1].gotsig = 1; |
478 | signals [signum - 1].gotsig = 1; |
462 | |
479 | |
463 | if (!gotsig) |
480 | if (!gotsig) |
464 | { |
481 | { |
465 | int old_errno = errno; |
482 | int old_errno = errno; |
… | |
… | |
470 | } |
487 | } |
471 | |
488 | |
472 | static void |
489 | static void |
473 | sigcb (EV_P_ struct ev_io *iow, int revents) |
490 | sigcb (EV_P_ struct ev_io *iow, int revents) |
474 | { |
491 | { |
475 | struct ev_watcher_list *w; |
492 | WL w; |
476 | int signum; |
493 | int signum; |
477 | |
494 | |
478 | read (sigpipe [0], &revents, 1); |
495 | read (sigpipe [0], &revents, 1); |
479 | gotsig = 0; |
496 | gotsig = 0; |
480 | |
497 | |
… | |
… | |
808 | ANPENDING *p = pendings [pri] + --pendingcnt [pri]; |
825 | ANPENDING *p = pendings [pri] + --pendingcnt [pri]; |
809 | |
826 | |
810 | if (p->w) |
827 | if (p->w) |
811 | { |
828 | { |
812 | p->w->pending = 0; |
829 | p->w->pending = 0; |
813 | |
|
|
814 | ((void (*)(EV_P_ W, int))p->w->cb) (EV_A_ p->w, p->events); |
830 | p->w->cb (EV_A_ p->w, p->events); |
815 | } |
831 | } |
816 | } |
832 | } |
817 | } |
833 | } |
818 | |
834 | |
819 | static void |
835 | static void |
… | |
… | |
1311 | array_needsize (signals, signalmax, w->signum, signals_init); |
1327 | array_needsize (signals, signalmax, w->signum, signals_init); |
1312 | wlist_add ((WL *)&signals [w->signum - 1].head, (WL)w); |
1328 | wlist_add ((WL *)&signals [w->signum - 1].head, (WL)w); |
1313 | |
1329 | |
1314 | if (!((WL)w)->next) |
1330 | if (!((WL)w)->next) |
1315 | { |
1331 | { |
|
|
1332 | #if WIN32 |
|
|
1333 | signal (w->signum, sighandler); |
|
|
1334 | #else |
1316 | struct sigaction sa; |
1335 | struct sigaction sa; |
1317 | sa.sa_handler = sighandler; |
1336 | sa.sa_handler = sighandler; |
1318 | sigfillset (&sa.sa_mask); |
1337 | sigfillset (&sa.sa_mask); |
1319 | sa.sa_flags = SA_RESTART; /* if restarting works we save one iteration */ |
1338 | sa.sa_flags = SA_RESTART; /* if restarting works we save one iteration */ |
1320 | sigaction (w->signum, &sa, 0); |
1339 | sigaction (w->signum, &sa, 0); |
|
|
1340 | #endif |
1321 | } |
1341 | } |
1322 | } |
1342 | } |
1323 | |
1343 | |
1324 | void |
1344 | void |
1325 | ev_signal_stop (EV_P_ struct ev_signal *w) |
1345 | ev_signal_stop (EV_P_ struct ev_signal *w) |