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.68 by root, Mon Nov 5 20:19:00 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 WL head;
155 unsigned char events; 161 unsigned char events;
156 unsigned char reify; 162 unsigned char reify;
157} ANFD; 163} ANFD;
158 164
159typedef struct 165typedef 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
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{
359 int fd; 376 int fd;
360 377
361 for (fd = anfdmax; fd--; ) 378 for (fd = anfdmax; fd--; )
362 if (anfds [fd].events) 379 if (anfds [fd].events)
363 { 380 {
364 close (fd);
365 fd_kill (EV_A_ fd); 381 fd_kill (EV_A_ fd);
366 return; 382 return;
367 } 383 }
368} 384}
369 385
427 443
428/*****************************************************************************/ 444/*****************************************************************************/
429 445
430typedef struct 446typedef struct
431{ 447{
432 struct ev_watcher_list *head; 448 WL head;
433 sig_atomic_t volatile gotsig; 449 sig_atomic_t volatile gotsig;
434} ANSIG; 450} ANSIG;
435 451
436static ANSIG *signals; 452static ANSIG *signals;
437static int signalmax; 453static int signalmax;
453} 469}
454 470
455static void 471static void
456sighandler (int signum) 472sighandler (int signum)
457{ 473{
474#if WIN32
475 signal (signum, sighandler);
476#endif
477
458 signals [signum - 1].gotsig = 1; 478 signals [signum - 1].gotsig = 1;
459 479
460 if (!gotsig) 480 if (!gotsig)
461 { 481 {
462 int old_errno = errno; 482 int old_errno = errno;
467} 487}
468 488
469static void 489static void
470sigcb (EV_P_ struct ev_io *iow, int revents) 490sigcb (EV_P_ struct ev_io *iow, int revents)
471{ 491{
472 struct ev_watcher_list *w; 492 WL w;
473 int signum; 493 int signum;
474 494
475 read (sigpipe [0], &revents, 1); 495 read (sigpipe [0], &revents, 1);
476 gotsig = 0; 496 gotsig = 0;
477 497
634} 654}
635 655
636void 656void
637loop_destroy (EV_P) 657loop_destroy (EV_P)
638{ 658{
659 int i;
660
639#if EV_USE_WIN32 661#if EV_USE_WIN32
640 if (method == EVMETHOD_WIN32 ) win32_destroy (EV_A); 662 if (method == EVMETHOD_WIN32 ) win32_destroy (EV_A);
641#endif 663#endif
642#if EV_USE_KQUEUE 664#if EV_USE_KQUEUE
643 if (method == EVMETHOD_KQUEUE) kqueue_destroy (EV_A); 665 if (method == EVMETHOD_KQUEUE) kqueue_destroy (EV_A);
649 if (method == EVMETHOD_POLL ) poll_destroy (EV_A); 671 if (method == EVMETHOD_POLL ) poll_destroy (EV_A);
650#endif 672#endif
651#if EV_USE_SELECT 673#if EV_USE_SELECT
652 if (method == EVMETHOD_SELECT) select_destroy (EV_A); 674 if (method == EVMETHOD_SELECT) select_destroy (EV_A);
653#endif 675#endif
676
677 for (i = NUMPRI; i--; )
678 array_free (pending, [i]);
679
680 array_free (fdchange, );
681 array_free (timer, );
682 array_free (periodic, );
683 array_free (idle, );
684 array_free (prepare, );
685 array_free (check, );
654 686
655 method = 0; 687 method = 0;
656 /*TODO*/ 688 /*TODO*/
657} 689}
658 690
793 ANPENDING *p = pendings [pri] + --pendingcnt [pri]; 825 ANPENDING *p = pendings [pri] + --pendingcnt [pri];
794 826
795 if (p->w) 827 if (p->w)
796 { 828 {
797 p->w->pending = 0; 829 p->w->pending = 0;
798
799 (*(void (**)(EV_P_ W, int))&p->w->cb) (EV_A_ p->w, p->events); 830 p->w->cb (EV_A_ p->w, p->events);
800 } 831 }
801 } 832 }
802} 833}
803 834
804static void 835static void
1296 array_needsize (signals, signalmax, w->signum, signals_init); 1327 array_needsize (signals, signalmax, w->signum, signals_init);
1297 wlist_add ((WL *)&signals [w->signum - 1].head, (WL)w); 1328 wlist_add ((WL *)&signals [w->signum - 1].head, (WL)w);
1298 1329
1299 if (!((WL)w)->next) 1330 if (!((WL)w)->next)
1300 { 1331 {
1332#if WIN32
1333 signal (w->signum, sighandler);
1334#else
1301 struct sigaction sa; 1335 struct sigaction sa;
1302 sa.sa_handler = sighandler; 1336 sa.sa_handler = sighandler;
1303 sigfillset (&sa.sa_mask); 1337 sigfillset (&sa.sa_mask);
1304 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 */
1305 sigaction (w->signum, &sa, 0); 1339 sigaction (w->signum, &sa, 0);
1340#endif
1306 } 1341 }
1307} 1342}
1308 1343
1309void 1344void
1310ev_signal_stop (EV_P_ struct ev_signal *w) 1345ev_signal_stop (EV_P_ struct ev_signal *w)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines