time: rework of GetLocalTime speedup

Huw D M Davies h.davies1 at physics.ox.ac.uk
Thu Feb 26 13:54:49 CST 2004


	Huw Davies <huw at codeweavers.com>
	Cache the result of TIME_GetBias for upto 1 second.
Index: dlls/ntdll/time.c
===================================================================
RCS file: /home/wine/wine/dlls/ntdll/time.c,v
retrieving revision 1.39
diff -u -r1.39 time.c
--- dlls/ntdll/time.c	26 Feb 2004 05:26:34 -0000	1.39
+++ dlls/ntdll/time.c	26 Feb 2004 19:51:53 -0000
@@ -48,6 +48,16 @@
 
 WINE_DEFAULT_DEBUG_CHANNEL(ntdll);
 
+static CRITICAL_SECTION TIME_GetBias_section;
+static CRITICAL_SECTION_DEBUG critsect_debug =
+{
+    0, 0, &TIME_GetBias_section,
+    { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
+      0, 0, { 0, (DWORD)(__FILE__ ": TIME_GetBias_section") }
+};
+static CRITICAL_SECTION TIME_GetBias_section = { &critsect_debug, -1, 0, 0, 0, 0 };
+
+
 #define SETTIME_MAX_ADJUST 120
 
 /* This structure is used to store strings that represent all of the time zones
@@ -481,11 +491,25 @@
  */
 static int TIME_GetBias(time_t utc, int *pdaylight)
 {
-    struct tm *ptm = localtime(&utc);
-    *pdaylight = ptm->tm_isdst; /* daylight for local timezone */
-    ptm = gmtime(&utc);
-    ptm->tm_isdst = *pdaylight; /* use local daylight, not that of Greenwich */
-    return (int)(utc-mktime(ptm));
+    struct tm *ptm;
+    static time_t last_utc;
+    static int last_bias;
+    int ret;
+
+    RtlEnterCriticalSection( &TIME_GetBias_section );
+    if(utc == last_utc)
+        ret = last_bias;	
+    else
+    {
+        ptm = localtime(&utc);
+	*pdaylight = ptm->tm_isdst; /* daylight for local timezone */
+	ptm = gmtime(&utc);
+	ptm->tm_isdst = *pdaylight; /* use local daylight, not that of Greenwich */
+	last_utc = utc;
+	ret = last_bias = (int)(utc-mktime(ptm));
+    }
+    RtlLeaveCriticalSection( &TIME_GetBias_section );
+    return ret;
 }
 
 /******************************************************************************



More information about the wine-patches mailing list