Bugzilla bug #39712: work around the /GT bug of MSVC 6.0 SP3.
authorwtc%netscape.com
Tue, 30 May 2000 22:51:39 +0000
changeset 1395 3b32a6650609cbcf71362b8b3244d882190bc80c
parent 1394 4349e461d34b74a562bf71b4e4429b724005e00d
child 1396 5292295526b6f5f4a5212d5a0f45effb9a6b55b0
push idunknown
push userunknown
push dateunknown
bugs39712
Bugzilla bug #39712: work around the /GT bug of MSVC 6.0 SP3. Modified files: WIN32.mk, ntthread.c
config/WIN32.mk
pr/src/md/windows/ntthread.c
--- a/config/WIN32.mk
+++ b/config/WIN32.mk
@@ -48,24 +48,17 @@ XP_DEFINE = -DXP_PC
 OBJ_SUFFIX = obj
 LIB_SUFFIX = lib
 DLL_SUFFIX = dll
 
 OS_CFLAGS = -W3 -nologo -GF -Gy
 
 ifdef BUILD_OPT
 OS_CFLAGS += -MD
-# The -O2 optimization of MSVC 6.0 SP3 appears to generate
-# code that is unsafe for our use of fibers and static thread
-# local storage.  We temporarily work around this problem by
-# turning off global optimizations (-Og).
 OPTIMIZER = -O2
-ifeq ($(OS_TARGET),WINNT)
-OPTIMIZER += -Og-
-endif
 DEFINES = -UDEBUG -U_DEBUG -DNDEBUG
 DLLFLAGS = -OUT:"$@"
 OBJDIR_TAG = _OPT
 
 # Add symbolic information for use by a profiler
 ifdef MOZ_PROFILE
 OPTIMIZER += -Z7
 DLLFLAGS += -DEBUG -DEBUGTYPE:CV
--- a/pr/src/md/windows/ntthread.c
+++ b/pr/src/md/windows/ntthread.c
@@ -425,16 +425,29 @@ void
 _PR_MD_SWITCH_CONTEXT(PRThread *thread)
 {
     PR_ASSERT( !_PR_IS_NATIVE_THREAD(thread) );
 
     thread->md.fiber_last_error = GetLastError();
     _PR_Schedule();
 }
 
+/*
+ * The /GT option of MSVC 6.0 SP3 fails to prevent compiler optimizations
+ * that are unsafe for fibers' access to static thread local storage.
+ * We work around this problem by moving all the code after the
+ * SwitchToFiber() call to a separate function.  (Bugzilla bug #39712)
+ */
+
+static void
+PostSwitchWork(void)
+{
+    POST_SWITCH_WORK();
+}
+
 void
 _PR_MD_RESTORE_CONTEXT(PRThread *thread)
 {
     PRThread *me = _PR_MD_CURRENT_THREAD();
 
     PR_ASSERT( !_PR_IS_NATIVE_THREAD(thread) );
 
     /* The user-level code for yielding will happily add ourselves to the runq
@@ -442,17 +455,26 @@ void
      * ourselves.
      */
     if (thread != me) {
         SetLastError(thread->md.fiber_last_error);
         _MD_SET_CURRENT_THREAD(thread);
         _PR_MD_SET_LAST_THREAD(me);
         thread->no_sched = 1;
         SwitchToFiber(thread->md.fiber_id);
+#if 0
         POST_SWITCH_WORK();
+#else
+        /*
+         * Move the code after SwitchToFiber() to another function so
+         * that it is not jointly optimized with the code before the
+         * SwitchToFiber() call.  See comments before PostSwitchWork().
+         */
+        PostSwitchWork();
+#endif
     }
 }
 
 
 #endif /* HAVE_FIBERS */
 
 PRInt32 _PR_MD_SETTHREADAFFINITYMASK(PRThread *thread, PRUint32 mask )
 {