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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines