PISystemTime toTimespec and PIConditionVariable fix

This commit is contained in:
2020-09-25 14:08:40 +03:00
parent d180c0c0dd
commit c3f0cc0b03
3 changed files with 19 additions and 15 deletions

View File

@@ -212,6 +212,13 @@ PIDateTime PIDateTime::current() {
}
void PISystemTime::toTimespec(void * ts) {
#ifndef WINDOWS
t_cur->tv_sec = seconds;
t_cur->tv_nsec = nanoseconds;
#endif
}
PISystemTime PISystemTime::abs() const {
if (seconds < 0)
return PISystemTime(piAbsl(seconds) - 1, 1000000000l - piAbsl(nanoseconds));
@@ -255,12 +262,12 @@ PISystemTime PISystemTime::current(bool precise_but_not_system) {
timeval tv;
tv.tv_sec = 0;
tv.tv_usec = 0;
gettimeofday(&tv, NULL);
gettimeofday(&tv, NULL);
t_cur.tv_sec = tv.tv_sec;
t_cur.tv_nsec = tv.tv_usec * 1000;
# else
timespec t_cur;
clock_gettime(0, &t_cur);
clock_gettime(precise_but_not_system ? CLOCK_MONOTONIC : 0, &t_cur);
# endif
# endif
return PISystemTime(t_cur.tv_sec, t_cur.tv_nsec);

View File

@@ -93,6 +93,8 @@ public:
//! If you call this function on system time returned with \a PISystemTime::current() thread will be sleep almost forever.
void sleep() {piUSleep(piFloord(toMicroseconds()));} // wait self value, useful to wait some dT = (t1 - t0)
//! On Unix system assign current value to timespec struct
void toTimespec(void *ts);
//! Returns copy of this system time with absolutely values of s and ns
PISystemTime abs() const;