24#ifndef MY_SYSTIME_INCLUDED
25#define MY_SYSTIME_INCLUDED
64 std::this_thread::sleep_for(std::chrono::microseconds{m_seconds});
75inline struct tm *localtime_r(
const time_t *timep,
struct tm *tmp) {
76 localtime_s(tmp, timep);
80inline struct tm *gmtime_r(
const time_t *clock,
struct tm *res) {
90inline void sleep(
unsigned long seconds) {
102#ifdef HAVE_CLOCK_GETTIME
105 clock_gettime(CLOCK_REALTIME, &tp);
106 return (
static_cast<unsigned long long int>(tp.tv_sec) * 10000000 +
107 static_cast<unsigned long long int>(tp.tv_nsec) / 100);
109 return std::chrono::duration_cast<
110 std::chrono::duration<std::int64_t, std::ratio<1, 10000000>>>(
111 UTC_clock::now().time_since_epoch())
121 std::numeric_limits<
decltype(timespec::tv_sec)>::max(), 999999999};
128 std::numeric_limits<Timeout_type>::max() - 1;
142 if (ts1->tv_sec > ts2->tv_sec ||
143 (ts1->tv_sec == ts2->tv_sec && ts1->tv_nsec > ts2->tv_nsec))
145 if (ts1->tv_sec < ts2->tv_sec ||
146 (ts1->tv_sec == ts2->tv_sec && ts1->tv_nsec < ts2->tv_nsec))
157 struct timespec *ts2) {
158 return (ts1->tv_sec - ts2->tv_sec) * 1000000000ULL + ts1->tv_nsec -
170[[deprecated]]
inline time_t
my_time(
int) {
return time(
nullptr); }
183 return std::chrono::duration_cast<std::chrono::microseconds>(
184 UTC_clock::now().time_since_epoch())
191 while (gettimeofday(&t,
nullptr) != 0) {
193 return (
static_cast<unsigned long long int>(t.tv_sec) * 1000000 + t.tv_usec);
208 return std::chrono::duration_cast<std::chrono::milliseconds>(
209 UTC_clock::now().time_since_epoch())
216 while (gettimeofday(&t,
nullptr) != 0) {
218 return (
static_cast<unsigned long long int>(t.tv_sec) * 1000 +
229 tm->
m_tv_sec =
static_cast<int64_t
>(micro_time / 1000000);
230 tm->
m_tv_usec =
static_cast<int64_t
>(micro_time % 1000000);
247 assert(
static_cast<std::int64_t
>(micro_time / 1000000) <=
248 std::numeric_limits<long>::max());
249 tm->tv_sec =
static_cast<long>(micro_time / 1000000);
250 tm->tv_usec =
static_cast<long>(micro_time % 1000000);
static struct my_cs_file_section_st sec[]
Definition: ctype.cc:161
static int flag
Definition: hp_test1.cc:39
constexpr const int GETDATE_T_DELIMITER
Definition: my_systime.h:55
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:57
time_t my_time(int)
Return current time.
Definition: my_systime.h:170
void get_date(char *to, int flag, time_t date)
Store textual representation of date in a character array.
Definition: my_systime.cc:108
int cmp_timespec(struct timespec *ts1, struct timespec *ts2)
Compare two timespec structs.
Definition: my_systime.h:141
constexpr const timespec TIMESPEC_POSINF
The maximum timespec value used to represent "inifinity" (as when requesting an "infinite" timeout.
Definition: my_systime.h:120
unsigned long long int my_getsystime()
Get high-resolution time.
Definition: my_systime.h:101
std::chrono::system_clock UTC_clock
Definition: my_systime.h:47
constexpr const int GETDATE_GMT
Definition: my_systime.h:53
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:228
constexpr const int GETDATE_SHORT_DATE_FULL_YEAR
Definition: my_systime.h:56
constexpr const int GETDATE_FIXEDLENGTH
Definition: my_systime.h:54
unsigned long long int my_milli_time()
Return time in milliseconds.
Definition: my_systime.h:206
unsigned long long int diff_timespec(struct timespec *ts1, struct timespec *ts2)
Calculate the diff between two timespec values.
Definition: my_systime.h:156
void my_sleep(time_t m_seconds)
Wait a given number of microseconds.
Definition: my_systime.h:63
constexpr const int GETDATE_DATE_TIME
Definition: my_systime.h:50
constexpr const int GETDATE_HHMMSSTIME
Definition: my_systime.h:52
unsigned long long int my_micro_time()
Return time in microseconds.
Definition: my_systime.h:181
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:83
constexpr const int GETDATE_SHORT_DATE
Definition: my_systime.h:51
constexpr const Timeout_type TIMEOUT_INF
Value representing "infinite" timeout.
Definition: my_systime.h:127
std::uint64_t Timeout_type
Type alias to reduce chance of conversion errors on timeout values.
Definition: my_systime.h:124
static int count
Definition: myisam_ftdump.cc:42
Replacement of system's struct timeval to ensure we can carry 64 bit values even on a platform which ...
Definition: my_time_t.h:44
int64_t m_tv_sec
Definition: my_time_t.h:45
int64_t m_tv_usec
Definition: my_time_t.h:46
double seconds()
Definition: task.cc:309
Include file for Sun RPC to compile out of the box.