[mapguide-commits] r10261 - in branches/4.0/MgDev: Common/MapGuideCommon/Util Portable/MgPortable/System

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Tue Nov 3 04:22:57 PST 2026


Author: jng
Date: 2026-11-03 04:22:56 -0800 (Tue, 03 Nov 2026)
New Revision: 10261

Modified:
   branches/4.0/MgDev/Common/MapGuideCommon/Util/TimerUtil.cpp
   branches/4.0/MgDev/Common/MapGuideCommon/Util/TimerUtil.h
   branches/4.0/MgDev/Portable/MgPortable/System/TimerUtil.cpp
   branches/4.0/MgDev/Portable/MgPortable/System/TimerUtil.h
Log:
Fix concurrent render timing measurements

Use a per-call counter in the server and portable timer utilities to prevent
concurrent calls from overwriting one another's samples. Initialize the
performance-counter frequency safely, and report counter-query failures.

Fixes #2302

Modified: branches/4.0/MgDev/Common/MapGuideCommon/Util/TimerUtil.cpp
===================================================================
--- branches/4.0/MgDev/Common/MapGuideCommon/Util/TimerUtil.cpp	2026-11-03 11:46:51 UTC (rev 10260)
+++ branches/4.0/MgDev/Common/MapGuideCommon/Util/TimerUtil.cpp	2026-11-03 12:22:56 UTC (rev 10261)
@@ -18,13 +18,6 @@
 #include "MapGuideCommon.h"
 #include "TimerUtil.h"
 
-#ifdef WIN32
-LARGE_INTEGER MgTimerUtil::frequency = {0};
-LARGE_INTEGER MgTimerUtil::count = {0};
-#else
-timeval MgTimerUtil::count = {0};
-#endif
-
 ///----------------------------------------------------------------------------
 /// <summary>
 /// Constructs the object.
@@ -54,14 +47,20 @@
 double MgTimerUtil::GetTime()
 {
 #ifdef WIN32
-    if(0 == frequency.QuadPart)
+    static const LARGE_INTEGER frequency = []()
     {
-        GetFrequency(&frequency);
-    }
-    QueryPerformanceCounter(&count);
+        LARGE_INTEGER value;
+        GetFrequency(&value);
+        return value;
+    }();
 
-    return count.QuadPart* (1000.0 / frequency.QuadPart);
+    LARGE_INTEGER count;
+    if (!QueryPerformanceCounter(&count))
+        throw new MgException(MgExceptionCodes::MgUnclassifiedException, L"MgTimerUtil.GetTime", __LINE__, __WFILE__, NULL, L"", NULL);
+
+    return count.QuadPart * (1000.0 / frequency.QuadPart);
 #else
+    timeval count;
     gettimeofday(&count, NULL);
     return (count.tv_sec * 1000.0) + (count.tv_usec / 1000.0);
 #endif

Modified: branches/4.0/MgDev/Common/MapGuideCommon/Util/TimerUtil.h
===================================================================
--- branches/4.0/MgDev/Common/MapGuideCommon/Util/TimerUtil.h	2026-11-03 11:46:51 UTC (rev 10260)
+++ branches/4.0/MgDev/Common/MapGuideCommon/Util/TimerUtil.h	2026-11-03 12:22:56 UTC (rev 10261)
@@ -77,15 +77,6 @@
 
     static void GetFrequency(LARGE_INTEGER* pFrequency);
 #endif
-
-private:
-
-#ifdef WIN32
-    static LARGE_INTEGER frequency;
-    static LARGE_INTEGER count;
-#else
-    static timeval count;
-#endif
 };
 /// \endcond
 

Modified: branches/4.0/MgDev/Portable/MgPortable/System/TimerUtil.cpp
===================================================================
--- branches/4.0/MgDev/Portable/MgPortable/System/TimerUtil.cpp	2026-11-03 11:46:51 UTC (rev 10260)
+++ branches/4.0/MgDev/Portable/MgPortable/System/TimerUtil.cpp	2026-11-03 12:22:56 UTC (rev 10261)
@@ -19,13 +19,6 @@
 #include "MgPortable.h"
 #include "TimerUtil.h"
 
-#ifdef WIN32
-LARGE_INTEGER MgPortableTimerUtil::frequency = {0};
-LARGE_INTEGER MgPortableTimerUtil::count = {0};
-#else
-timeval MgPortableTimerUtil::count = {0};
-#endif
-
 ///----------------------------------------------------------------------------
 /// <summary>
 /// Constructs the object.
@@ -55,14 +48,20 @@
 double MgPortableTimerUtil::GetTime()
 {
 #ifdef WIN32
-    if(0 == frequency.QuadPart)
+    static const LARGE_INTEGER frequency = []()
     {
-        GetFrequency(&frequency);
-    }
-    QueryPerformanceCounter(&count);
+        LARGE_INTEGER value;
+        GetFrequency(&value);
+        return value;
+    }();
 
-    return count.QuadPart* (1000.0 / frequency.QuadPart);
+    LARGE_INTEGER count;
+    if (!QueryPerformanceCounter(&count))
+        throw new MgException(MgExceptionCodes::MgUnclassifiedException, L"MgPortableTimerUtil.GetTime", __LINE__, __WFILE__, NULL, L"", NULL);
+
+    return count.QuadPart * (1000.0 / frequency.QuadPart);
 #else
+    timeval count;
     gettimeofday(&count, NULL);
     return (count.tv_sec * 1000.0) + (count.tv_usec / 1000.0);
 #endif

Modified: branches/4.0/MgDev/Portable/MgPortable/System/TimerUtil.h
===================================================================
--- branches/4.0/MgDev/Portable/MgPortable/System/TimerUtil.h	2026-11-03 11:46:51 UTC (rev 10260)
+++ branches/4.0/MgDev/Portable/MgPortable/System/TimerUtil.h	2026-11-03 12:22:56 UTC (rev 10261)
@@ -77,15 +77,6 @@
 
     static void GetFrequency(LARGE_INTEGER* pFrequency);
 #endif
-
-private:
-
-#ifdef WIN32
-    static LARGE_INTEGER frequency;
-    static LARGE_INTEGER count;
-#else
-    static timeval count;
-#endif
 };
 /// \endcond
 



More information about the mapguide-commits mailing list