Changeset View
Changeset View
Standalone View
Standalone View
source/lib/timer.cpp
Show First 20 Lines • Show All 76 Lines • ▼ Show 20 Lines | #if OS_WIN | ||||
// whrt_Time starts at zero, nothing needs to be done. | // whrt_Time starts at zero, nothing needs to be done. | ||||
#elif HAVE_CLOCK_GETTIME | #elif HAVE_CLOCK_GETTIME | ||||
(void)clock_gettime(CLOCK_REALTIME, &start); | (void)clock_gettime(CLOCK_REALTIME, &start); | ||||
#elif HAVE_GETTIMEOFDAY | #elif HAVE_GETTIMEOFDAY | ||||
gettimeofday(&start, 0); | gettimeofday(&start, 0); | ||||
#endif | #endif | ||||
} | } | ||||
static pthread_mutex_t ensure_monotonic_mutex = PTHREAD_MUTEX_INITIALIZER; | static std::mutex ensure_monotonic_mutex; | ||||
// NB: does not guarantee strict monotonicity - callers must avoid | // NB: does not guarantee strict monotonicity - callers must avoid | ||||
// dividing by the difference of two equal times. | // dividing by the difference of two equal times. | ||||
static void EnsureMonotonic(double& newTime) | static void EnsureMonotonic(double& newTime) | ||||
{ | { | ||||
pthread_mutex_lock(&ensure_monotonic_mutex); | std::lock_guard<std::mutex> lock(ensure_monotonic_mutex); | ||||
static double maxTime; | static double maxTime; | ||||
maxTime = std::max(maxTime, newTime); | maxTime = std::max(maxTime, newTime); | ||||
newTime = maxTime; | newTime = maxTime; | ||||
pthread_mutex_unlock(&ensure_monotonic_mutex); | |||||
} | } | ||||
double timer_Time() | double timer_Time() | ||||
{ | { | ||||
double t; | double t; | ||||
#if OS_WIN | #if OS_WIN | ||||
▲ Show 20 Lines • Show All 133 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator