Browse Source

Use uint32_t for carla_gettime_ms

Signed-off-by: falkTX <falktx@falktx.com>
pull/1780/head
falkTX 1 year ago
parent
commit
f5aa43b16f
Signed by: falkTX <falktx@falktx.com> GPG Key ID: CDBAA37ABC74FBA0
1 changed files with 5 additions and 7 deletions
  1. +5
    -7
      source/utils/CarlaTimeUtils.hpp

+ 5
- 7
source/utils/CarlaTimeUtils.hpp View File

@@ -70,20 +70,20 @@ void carla_msleep(const uint msecs) noexcept
* Get a monotonically-increasing time in milliseconds. * Get a monotonically-increasing time in milliseconds.
*/ */
static inline static inline
time_t carla_gettime_ms() noexcept
uint32_t carla_gettime_ms() noexcept
{ {
#if defined(CARLA_OS_MAC) #if defined(CARLA_OS_MAC)
static const time_t s = clock_gettime_nsec_np(CLOCK_UPTIME_RAW) / 1000000; static const time_t s = clock_gettime_nsec_np(CLOCK_UPTIME_RAW) / 1000000;
return (clock_gettime_nsec_np(CLOCK_UPTIME_RAW) / 1000000) - s; return (clock_gettime_nsec_np(CLOCK_UPTIME_RAW) / 1000000) - s;
#elif defined(CARLA_OS_WIN) #elif defined(CARLA_OS_WIN)
return static_cast<time_t>(timeGetTime());
return static_cast<uint32_t>(timeGetTime());
#else #else
static struct { static struct {
timespec ts; timespec ts;
int r; int r;
time_t ms;
} s = { {}, clock_gettime(CLOCK_MONOTONIC, &s.ts), s.ts.tv_sec * 1000 + s.ts.tv_nsec / 1000000 };
uint32_t ms;
} s = { {}, clock_gettime(CLOCK_MONOTONIC, &s.ts), static_cast<uint32_t>(s.ts.tv_sec * 1000 +
s.ts.tv_nsec / 1000000) };
timespec ts; timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts); clock_gettime(CLOCK_MONOTONIC, &ts);
return (ts.tv_sec * 1000 + ts.tv_nsec / 1000000) - s.ms; return (ts.tv_sec * 1000 + ts.tv_nsec / 1000000) - s.ms;
@@ -116,7 +116,6 @@ uint64_t carla_gettime_us() noexcept
uint64_t us; uint64_t us;
} s = { {}, clock_gettime(CLOCK_MONOTONIC, &s.ts), static_cast<uint64_t>(s.ts.tv_sec * 1000000 + } s = { {}, clock_gettime(CLOCK_MONOTONIC, &s.ts), static_cast<uint64_t>(s.ts.tv_sec * 1000000 +
s.ts.tv_nsec / 1000) }; s.ts.tv_nsec / 1000) };

timespec ts; timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts); clock_gettime(CLOCK_MONOTONIC, &ts);
return (ts.tv_sec * 1000000 + ts.tv_nsec / 1000) - s.us; return (ts.tv_sec * 1000000 + ts.tv_nsec / 1000) - s.us;
@@ -149,7 +148,6 @@ uint64_t carla_gettime_ns() noexcept
uint64_t ns; uint64_t ns;
} s = { {}, clock_gettime(CLOCK_MONOTONIC, &s.ts), static_cast<uint64_t>(s.ts.tv_sec * 1000000000ULL + } s = { {}, clock_gettime(CLOCK_MONOTONIC, &s.ts), static_cast<uint64_t>(s.ts.tv_sec * 1000000000ULL +
s.ts.tv_nsec) }; s.ts.tv_nsec) };

timespec ts; timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts); clock_gettime(CLOCK_MONOTONIC, &ts);
return (ts.tv_sec * 1000000000ULL + ts.tv_nsec) - s.ns; return (ts.tv_sec * 1000000000ULL + ts.tv_nsec) - s.ns;


Loading…
Cancel
Save