25#ifndef MY_SYSTIME_INCLUDED
26#define MY_SYSTIME_INCLUDED
47#if !defined(HAVE_CLOCK_GETTIME) || !defined(HAVE_GETTIMEOFDAY)
49using UTC_clock = std::chrono::system_clock;
80inline struct tm *localtime_r(
const time_t *timep,
struct tm *tmp) {
81 localtime_s(tmp, timep);
85inline struct tm *gmtime_r(
const time_t *clock,
struct tm *res) {
95void sleep(
unsigned long seconds);
105#ifdef HAVE_CLOCK_GETTIME
108 clock_gettime(CLOCK_REALTIME, &tp);
109 return (
static_cast<unsigned long long int>(tp.tv_sec) * 10000000 +
110 static_cast<unsigned long long int>(tp.tv_nsec) / 100);
112 return std::chrono::duration_cast<
113 std::chrono::duration<std::int64_t, std::ratio<1, 10000000>>>(
114 UTC_clock::now().time_since_epoch())
124 std::numeric_limits<
decltype(timespec::tv_sec)>::
max(), 999999999};
144 if (ts1->tv_sec > ts2->tv_sec ||
145 (ts1->tv_sec == ts2->tv_sec && ts1->tv_nsec > ts2->tv_nsec))
147 if (ts1->tv_sec < ts2->tv_sec ||
148 (ts1->tv_sec == ts2->tv_sec && ts1->tv_nsec < ts2->tv_nsec))
159 struct timespec *ts2) {
160 return (ts1->tv_sec - ts2->tv_sec) * 1000000000ULL + ts1->tv_nsec -
172[[deprecated]]
inline time_t
my_time(
int) {
return time(
nullptr); }
184#ifdef HAVE_GETTIMEOFDAY
189 while (gettimeofday(&t,
nullptr) != 0) {
191 return (
static_cast<unsigned long long int>(t.tv_sec) * 1000000 + t.tv_usec);
193 return std::chrono::duration_cast<std::chrono::microseconds>(
194 UTC_clock::now().time_since_epoch())
205 tm->
m_tv_sec =
static_cast<int64_t
>(micro_time / 1000000);
206 tm->
m_tv_usec =
static_cast<int64_t
>(micro_time % 1000000);
223 assert(
static_cast<std::int64_t
>(micro_time / 1000000) <=
225 tm->tv_sec =
static_cast<long>(micro_time / 1000000);
226 tm->tv_usec =
static_cast<long>(micro_time % 1000000);
static struct my_cs_file_section_st sec[]
Definition: ctype.cc:168
static int flag
Definition: hp_test1.cc:40
constexpr const int GETDATE_T_DELIMITER
Definition: my_systime.h:62
void set_timespec_nsec(struct timespec *abstime, Timeout_type nsec)
Set the value of a timespec object to the current time plus a number of nanosconds.
Definition: my_systime.cc:67
void my_sleep(int64_t micro_seconds)
Wait a given number of microseconds.
Definition: my_systime.cc:48
time_t my_time(int)
Return current time.
Definition: my_systime.h:172
void get_date(char *to, int flag, time_t date)
Store textual representation of date in a character array.
Definition: my_systime.cc:118
int cmp_timespec(struct timespec *ts1, struct timespec *ts2)
Compare two timespec structs.
Definition: my_systime.h:143
constexpr const timespec TIMESPEC_POSINF
The maximum timespec value used to represent "inifinity" (as when requesting an "infinite" timeout.
Definition: my_systime.h:123
unsigned long long int my_getsystime()
Get high-resolution time.
Definition: my_systime.h:104
constexpr const int GETDATE_GMT
Definition: my_systime.h:60
void my_micro_time_to_timeval(std::uint64_t micro_time, my_timeval *tm)
Convert microseconds since epoch to my_timeval.
Definition: my_systime.h:204
constexpr const int GETDATE_SHORT_DATE_FULL_YEAR
Definition: my_systime.h:63
constexpr const int GETDATE_FIXEDLENGTH
Definition: my_systime.h:61
unsigned long long int diff_timespec(struct timespec *ts1, struct timespec *ts2)
Calculate the diff between two timespec values.
Definition: my_systime.h:158
constexpr const int GETDATE_DATE_TIME
Definition: my_systime.h:57
constexpr const int GETDATE_HHMMSSTIME
Definition: my_systime.h:59
unsigned long long int my_micro_time()
Return time in microseconds.
Definition: my_systime.h:183
void set_timespec(struct timespec *abstime, Timeout_type sec)
Set the value of a timespec object to the current time plus a number of seconds using seconds.
Definition: my_systime.cc:93
constexpr const int GETDATE_SHORT_DATE
Definition: my_systime.h:58
constexpr const Timeout_type TIMEOUT_INF
Value representing "infinite" timeout.
Definition: my_systime.h:130
std::uint64_t Timeout_type
Type alias to reduce chance of conversion errors on timeout values.
Definition: my_systime.h:127
static int count
Definition: myisam_ftdump.cc:45
std::chrono::seconds seconds
Definition: authorize_manager.cc:69
ValueType max(X &&first)
Definition: gtid.h:103
Replacement of system's struct timeval to ensure we can carry 64 bit values even on a platform which ...
Definition: my_time_t.h:45
int64_t m_tv_sec
Definition: my_time_t.h:46
int64_t m_tv_usec
Definition: my_time_t.h:47
Include file for Sun RPC to compile out of the box.