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

Comparing libev/ev.c (file contents):
Revision 1.327 by root, Sun Feb 14 19:09:04 2010 UTC vs.
Revision 1.331 by root, Tue Mar 9 08:55: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 *
577{ 595{
578 ptr = alloc (ptr, size); 596 ptr = alloc (ptr, size);
579 597
580 if (!ptr && size) 598 if (!ptr && size)
581 { 599 {
600#if EV_AVOID_STDIO
601 ev_printerr ("libev: memory allocation failed, aborting.\n");
602#else
582 fprintf (stderr, "libev: cannot allocate %ld bytes, aborting.", size); 603 fprintf (stderr, "libev: cannot allocate %ld bytes, aborting.", size);
604#endif
583 abort (); 605 abort ();
584 } 606 }
585 607
586 return ptr; 608 return ptr;
587} 609}
2588 timers [active] = timers [timercnt + HEAP0]; 2610 timers [active] = timers [timercnt + HEAP0];
2589 adjustheap (timers, timercnt, active); 2611 adjustheap (timers, timercnt, active);
2590 } 2612 }
2591 } 2613 }
2592 2614
2593 EV_FREQUENT_CHECK;
2594
2595 ev_at (w) -= mn_now; 2615 ev_at (w) -= mn_now;
2596 2616
2597 ev_stop (EV_A_ (W)w); 2617 ev_stop (EV_A_ (W)w);
2618
2619 EV_FREQUENT_CHECK;
2598} 2620}
2599 2621
2600void noinline 2622void noinline
2601ev_timer_again (EV_P_ ev_timer *w) 2623ev_timer_again (EV_P_ ev_timer *w)
2602{ 2624{
2681 periodics [active] = periodics [periodiccnt + HEAP0]; 2703 periodics [active] = periodics [periodiccnt + HEAP0];
2682 adjustheap (periodics, periodiccnt, active); 2704 adjustheap (periodics, periodiccnt, active);
2683 } 2705 }
2684 } 2706 }
2685 2707
2686 EV_FREQUENT_CHECK;
2687
2688 ev_stop (EV_A_ (W)w); 2708 ev_stop (EV_A_ (W)w);
2709
2710 EV_FREQUENT_CHECK;
2689} 2711}
2690 2712
2691void noinline 2713void noinline
2692ev_periodic_again (EV_P_ ev_periodic *w) 2714ev_periodic_again (EV_P_ ev_periodic *w)
2693{ 2715{
2992 infy_wd (EV_A_ ev->wd, ev->wd, ev); 3014 infy_wd (EV_A_ ev->wd, ev->wd, ev);
2993 ofs += sizeof (struct inotify_event) + ev->len; 3015 ofs += sizeof (struct inotify_event) + ev->len;
2994 } 3016 }
2995} 3017}
2996 3018
3019inline_size unsigned int
3020ev_linux_version (void)
3021{
3022 struct utsname buf;
3023 unsigned int v;
3024 int i;
3025 char *p = buf.release;
3026
3027 if (uname (&buf))
3028 return 0;
3029
3030 for (i = 3+1; --i; )
3031 {
3032 unsigned int c = 0;
3033
3034 for (;;)
3035 {
3036 if (*p >= '0' && *p <= '9')
3037 c = c * 10 + *p++ - '0';
3038 else
3039 {
3040 p += *p == '.';
3041 break;
3042 }
3043 }
3044
3045 v = (v << 8) | c;
3046 }
3047
3048 return v;
3049}
3050
2997inline_size void 3051inline_size void
2998check_2625 (EV_P) 3052ev_check_2625 (EV_P)
2999{ 3053{
3000 /* kernels < 2.6.25 are borked 3054 /* kernels < 2.6.25 are borked
3001 * http://www.ussg.indiana.edu/hypermail/linux/kernel/0711.3/1208.html 3055 * http://www.ussg.indiana.edu/hypermail/linux/kernel/0711.3/1208.html
3002 */ 3056 */
3003 struct utsname buf; 3057 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; 3058 return;
3016 3059
3017 fs_2625 = 1; 3060 fs_2625 = 1;
3018} 3061}
3019 3062
3034 if (fs_fd != -2) 3077 if (fs_fd != -2)
3035 return; 3078 return;
3036 3079
3037 fs_fd = -1; 3080 fs_fd = -1;
3038 3081
3039 check_2625 (EV_A); 3082 ev_check_2625 (EV_A);
3040 3083
3041 fs_fd = infy_newfd (); 3084 fs_fd = infy_newfd ();
3042 3085
3043 if (fs_fd >= 0) 3086 if (fs_fd >= 0)
3044 { 3087 {
3429 3472
3430 ev_io_stop (EV_A_ &w->io); 3473 ev_io_stop (EV_A_ &w->io);
3431 ev_prepare_stop (EV_A_ &w->prepare); 3474 ev_prepare_stop (EV_A_ &w->prepare);
3432 ev_fork_stop (EV_A_ &w->fork); 3475 ev_fork_stop (EV_A_ &w->fork);
3433 3476
3477 ev_stop (EV_A_ (W)w);
3478
3434 EV_FREQUENT_CHECK; 3479 EV_FREQUENT_CHECK;
3435} 3480}
3436#endif 3481#endif
3437 3482
3438#if EV_FORK_ENABLE 3483#if EV_FORK_ENABLE

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines