19 #if !defined USE_QTHREAD
22 using namespace std::chrono;
27 DECLSPEC_KAME
void msecsleep(
unsigned int ms) noexcept;
30 using timestamp_t = uint64_t;
31 DECLSPEC_KAME timestamp_t timeStamp() noexcept;
32 DECLSPEC_KAME timestamp_t timeStampCountsPerMilliSec() noexcept;
36 XTime() noexcept : tv_sec(0), tv_usec(0) {}
37 XTime(
long sec,
long usec) noexcept : tv_sec(sec), tv_usec(usec) {}
38 double operator-(
const XTime &x)
const noexcept {
39 return (tv_sec - x.tv_sec) + (tv_usec - x.tv_usec) * 1e-6;
41 long diff_usec(
const XTime &x)
const noexcept {
42 return (tv_sec - x.tv_sec) * 1000000L + ((tv_usec - x.tv_usec));
44 long diff_msec(
const XTime &x)
const noexcept {
45 return (tv_sec - x.tv_sec) * 1000L + ((tv_usec - x.tv_usec) / 1000L);
47 long diff_sec(
const XTime &x)
const noexcept {
48 return tv_sec - x.tv_sec;
50 XTime &operator+=(
double sec_d) noexcept {
51 long sec = floor(sec_d + tv_sec + 1e-6 * tv_usec);
52 long usec = (lrint(1e6 * (tv_sec - sec + sec_d) + tv_usec));
55 assert((tv_usec >= 0) && (tv_usec < 1000000));
58 XTime &operator-=(
double sec) noexcept {
62 bool operator==(
const XTime &x)
const noexcept {
63 return (tv_sec == x.tv_sec) && (tv_usec == x.tv_usec);
65 bool operator!=(
const XTime &x)
const noexcept {
66 return (tv_sec != x.tv_sec) || (tv_usec != x.tv_usec);
68 bool operator<(
const XTime &x)
const noexcept {
69 return (tv_sec < x.tv_sec) || ((tv_sec == x.tv_sec) && (tv_usec < x.tv_usec));
71 bool operator<=(
const XTime &x)
const noexcept {
72 return (tv_sec <= x.tv_sec) || ((tv_sec == x.tv_sec) && (tv_usec <= x.tv_usec));
74 bool operator>(
const XTime &x)
const noexcept {
75 return (tv_sec > x.tv_sec) || ((tv_sec == x.tv_sec) && (tv_usec > x.tv_usec));
77 bool operator>=(
const XTime &x)
const noexcept {
78 return (tv_sec >= x.tv_sec) || ((tv_sec == x.tv_sec) && (tv_usec >= x.tv_usec));
80 bool operator!()
const noexcept {
81 return (tv_sec == 0) && (tv_usec == 0);
83 operator bool()
const noexcept {
84 return (tv_sec != 0) || (tv_usec != 0);
86 long sec()
const noexcept {
return tv_sec;}
87 long usec()
const noexcept {
return tv_usec;}
88 static XTime now() noexcept;
89 XString getTimeStr(
bool subsecond =
true)
const;
90 XString getTimeFmtStr(
const char *fmt,
bool subsecond =
true)
const
91 #if defined __GNUC__ || defined __clang__
92 __attribute__ ((format(strftime,2, 0)))