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

Comparing libev/ev.c (file contents):
Revision 1.278 by root, Tue Jan 6 19:46:56 2009 UTC vs.
Revision 1.279 by root, Fri Feb 6 20:17:43 2009 UTC

64# if HAVE_CLOCK_GETTIME 64# if HAVE_CLOCK_GETTIME
65# ifndef EV_USE_MONOTONIC 65# ifndef EV_USE_MONOTONIC
66# define EV_USE_MONOTONIC 1 66# define EV_USE_MONOTONIC 1
67# endif 67# endif
68# ifndef EV_USE_REALTIME 68# ifndef EV_USE_REALTIME
69# define EV_USE_REALTIME 1 69# define EV_USE_REALTIME 0
70# endif 70# endif
71# else 71# else
72# ifndef EV_USE_MONOTONIC 72# ifndef EV_USE_MONOTONIC
73# define EV_USE_MONOTONIC 0 73# define EV_USE_MONOTONIC 0
74# endif 74# endif
193# define EV_USE_MONOTONIC 0 193# define EV_USE_MONOTONIC 0
194# endif 194# endif
195#endif 195#endif
196 196
197#ifndef EV_USE_REALTIME 197#ifndef EV_USE_REALTIME
198# define EV_USE_REALTIME 0 198# define EV_USE_REALTIME !EV_USE_CLOCK_SYSCALL
199#endif 199#endif
200 200
201#ifndef EV_USE_NANOSLEEP 201#ifndef EV_USE_NANOSLEEP
202# if _POSIX_C_SOURCE >= 199309L 202# if _POSIX_C_SOURCE >= 199309L
203# define EV_USE_NANOSLEEP 1 203# define EV_USE_NANOSLEEP 1
397typedef ev_watcher_time *WT; 397typedef ev_watcher_time *WT;
398 398
399#define ev_active(w) ((W)(w))->active 399#define ev_active(w) ((W)(w))->active
400#define ev_at(w) ((WT)(w))->at 400#define ev_at(w) ((WT)(w))->at
401 401
402#if EV_USE_MONOTONIC 402#if EV_USE_REALTIME
403/* sig_atomic_t is used to avoid per-thread variables or locking but still */ 403/* sig_atomic_t is used to avoid per-thread variables or locking but still */
404/* giving it a reasonably high chance of working on typical architetcures */ 404/* giving it a reasonably high chance of working on typical architetcures */
405static EV_ATOMIC_T have_realtime; /* did clock_gettime (CLOCK_REALTIME) work? */
406#endif
407
408#if EV_USE_MONOTONIC
405static EV_ATOMIC_T have_monotonic; /* did clock_gettime (CLOCK_MONOTONIC) work? */ 409static EV_ATOMIC_T have_monotonic; /* did clock_gettime (CLOCK_MONOTONIC) work? */
406#endif 410#endif
407 411
408#ifdef _WIN32 412#ifdef _WIN32
409# include "ev_win32.c" 413# include "ev_win32.c"
553 557
554ev_tstamp 558ev_tstamp
555ev_time (void) 559ev_time (void)
556{ 560{
557#if EV_USE_REALTIME 561#if EV_USE_REALTIME
562 if (expect_true (have_realtime))
563 {
558 struct timespec ts; 564 struct timespec ts;
559 clock_gettime (CLOCK_REALTIME, &ts); 565 clock_gettime (CLOCK_REALTIME, &ts);
560 return ts.tv_sec + ts.tv_nsec * 1e-9; 566 return ts.tv_sec + ts.tv_nsec * 1e-9;
561#else 567 }
568#endif
569
562 struct timeval tv; 570 struct timeval tv;
563 gettimeofday (&tv, 0); 571 gettimeofday (&tv, 0);
564 return tv.tv_sec + tv.tv_usec * 1e-6; 572 return tv.tv_sec + tv.tv_usec * 1e-6;
565#endif
566} 573}
567 574
568ev_tstamp inline_size 575ev_tstamp inline_size
569get_clock (void) 576get_clock (void)
570{ 577{
1319static void noinline 1326static void noinline
1320loop_init (EV_P_ unsigned int flags) 1327loop_init (EV_P_ unsigned int flags)
1321{ 1328{
1322 if (!backend) 1329 if (!backend)
1323 { 1330 {
1331#if EV_USE_REALTIME
1332 if (!have_realtime)
1333 {
1334 struct timespec ts;
1335
1336 if (!clock_gettime (CLOCK_REALTIME, &ts))
1337 have_realtime = 1;
1338 }
1339#endif
1340
1324#if EV_USE_MONOTONIC 1341#if EV_USE_MONOTONIC
1342 if (!have_monotonic)
1325 { 1343 {
1326 struct timespec ts; 1344 struct timespec ts;
1345
1327 if (!clock_gettime (CLOCK_MONOTONIC, &ts)) 1346 if (!clock_gettime (CLOCK_MONOTONIC, &ts))
1328 have_monotonic = 1; 1347 have_monotonic = 1;
1329 } 1348 }
1330#endif 1349#endif
1331 1350
1332 ev_rt_now = ev_time (); 1351 ev_rt_now = ev_time ();
1333 mn_now = get_clock (); 1352 mn_now = get_clock ();
1334 now_floor = mn_now; 1353 now_floor = mn_now;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines