Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/lib/timer.cpp
/* Copyright (C) 2010 Wildfire Games. | /* Copyright (C) 2019 Wildfire Games. | ||||
* | * | ||||
* Permission is hereby granted, free of charge, to any person obtaining | * Permission is hereby granted, free of charge, to any person obtaining | ||||
* a copy of this software and associated documentation files (the | * a copy of this software and associated documentation files (the | ||||
* "Software"), to deal in the Software without restriction, including | * "Software"), to deal in the Software without restriction, including | ||||
* without limitation the rights to use, copy, modify, merge, publish, | * without limitation the rights to use, copy, modify, merge, publish, | ||||
* distribute, sublicense, and/or sell copies of the Software, and to | * distribute, sublicense, and/or sell copies of the Software, and to | ||||
* permit persons to whom the Software is furnished to do so, subject to | * permit persons to whom the Software is furnished to do so, subject to | ||||
* the following conditions: | * the following conditions: | ||||
▲ Show 20 Lines • Show All 67 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