… | |
… | |
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 | struct ev_watcher_list *head; |
… | |
… | |
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 | |
|
|
251 | #define array_free(stem, idx) \ |
|
|
252 | free (stem ## s idx); stem ## cnt idx = stem ## max idx = 0; |
|
|
253 | |
237 | /*****************************************************************************/ |
254 | /*****************************************************************************/ |
238 | |
255 | |
239 | static void |
256 | static void |
240 | anfds_init (ANFD *base, int count) |
257 | anfds_init (ANFD *base, int count) |
241 | { |
258 | { |
… | |
… | |
306 | for (w = (struct ev_io *)anfd->head; w; w = (struct ev_io *)((WL)w)->next) |
323 | for (w = (struct ev_io *)anfd->head; w; w = (struct ev_io *)((WL)w)->next) |
307 | events |= w->events; |
324 | events |= w->events; |
308 | |
325 | |
309 | anfd->reify = 0; |
326 | anfd->reify = 0; |
310 | |
327 | |
311 | if (anfd->events != events) |
|
|
312 | { |
|
|
313 | method_modify (EV_A_ fd, anfd->events, events); |
328 | method_modify (EV_A_ fd, anfd->events, events); |
314 | anfd->events = events; |
329 | anfd->events = events; |
315 | } |
|
|
316 | } |
330 | } |
317 | |
331 | |
318 | fdchangecnt = 0; |
332 | fdchangecnt = 0; |
319 | } |
333 | } |
320 | |
334 | |
… | |
… | |
456 | } |
470 | } |
457 | |
471 | |
458 | static void |
472 | static void |
459 | sighandler (int signum) |
473 | sighandler (int signum) |
460 | { |
474 | { |
|
|
475 | #if WIN32 |
|
|
476 | signal (signum, sighandler); |
|
|
477 | #endif |
|
|
478 | |
461 | signals [signum - 1].gotsig = 1; |
479 | signals [signum - 1].gotsig = 1; |
462 | |
480 | |
463 | if (!gotsig) |
481 | if (!gotsig) |
464 | { |
482 | { |
465 | int old_errno = errno; |
483 | int old_errno = errno; |
… | |
… | |
637 | } |
655 | } |
638 | |
656 | |
639 | void |
657 | void |
640 | loop_destroy (EV_P) |
658 | loop_destroy (EV_P) |
641 | { |
659 | { |
|
|
660 | int i; |
|
|
661 | |
642 | #if EV_USE_WIN32 |
662 | #if EV_USE_WIN32 |
643 | if (method == EVMETHOD_WIN32 ) win32_destroy (EV_A); |
663 | if (method == EVMETHOD_WIN32 ) win32_destroy (EV_A); |
644 | #endif |
664 | #endif |
645 | #if EV_USE_KQUEUE |
665 | #if EV_USE_KQUEUE |
646 | if (method == EVMETHOD_KQUEUE) kqueue_destroy (EV_A); |
666 | if (method == EVMETHOD_KQUEUE) kqueue_destroy (EV_A); |
… | |
… | |
652 | if (method == EVMETHOD_POLL ) poll_destroy (EV_A); |
672 | if (method == EVMETHOD_POLL ) poll_destroy (EV_A); |
653 | #endif |
673 | #endif |
654 | #if EV_USE_SELECT |
674 | #if EV_USE_SELECT |
655 | if (method == EVMETHOD_SELECT) select_destroy (EV_A); |
675 | if (method == EVMETHOD_SELECT) select_destroy (EV_A); |
656 | #endif |
676 | #endif |
|
|
677 | |
|
|
678 | for (i = NUMPRI; i--; ) |
|
|
679 | array_free (pending, [i]); |
|
|
680 | |
|
|
681 | array_free (fdchange, ); |
|
|
682 | array_free (timer, ); |
|
|
683 | array_free (periodic, ); |
|
|
684 | array_free (idle, ); |
|
|
685 | array_free (prepare, ); |
|
|
686 | array_free (check, ); |
657 | |
687 | |
658 | method = 0; |
688 | method = 0; |
659 | /*TODO*/ |
689 | /*TODO*/ |
660 | } |
690 | } |
661 | |
691 | |
… | |
… | |
796 | ANPENDING *p = pendings [pri] + --pendingcnt [pri]; |
826 | ANPENDING *p = pendings [pri] + --pendingcnt [pri]; |
797 | |
827 | |
798 | if (p->w) |
828 | if (p->w) |
799 | { |
829 | { |
800 | p->w->pending = 0; |
830 | p->w->pending = 0; |
801 | |
|
|
802 | (*(void (**)(EV_P_ W, int))&p->w->cb) (EV_A_ p->w, p->events); |
831 | p->w->cb (EV_A_ p->w, p->events); |
803 | } |
832 | } |
804 | } |
833 | } |
805 | } |
834 | } |
806 | |
835 | |
807 | static void |
836 | static void |
… | |
… | |
1299 | array_needsize (signals, signalmax, w->signum, signals_init); |
1328 | array_needsize (signals, signalmax, w->signum, signals_init); |
1300 | wlist_add ((WL *)&signals [w->signum - 1].head, (WL)w); |
1329 | wlist_add ((WL *)&signals [w->signum - 1].head, (WL)w); |
1301 | |
1330 | |
1302 | if (!((WL)w)->next) |
1331 | if (!((WL)w)->next) |
1303 | { |
1332 | { |
|
|
1333 | #if WIN32 |
|
|
1334 | signal (w->signum, sighandler); |
|
|
1335 | #else |
1304 | struct sigaction sa; |
1336 | struct sigaction sa; |
1305 | sa.sa_handler = sighandler; |
1337 | sa.sa_handler = sighandler; |
1306 | sigfillset (&sa.sa_mask); |
1338 | sigfillset (&sa.sa_mask); |
1307 | sa.sa_flags = SA_RESTART; /* if restarting works we save one iteration */ |
1339 | sa.sa_flags = SA_RESTART; /* if restarting works we save one iteration */ |
1308 | sigaction (w->signum, &sa, 0); |
1340 | sigaction (w->signum, &sa, 0); |
|
|
1341 | #endif |
1309 | } |
1342 | } |
1310 | } |
1343 | } |
1311 | |
1344 | |
1312 | void |
1345 | void |
1313 | ev_signal_stop (EV_P_ struct ev_signal *w) |
1346 | ev_signal_stop (EV_P_ struct ev_signal *w) |