Qt 4.8
Macros | Functions | Variables
qelapsedtimer_unix.cpp File Reference
#include "qelapsedtimer.h"
#include <sys/time.h>
#include <time.h>
#include <unistd.h>

Go to the source code of this file.

Macros

#define is_likely(x)   (x)
 
#define load_acquire(x)   ((volatile const int&)(x))
 
#define store_release(x, v)   ((volatile int&)(x) = (v))
 

Functions

static void do_gettime (qint64 *sec, qint64 *frac)
 
static qint64 elapsedAndRestart (qint64 sec, qint64 frac, qint64 *nowsec, qint64 *nowfrac)
 
static qint64 fractionAdjustment ()
 
bool operator< (const QElapsedTimer &v1, const QElapsedTimer &v2)
 
timeval qt_gettime ()
 
static void unixCheckClockType ()
 

Variables

static int monotonicClockAvailable = false
 
static int monotonicClockChecked = false
 

Macro Definition Documentation

◆ is_likely

#define is_likely (   x)    (x)

Definition at line 72 of file qelapsedtimer_unix.cpp.

Referenced by do_gettime(), and unixCheckClockType().

◆ load_acquire

#define load_acquire (   x)    ((volatile const int&)(x))

Definition at line 74 of file qelapsedtimer_unix.cpp.

Referenced by unixCheckClockType().

◆ store_release

#define store_release (   x,
 
)    ((volatile int&)(x) = (v))

Definition at line 75 of file qelapsedtimer_unix.cpp.

Referenced by unixCheckClockType().

Function Documentation

◆ do_gettime()

static void do_gettime ( qint64 sec,
qint64 frac 
)
inlinestatic

Definition at line 121 of file qelapsedtimer_unix.cpp.

Referenced by elapsedAndRestart(), and qt_gettime().

122 {
123 #if (_POSIX_MONOTONIC_CLOCK-0 >= 0)
126  timespec ts;
127  clock_gettime(CLOCK_MONOTONIC, &ts);
128  *sec = ts.tv_sec;
129  *frac = ts.tv_nsec;
130  return;
131  }
132 #endif
133  // use gettimeofday
134  struct timeval tv;
135  ::gettimeofday(&tv, 0);
136  *sec = tv.tv_sec;
137  *frac = tv.tv_usec;
138 }
static int monotonicClockAvailable
static void unixCheckClockType()
#define is_likely(x)

◆ elapsedAndRestart()

static qint64 elapsedAndRestart ( qint64  sec,
qint64  frac,
qint64 nowsec,
qint64 nowfrac 
)
static

Definition at line 155 of file qelapsedtimer_unix.cpp.

157 {
158  do_gettime(nowsec, nowfrac);
159  sec = *nowsec - sec;
160  frac = *nowfrac - frac;
161  return sec * Q_INT64_C(1000) + frac / fractionAdjustment();
162 }
static qint64 fractionAdjustment()
#define Q_INT64_C(c)
Definition: qglobal.h:940
static void do_gettime(qint64 *sec, qint64 *frac)

◆ fractionAdjustment()

static qint64 fractionAdjustment ( )
inlinestatic

Definition at line 93 of file qelapsedtimer_unix.cpp.

Referenced by elapsedAndRestart().

94 {
95  // disabled, but otherwise indicates bad usage of QElapsedTimer
96  //Q_ASSERT(monotonicClockChecked);
97 
99  // the monotonic timer is measured in nanoseconds
100  // 1 ms = 1000000 ns
101  return 1000*1000ull;
102  } else {
103  // gettimeofday is measured in microseconds
104  // 1 ms = 1000 us
105  return 1000;
106  }
107 }
static int monotonicClockAvailable

◆ operator<()

bool operator< ( const QElapsedTimer v1,
const QElapsedTimer v2 
)

Definition at line 208 of file qelapsedtimer_unix.cpp.

209 {
210  return v1.t1 < v2.t1 || (v1.t1 == v2.t1 && v1.t2 < v2.t2);
211 }

◆ qt_gettime()

timeval qt_gettime ( )

Definition at line 141 of file qelapsedtimer_unix.cpp.

Referenced by qt_safe_select(), QTimerInfoList::QTimerInfoList(), QEventDispatcherBlackberry::select(), time_update(), and QTimerInfoList::updateCurrentTime().

142 {
143  qint64 sec, frac;
144  do_gettime(&sec, &frac);
145 
146  timeval tv;
147  tv.tv_sec = sec;
148  tv.tv_usec = frac;
150  tv.tv_usec /= 1000;
151 
152  return tv;
153 }
static int monotonicClockAvailable
__int64 qint64
Definition: qglobal.h:942
static void do_gettime(qint64 *sec, qint64 *frac)

◆ unixCheckClockType()

static void unixCheckClockType ( )
static

Definition at line 77 of file qelapsedtimer_unix.cpp.

Referenced by do_gettime(), and fractionAdjustment().

78 {
79 #if (_POSIX_MONOTONIC_CLOCK-0 == 0)
81  return;
82 
83 # if defined(_SC_MONOTONIC_CLOCK)
84  // detect if the system support monotonic timers
85  long x = sysconf(_SC_MONOTONIC_CLOCK);
87 # endif
88 
90 #endif
91 }
#define store_release(x, v)
#define load_acquire(x)
static int monotonicClockAvailable
static int monotonicClockChecked
#define is_likely(x)

Variable Documentation

◆ monotonicClockAvailable

int monotonicClockAvailable = false
static

◆ monotonicClockChecked

int monotonicClockChecked = false
static

Definition at line 65 of file qelapsedtimer_unix.cpp.

Referenced by unixCheckClockType().