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

Comparing libev/ev.c (file contents):
Revision 1.502 by root, Tue Jul 2 06:07:54 2019 UTC vs.
Revision 1.505 by root, Wed Jul 10 14:25:35 2019 UTC

457# endif 457# endif
458#endif 458#endif
459 459
460#if EV_USE_IOURING 460#if EV_USE_IOURING
461# include <sys/syscall.h> 461# include <sys/syscall.h>
462# if !__alpha && !SYS_io_uring_setup 462# if !SYS_io_uring_setup && __linux && !__alpha
463# define SYS_io_uring_setup 425 463# define SYS_io_uring_setup 425
464# define SYS_io_uring_enter 426 464# define SYS_io_uring_enter 426
465# define SYS_io_uring_wregister 427 465# define SYS_io_uring_wregister 427
466# endif 466# endif
467# if SYS_io_uring_setup && EV_USE_EPOLL /* iouring backend requires epoll backend */ 467# if SYS_io_uring_setup && EV_USE_EPOLL /* iouring backend requires epoll backend */
536/*#define MIN_INTERVAL 0.00000095367431640625 /* 1/2**20, good till 2200 */ 536/*#define MIN_INTERVAL 0.00000095367431640625 /* 1/2**20, good till 2200 */
537 537
538#define MIN_TIMEJUMP 1. /* minimum timejump that gets detected (if monotonic clock available) */ 538#define MIN_TIMEJUMP 1. /* minimum timejump that gets detected (if monotonic clock available) */
539#define MAX_BLOCKTIME 59.743 /* never wait longer than this time (to detect time jumps) */ 539#define MAX_BLOCKTIME 59.743 /* never wait longer than this time (to detect time jumps) */
540 540
541/* find a portable timestamp that is "alawys" in the future but fits into time_t. 541/* find a portable timestamp that is "always" in the future but fits into time_t.
542 * this is quite hard, and we are mostly guessing - we handle 32 bit signed/unsigned time_t, 542 * this is quite hard, and we are mostly guessing - we handle 32 bit signed/unsigned time_t,
543 * and sizes large than 32 bit, but and maybe the unlikely loating point time_t */ 543 * and sizes larger than 32 bit, and maybe the unlikely floating point time_t */
544#define EV_TSTAMP_HUGE \ 544#define EV_TSTAMP_HUGE \
545 (sizeof (time_t) >= 8 ? 10000000000000. \ 545 (sizeof (time_t) >= 8 ? 10000000000000. \
546 : 0 < (time_t)4294967295 ? 4294967295. \ 546 : 0 < (time_t)4294967295 ? 4294967295. \
547 : 2147483647.) \ 547 : 2147483647.) \
548 548
549#define EV_TV_SET(tv,t) do { tv.tv_sec = (long)t; tv.tv_usec = (long)((t - tv.tv_sec) * 1e6); } while (0) 549#define EV_TV_SET(tv,t) do { tv.tv_sec = (long)t; tv.tv_usec = (long)((t - tv.tv_sec) * 1e6); } while (0)
550#define EV_TS_SET(ts,t) do { ts.tv_sec = (long)t; ts.tv_nsec = (long)((t - ts.tv_sec) * 1e9); } while (0) 550#define EV_TS_SET(ts,t) do { ts.tv_sec = (long)t; ts.tv_nsec = (long)((t - ts.tv_sec) * 1e9); } while (0)
551#define EV_TV_GET(tv) ((tv).tv_sec + (tv).tv_usec * 1e6)
552#define EV_TS_GET(ts) ((ts).tv_sec + (ts).tv_nsec * 1e9)
551 553
552/* the following is ecb.h embedded into libev - use update_ev_c to update from an external copy */ 554/* the following is ecb.h embedded into libev - use update_ev_c to update from an external copy */
553/* ECB.H BEGIN */ 555/* ECB.H BEGIN */
554/* 556/*
555 * libecb - http://software.schmorp.de/pkg/libecb 557 * libecb - http://software.schmorp.de/pkg/libecb
1726 const ev_tstamp shift = sizeof (unsigned long) >= 8 ? 10000000000000000000. : 1000000000.; 1728 const ev_tstamp shift = sizeof (unsigned long) >= 8 ? 10000000000000000000. : 1000000000.;
1727#else 1729#else
1728 const ev_tstamp shift = sizeof (unsigned long) >= 8 ? 18446744073709551616. : 4294967296.; 1730 const ev_tstamp shift = sizeof (unsigned long) >= 8 ? 18446744073709551616. : 4294967296.;
1729#endif 1731#endif
1730 1732
1733 /* special treatment for negative arguments */
1734 if (ecb_expect_false (v < 0.))
1735 {
1736 ev_tstamp f = -ev_floor (-v);
1737
1738 return f - (f == v ? 0 : 1);
1739 }
1740
1731 /* argument too large for an unsigned long? */ 1741 /* argument too large for an unsigned long? then reduce it */
1732 if (ecb_expect_false (v >= shift)) 1742 if (ecb_expect_false (v >= shift))
1733 { 1743 {
1734 ev_tstamp f; 1744 ev_tstamp f;
1735 1745
1736 if (v == v - 1.) 1746 if (v == v - 1.)
1737 return v; /* very large number */ 1747 return v; /* very large numbers are assumed to be integer */
1738 1748
1739 f = shift * ev_floor (v * (1. / shift)); 1749 f = shift * ev_floor (v * (1. / shift));
1740 return f + ev_floor (v - f); 1750 return f + ev_floor (v - f);
1741 }
1742
1743 /* special treatment for negative args? */
1744 if (ecb_expect_false (v < 0.))
1745 {
1746 ev_tstamp f = -ev_floor (-v);
1747
1748 return f - (f == v ? 0 : 1);
1749 } 1751 }
1750 1752
1751 /* fits into an unsigned long */ 1753 /* fits into an unsigned long */
1752 return (unsigned long)v; 1754 return (unsigned long)v;
1753} 1755}
1993#if EV_USE_REALTIME 1995#if EV_USE_REALTIME
1994 if (ecb_expect_true (have_realtime)) 1996 if (ecb_expect_true (have_realtime))
1995 { 1997 {
1996 struct timespec ts; 1998 struct timespec ts;
1997 clock_gettime (CLOCK_REALTIME, &ts); 1999 clock_gettime (CLOCK_REALTIME, &ts);
1998 return ts.tv_sec + ts.tv_nsec * 1e-9; 2000 return EV_TS_GET (ts);
1999 } 2001 }
2000#endif 2002#endif
2001 2003
2002 struct timeval tv; 2004 struct timeval tv;
2003 gettimeofday (&tv, 0); 2005 gettimeofday (&tv, 0);
2004 return tv.tv_sec + tv.tv_usec * 1e-6; 2006 return EV_TV_GET (tv);
2005} 2007}
2006#endif 2008#endif
2007 2009
2008inline_size ev_tstamp 2010inline_size ev_tstamp
2009get_clock (void) 2011get_clock (void)
2011#if EV_USE_MONOTONIC 2013#if EV_USE_MONOTONIC
2012 if (ecb_expect_true (have_monotonic)) 2014 if (ecb_expect_true (have_monotonic))
2013 { 2015 {
2014 struct timespec ts; 2016 struct timespec ts;
2015 clock_gettime (CLOCK_MONOTONIC, &ts); 2017 clock_gettime (CLOCK_MONOTONIC, &ts);
2016 return ts.tv_sec + ts.tv_nsec * 1e-9; 2018 return EV_TS_GET (ts);
2017 } 2019 }
2018#endif 2020#endif
2019 2021
2020 return ev_time (); 2022 return ev_time ();
2021} 2023}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines