made frame count atomic

This commit is contained in:
Jack Andersen 2015-07-26 10:55:17 -10:00
parent c61ff288b9
commit 34f2f028a9
2 changed files with 11 additions and 8 deletions

View File

@ -102,7 +102,7 @@ extern std::atomic_size_t ErrorCount;
* The default value is zero, the app is responsible for updating it * The default value is zero, the app is responsible for updating it
* within its main loop. * within its main loop.
*/ */
extern uint64_t FrameIndex; extern std::atomic_uint_fast64_t FrameIndex;
/** /**
* @brief Restore centralized logger vector to default state (silent operation) * @brief Restore centralized logger vector to default state (silent operation)

View File

@ -59,7 +59,7 @@ static std::chrono::steady_clock MonoClock;
static std::chrono::steady_clock::time_point GlobalStart = MonoClock.now(); static std::chrono::steady_clock::time_point GlobalStart = MonoClock.now();
static inline std::chrono::steady_clock::duration CurrentUptime() static inline std::chrono::steady_clock::duration CurrentUptime()
{return MonoClock.now() - GlobalStart;} {return MonoClock.now() - GlobalStart;}
uint64_t FrameIndex = 0; std::atomic_uint_fast64_t FrameIndex(0);
#if _WIN32 #if _WIN32
static HANDLE Term = 0; static HANDLE Term = 0;
@ -143,8 +143,9 @@ struct ConsoleLogger : public ILogger
{ {
fprintf(stderr, BOLD "["); fprintf(stderr, BOLD "[");
fprintf(stderr, GREEN "%5.4f ", tmd); fprintf(stderr, GREEN "%5.4f ", tmd);
if (FrameIndex) uint_fast64_t fIdx = FrameIndex.load();
fprintf(stderr, "(%lu) ", FrameIndex); if (fIdx)
fprintf(stderr, "(%lu) ", fIdx);
switch (severity) switch (severity)
{ {
case Info: case Info:
@ -173,8 +174,9 @@ struct ConsoleLogger : public ILogger
{ {
fprintf(stderr, "["); fprintf(stderr, "[");
fprintf(stderr, "%5.4f ", tmd); fprintf(stderr, "%5.4f ", tmd);
if (FrameIndex) uint_fast64_t fIdx = FrameIndex.load();
fprintf(stderr, "(%lu) ", FrameIndex); if (fIdx)
fprintf(stderr, "(%lu) ", fIdx);
switch (severity) switch (severity)
{ {
case Info: case Info:
@ -300,8 +302,9 @@ struct FileLogger : public ILogger
if (thrName) if (thrName)
fprintf(fp, " (%s)", thrName); fprintf(fp, " (%s)", thrName);
fprintf(fp, " %5.4f", tmd); fprintf(fp, " %5.4f", tmd);
if (FrameIndex) uint_fast64_t fIdx = FrameIndex.load();
fprintf(fp, " (%lu)", FrameIndex); if (fIdx)
fprintf(fp, " (%lu)", fIdx);
fprintf(fp, "] "); fprintf(fp, "] ");
} }