ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libev/ev.c
(Generate patch)

Comparing libev/ev.c (file contents):
Revision 1.64 by root, Sun Nov 4 23:14:11 2007 UTC vs.
Revision 1.67 by root, Mon Nov 5 16:42:15 2007 UTC

145typedef struct ev_watcher_list *WL; 145typedef struct ev_watcher_list *WL;
146typedef struct ev_watcher_time *WT; 146typedef struct ev_watcher_time *WT;
147 147
148static int have_monotonic; /* did clock_gettime (CLOCK_MONOTONIC) work? */ 148static 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 */
153volatile double SIGFPE_REQ = 0.0f;
154#endif
155
150/*****************************************************************************/ 156/*****************************************************************************/
151 157
152typedef struct 158typedef 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
239static void 256static void
240anfds_init (ANFD *base, int count) 257anfds_init (ANFD *base, int count)
241{ 258{
453} 470}
454 471
455static void 472static void
456sighandler (int signum) 473sighandler (int signum)
457{ 474{
475#if WIN32
476 signal (signum, sighandler);
477#endif
478
458 signals [signum - 1].gotsig = 1; 479 signals [signum - 1].gotsig = 1;
459 480
460 if (!gotsig) 481 if (!gotsig)
461 { 482 {
462 int old_errno = errno; 483 int old_errno = errno;
634} 655}
635 656
636void 657void
637loop_destroy (EV_P) 658loop_destroy (EV_P)
638{ 659{
660 int i;
661
639#if EV_USE_WIN32 662#if EV_USE_WIN32
640 if (method == EVMETHOD_WIN32 ) win32_destroy (EV_A); 663 if (method == EVMETHOD_WIN32 ) win32_destroy (EV_A);
641#endif 664#endif
642#if EV_USE_KQUEUE 665#if EV_USE_KQUEUE
643 if (method == EVMETHOD_KQUEUE) kqueue_destroy (EV_A); 666 if (method == EVMETHOD_KQUEUE) kqueue_destroy (EV_A);
649 if (method == EVMETHOD_POLL ) poll_destroy (EV_A); 672 if (method == EVMETHOD_POLL ) poll_destroy (EV_A);
650#endif 673#endif
651#if EV_USE_SELECT 674#if EV_USE_SELECT
652 if (method == EVMETHOD_SELECT) select_destroy (EV_A); 675 if (method == EVMETHOD_SELECT) select_destroy (EV_A);
653#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, );
654 687
655 method = 0; 688 method = 0;
656 /*TODO*/ 689 /*TODO*/
657} 690}
658 691
793 ANPENDING *p = pendings [pri] + --pendingcnt [pri]; 826 ANPENDING *p = pendings [pri] + --pendingcnt [pri];
794 827
795 if (p->w) 828 if (p->w)
796 { 829 {
797 p->w->pending = 0; 830 p->w->pending = 0;
798
799 (*(void (**)(EV_P_ W, int))&p->w->cb) (EV_A_ p->w, p->events); 831 p->w->cb (EV_A_ p->w, p->events);
800 } 832 }
801 } 833 }
802} 834}
803 835
804static void 836static void
1296 array_needsize (signals, signalmax, w->signum, signals_init); 1328 array_needsize (signals, signalmax, w->signum, signals_init);
1297 wlist_add ((WL *)&signals [w->signum - 1].head, (WL)w); 1329 wlist_add ((WL *)&signals [w->signum - 1].head, (WL)w);
1298 1330
1299 if (!((WL)w)->next) 1331 if (!((WL)w)->next)
1300 { 1332 {
1333#if WIN32
1334 signal (w->signum, sighandler);
1335#else
1301 struct sigaction sa; 1336 struct sigaction sa;
1302 sa.sa_handler = sighandler; 1337 sa.sa_handler = sighandler;
1303 sigfillset (&sa.sa_mask); 1338 sigfillset (&sa.sa_mask);
1304 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 */
1305 sigaction (w->signum, &sa, 0); 1340 sigaction (w->signum, &sa, 0);
1341#endif
1306 } 1342 }
1307} 1343}
1308 1344
1309void 1345void
1310ev_signal_stop (EV_P_ struct ev_signal *w) 1346ev_signal_stop (EV_P_ struct ev_signal *w)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines