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

Comparing libev/ev.c (file contents):
Revision 1.326 by root, Tue Jan 26 04:19:37 2010 UTC vs.
Revision 1.335 by root, Tue Mar 9 09:02:03 2010 UTC

184# define WIN32_LEAN_AND_MEAN 184# define WIN32_LEAN_AND_MEAN
185# include <windows.h> 185# include <windows.h>
186# ifndef EV_SELECT_IS_WINSOCKET 186# ifndef EV_SELECT_IS_WINSOCKET
187# define EV_SELECT_IS_WINSOCKET 1 187# define EV_SELECT_IS_WINSOCKET 1
188# endif 188# endif
189# undef EV_AVOID_STDIO
189#endif 190#endif
190 191
191/* this block tries to deduce configuration from header-defined symbols and defaults */ 192/* this block tries to deduce configuration from header-defined symbols and defaults */
192 193
193/* try to deduce the maximum number of signals on this platform */ 194/* try to deduce the maximum number of signals on this platform */
403# endif 404# endif
404# endif 405# endif
405# ifdef __cplusplus 406# ifdef __cplusplus
406extern "C" { 407extern "C" {
407# endif 408# endif
408int eventfd (unsigned int initval, int flags); 409int (eventfd) (unsigned int initval, int flags);
409# ifdef __cplusplus 410# ifdef __cplusplus
410} 411}
411# endif 412# endif
412#endif 413#endif
413 414
524# include "ev_win32.c" 525# include "ev_win32.c"
525#endif 526#endif
526 527
527/*****************************************************************************/ 528/*****************************************************************************/
528 529
530#if EV_AVOID_STDIO
531static void noinline
532ev_printerr (const char *msg)
533{
534 write (STDERR_FILENO, msg, strlen (msg));
535}
536#endif
537
529static void (*syserr_cb)(const char *msg); 538static void (*syserr_cb)(const char *msg);
530 539
531void 540void
532ev_set_syserr_cb (void (*cb)(const char *msg)) 541ev_set_syserr_cb (void (*cb)(const char *msg))
533{ 542{
542 551
543 if (syserr_cb) 552 if (syserr_cb)
544 syserr_cb (msg); 553 syserr_cb (msg);
545 else 554 else
546 { 555 {
556#if EV_AVOID_STDIO
557 const char *err = strerror (errno);
558
559 ev_printerr (msg);
560 ev_printerr (": ");
561 ev_printerr (err);
562 ev_printerr ("\n");
563#else
547 perror (msg); 564 perror (msg);
565#endif
548 abort (); 566 abort ();
549 } 567 }
550} 568}
551 569
552static void * 570static void *
553ev_realloc_emul (void *ptr, long size) 571ev_realloc_emul (void *ptr, long size)
554{ 572{
573#if __GLIBC__
574 return realloc (ptr, size);
575#else
555 /* some systems, notably openbsd and darwin, fail to properly 576 /* some systems, notably openbsd and darwin, fail to properly
556 * implement realloc (x, 0) (as required by both ansi c-98 and 577 * implement realloc (x, 0) (as required by both ansi c-89 and
557 * the single unix specification, so work around them here. 578 * the single unix specification, so work around them here.
558 */ 579 */
559 580
560 if (size) 581 if (size)
561 return realloc (ptr, size); 582 return realloc (ptr, size);
562 583
563 free (ptr); 584 free (ptr);
564 return 0; 585 return 0;
586#endif
565} 587}
566 588
567static void *(*alloc)(void *ptr, long size) = ev_realloc_emul; 589static void *(*alloc)(void *ptr, long size) = ev_realloc_emul;
568 590
569void 591void
577{ 599{
578 ptr = alloc (ptr, size); 600 ptr = alloc (ptr, size);
579 601
580 if (!ptr && size) 602 if (!ptr && size)
581 { 603 {
604#if EV_AVOID_STDIO
605 ev_printerr ("libev: memory allocation failed, aborting.\n");
606#else
582 fprintf (stderr, "libev: cannot allocate %ld bytes, aborting.", size); 607 fprintf (stderr, "libev: cannot allocate %ld bytes, aborting.", size);
608#endif
583 abort (); 609 abort ();
584 } 610 }
585 611
586 return ptr; 612 return ptr;
587} 613}
2508 2534
2509 if (expect_false (ev_is_active (w))) 2535 if (expect_false (ev_is_active (w)))
2510 return; 2536 return;
2511 2537
2512 assert (("libev: ev_io_start called with negative fd", fd >= 0)); 2538 assert (("libev: ev_io_start called with negative fd", fd >= 0));
2513 assert (("libev: ev_io start called with illegal event mask", !(w->events & ~(EV__IOFDSET | EV_READ | EV_WRITE)))); 2539 assert (("libev: ev_io_start called with illegal event mask", !(w->events & ~(EV__IOFDSET | EV_READ | EV_WRITE))));
2514 2540
2515 EV_FREQUENT_CHECK; 2541 EV_FREQUENT_CHECK;
2516 2542
2517 ev_start (EV_A_ (W)w, 1); 2543 ev_start (EV_A_ (W)w, 1);
2518 array_needsize (ANFD, anfds, anfdmax, fd + 1, array_init_zero); 2544 array_needsize (ANFD, anfds, anfdmax, fd + 1, array_init_zero);
2588 timers [active] = timers [timercnt + HEAP0]; 2614 timers [active] = timers [timercnt + HEAP0];
2589 adjustheap (timers, timercnt, active); 2615 adjustheap (timers, timercnt, active);
2590 } 2616 }
2591 } 2617 }
2592 2618
2593 EV_FREQUENT_CHECK;
2594
2595 ev_at (w) -= mn_now; 2619 ev_at (w) -= mn_now;
2596 2620
2597 ev_stop (EV_A_ (W)w); 2621 ev_stop (EV_A_ (W)w);
2622
2623 EV_FREQUENT_CHECK;
2598} 2624}
2599 2625
2600void noinline 2626void noinline
2601ev_timer_again (EV_P_ ev_timer *w) 2627ev_timer_again (EV_P_ ev_timer *w)
2602{ 2628{
2681 periodics [active] = periodics [periodiccnt + HEAP0]; 2707 periodics [active] = periodics [periodiccnt + HEAP0];
2682 adjustheap (periodics, periodiccnt, active); 2708 adjustheap (periodics, periodiccnt, active);
2683 } 2709 }
2684 } 2710 }
2685 2711
2686 EV_FREQUENT_CHECK;
2687
2688 ev_stop (EV_A_ (W)w); 2712 ev_stop (EV_A_ (W)w);
2713
2714 EV_FREQUENT_CHECK;
2689} 2715}
2690 2716
2691void noinline 2717void noinline
2692ev_periodic_again (EV_P_ ev_periodic *w) 2718ev_periodic_again (EV_P_ ev_periodic *w)
2693{ 2719{
2992 infy_wd (EV_A_ ev->wd, ev->wd, ev); 3018 infy_wd (EV_A_ ev->wd, ev->wd, ev);
2993 ofs += sizeof (struct inotify_event) + ev->len; 3019 ofs += sizeof (struct inotify_event) + ev->len;
2994 } 3020 }
2995} 3021}
2996 3022
3023inline_size unsigned int
3024ev_linux_version (void)
3025{
3026 struct utsname buf;
3027 unsigned int v;
3028 int i;
3029 char *p = buf.release;
3030
3031 if (uname (&buf))
3032 return 0;
3033
3034 for (i = 3+1; --i; )
3035 {
3036 unsigned int c = 0;
3037
3038 for (;;)
3039 {
3040 if (*p >= '0' && *p <= '9')
3041 c = c * 10 + *p++ - '0';
3042 else
3043 {
3044 p += *p == '.';
3045 break;
3046 }
3047 }
3048
3049 v = (v << 8) | c;
3050 }
3051
3052 return v;
3053}
3054
2997inline_size void 3055inline_size void
2998check_2625 (EV_P) 3056ev_check_2625 (EV_P)
2999{ 3057{
3000 /* kernels < 2.6.25 are borked 3058 /* kernels < 2.6.25 are borked
3001 * http://www.ussg.indiana.edu/hypermail/linux/kernel/0711.3/1208.html 3059 * http://www.ussg.indiana.edu/hypermail/linux/kernel/0711.3/1208.html
3002 */ 3060 */
3003 struct utsname buf; 3061 if (ev_linux_version () < 0x020619)
3004 int major, minor, micro;
3005
3006 if (uname (&buf))
3007 return;
3008
3009 if (sscanf (buf.release, "%d.%d.%d", &major, &minor, &micro) != 3)
3010 return;
3011
3012 if (major < 2
3013 || (major == 2 && minor < 6)
3014 || (major == 2 && minor == 6 && micro < 25))
3015 return; 3062 return;
3016 3063
3017 fs_2625 = 1; 3064 fs_2625 = 1;
3018} 3065}
3019 3066
3034 if (fs_fd != -2) 3081 if (fs_fd != -2)
3035 return; 3082 return;
3036 3083
3037 fs_fd = -1; 3084 fs_fd = -1;
3038 3085
3039 check_2625 (EV_A); 3086 ev_check_2625 (EV_A);
3040 3087
3041 fs_fd = infy_newfd (); 3088 fs_fd = infy_newfd ();
3042 3089
3043 if (fs_fd >= 0) 3090 if (fs_fd >= 0)
3044 { 3091 {
3429 3476
3430 ev_io_stop (EV_A_ &w->io); 3477 ev_io_stop (EV_A_ &w->io);
3431 ev_prepare_stop (EV_A_ &w->prepare); 3478 ev_prepare_stop (EV_A_ &w->prepare);
3432 ev_fork_stop (EV_A_ &w->fork); 3479 ev_fork_stop (EV_A_ &w->fork);
3433 3480
3481 ev_stop (EV_A_ (W)w);
3482
3434 EV_FREQUENT_CHECK; 3483 EV_FREQUENT_CHECK;
3435} 3484}
3436#endif 3485#endif
3437 3486
3438#if EV_FORK_ENABLE 3487#if EV_FORK_ENABLE

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines