… | |
… | |
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 |
… | |
… | |
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 | |
2008 | inline_size ev_tstamp |
2010 | inline_size ev_tstamp |
2009 | get_clock (void) |
2011 | get_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 | } |