Bugzilla bug 121975: allow the WIN95 version of NSPR to use static TLS when
authorwtc%netscape.com
Fri, 29 Mar 2002 21:51:45 +0000
changeset 2314 ba1e15124cafee02200f08605d82afab11c62da9
parent 2313 77cd1954201eaf12fa773584a61547d9f4e2d5f0
child 2315 7a43a7a1f5aebe9dcdab1037582d8521474cb2da
push idunknown
push userunknown
push dateunknown
bugs121975
Bugzilla bug 121975: allow the WIN95 version of NSPR to use static TLS when possible. Thanks to Daniel Bratell <bratell@lysator.liu.se> for suggesting this change and performing the measurements to show its improvement. Modified files: configure configure.in WIN32.mk _win95.h w95dllmain.c w95thred.c
config/WIN32.mk
configure
configure.in
pr/include/md/_win95.h
pr/src/md/windows/w95dllmain.c
pr/src/md/windows/w95thred.c
--- a/config/WIN32.mk
+++ b/config/WIN32.mk
@@ -111,26 +111,16 @@ ifdef PROFILE
 LDFLAGS += -PROFILE -MAP
 DLLFLAGS += -PROFILE -MAP
 endif
 endif
 
 DEFINES += -DWIN32
 
 #
-# On Win95, we use the TlsXXX() interface by default because that
-# allows us to load the NSPR DLL dynamically at run time.
-# If you want to use static thread-local storage (TLS) for better
-# performance, build the NSPR library with USE_STATIC_TLS=1.
-#
-ifeq ($(USE_STATIC_TLS),1)
-DEFINES += -D_PR_USE_STATIC_TLS
-endif
-
-#
 # NSPR uses both fibers and static thread-local storage
 # (i.e., __declspec(thread) variables) on NT.  We need the -GT
 # flag to turn off certain compiler optimizations so that fibers
 # can use static TLS safely.
 #
 # Also, we optimize for Pentium (-G5) on NT.
 #
 ifeq ($(OS_TARGET),WINNT)
--- a/configure
+++ b/configure
@@ -3782,23 +3782,16 @@ EOF
             LIBNSPR='$(dist_libdir)/libnspr$(MOD_MAJOR_VERSION).$(LIB_SUFFIX)'
             LIBPLC='$(dist_libdir)/libplc$(MOD_MAJOR_VERSION).$(LIB_SUFFIX)'
         else
             LIBNSPR='$(dist_libdir)/nspr$(MOD_MAJOR_VERSION).$(LIB_SUFFIX)'
             LIBPLC='$(dist_libdir)/plc$(MOD_MAJOR_VERSION).$(LIB_SUFFIX)'
         fi
     fi # GNU_CC
 
-    if test -n "$USE_STATIC_TLS"; then
-        cat >> confdefs.h <<\EOF
-#define _PR_USE_STATIC_TLS 1
-EOF
-
-    fi
-
     if test "$OS_TARGET" = "WINNT"; then
         cat >> confdefs.h <<\EOF
 #define WINNT 1
 EOF
 
     else
         cat >> confdefs.h <<\EOF
 #define WIN95 1
@@ -4145,27 +4138,27 @@ EOF
 EOF
 
     cat >> confdefs.h <<\EOF
 #define _REENTRANT 1
 EOF
 
     ac_safe=`echo "machine/builtins.h" | sed 'y%./+-%__p_%'`
 echo $ac_n "checking for machine/builtins.h""... $ac_c" 1>&6
-echo "configure:4154: checking for machine/builtins.h" >&5
+echo "configure:4147: checking for machine/builtins.h" >&5
 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 4159 "configure"
+#line 4152 "configure"
 #include "confdefs.h"
 #include <machine/builtins.h>
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:4164: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:4157: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
 ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
 if test -z "$ac_err"; then
   rm -rf conftest*
   eval "ac_cv_header_$ac_safe=yes"
 else
   echo "$ac_err" >&5
   echo "configure: failed program was:" >&5
   cat conftest.$ac_ext >&5
@@ -4670,22 +4663,22 @@ EOF
 
     ;;
    
 esac
 
 if test -z "$SKIP_LIBRARY_CHECKS"; then
 
 echo $ac_n "checking for dlopen""... $ac_c" 1>&6
-echo "configure:4679: checking for dlopen" >&5
+echo "configure:4672: checking for dlopen" >&5
 if eval "test \"`echo '$''{'ac_cv_func_dlopen'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 4684 "configure"
+#line 4677 "configure"
 #include "confdefs.h"
 /* System header to define __stub macros and hopefully few prototypes,
     which can conflict with char dlopen(); below.  */
 #include <assert.h>
 /* Override any gcc2 internal prototype to avoid an error.  */
 /* We use char because int might match the return type of a gcc2
     builtin and then its argument prototype would still apply.  */
 char dlopen();
@@ -4698,17 +4691,17 @@ int main() {
 #if defined (__stub_dlopen) || defined (__stub___dlopen)
 choke me
 #else
 dlopen();
 #endif
 
 ; return 0; }
 EOF
-if { (eval echo configure:4707: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:4700: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
   rm -rf conftest*
   eval "ac_cv_func_dlopen=yes"
 else
   echo "configure: failed program was:" >&5
   cat conftest.$ac_ext >&5
   rm -rf conftest*
   eval "ac_cv_func_dlopen=no"
 fi
@@ -4717,36 +4710,36 @@ fi
 
 if eval "test \"`echo '$ac_cv_func_'dlopen`\" = yes"; then
   echo "$ac_t""yes" 1>&6
   :
 else
   echo "$ac_t""no" 1>&6
 
     echo $ac_n "checking for dlopen in -ldl""... $ac_c" 1>&6
-echo "configure:4726: checking for dlopen in -ldl" >&5
+echo "configure:4719: checking for dlopen in -ldl" >&5
 ac_lib_var=`echo dl'_'dlopen | sed 'y%./+-%__p_%'`
 if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   ac_save_LIBS="$LIBS"
 LIBS="-ldl  $LIBS"
 cat > conftest.$ac_ext <<EOF
-#line 4734 "configure"
+#line 4727 "configure"
 #include "confdefs.h"
 /* Override any gcc2 internal prototype to avoid an error.  */
 /* We use char because int might match the return type of a gcc2
     builtin and then its argument prototype would still apply.  */
 char dlopen();
 
 int main() {
 dlopen()
 ; return 0; }
 EOF
-if { (eval echo configure:4745: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:4738: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
   rm -rf conftest*
   eval "ac_cv_lib_$ac_lib_var=yes"
 else
   echo "configure: failed program was:" >&5
   cat conftest.$ac_ext >&5
   rm -rf conftest*
   eval "ac_cv_lib_$ac_lib_var=no"
 fi
@@ -4764,23 +4757,23 @@ fi
 
 fi
 
 
 
 
 if test $ac_cv_prog_gcc = yes; then
     echo $ac_n "checking whether ${CC-cc} needs -traditional""... $ac_c" 1>&6
-echo "configure:4773: checking whether ${CC-cc} needs -traditional" >&5
+echo "configure:4766: checking whether ${CC-cc} needs -traditional" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_gcc_traditional'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
     ac_pattern="Autoconf.*'x'"
   cat > conftest.$ac_ext <<EOF
-#line 4779 "configure"
+#line 4772 "configure"
 #include "confdefs.h"
 #include <sgtty.h>
 Autoconf TIOCGETP
 EOF
 if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
   egrep "$ac_pattern" >/dev/null 2>&1; then
   rm -rf conftest*
   ac_cv_prog_gcc_traditional=yes
@@ -4788,17 +4781,17 @@ else
   rm -rf conftest*
   ac_cv_prog_gcc_traditional=no
 fi
 rm -f conftest*
 
 
   if test $ac_cv_prog_gcc_traditional = no; then
     cat > conftest.$ac_ext <<EOF
-#line 4797 "configure"
+#line 4790 "configure"
 #include "confdefs.h"
 #include <termio.h>
 Autoconf TCGETA
 EOF
 if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
   egrep "$ac_pattern" >/dev/null 2>&1; then
   rm -rf conftest*
   ac_cv_prog_gcc_traditional=yes
@@ -4812,22 +4805,22 @@ echo "$ac_t""$ac_cv_prog_gcc_traditional
   if test $ac_cv_prog_gcc_traditional = yes; then
     CC="$CC -traditional"
   fi
 fi
 
 for ac_func in lchown strerror
 do
 echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
-echo "configure:4821: checking for $ac_func" >&5
+echo "configure:4814: checking for $ac_func" >&5
 if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 4826 "configure"
+#line 4819 "configure"
 #include "confdefs.h"
 /* System header to define __stub macros and hopefully few prototypes,
     which can conflict with char $ac_func(); below.  */
 #include <assert.h>
 /* Override any gcc2 internal prototype to avoid an error.  */
 /* We use char because int might match the return type of a gcc2
     builtin and then its argument prototype would still apply.  */
 char $ac_func();
@@ -4840,17 +4833,17 @@ int main() {
 #if defined (__stub_$ac_func) || defined (__stub___$ac_func)
 choke me
 #else
 $ac_func();
 #endif
 
 ; return 0; }
 EOF
-if { (eval echo configure:4849: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:4842: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
   rm -rf conftest*
   eval "ac_cv_func_$ac_func=yes"
 else
   echo "configure: failed program was:" >&5
   cat conftest.$ac_ext >&5
   rm -rf conftest*
   eval "ac_cv_func_$ac_func=no"
 fi
@@ -4878,17 +4871,17 @@ if test "${enable_strip+set}" = set; the
    ENABLE_STRIP=1 
 fi
 
 
 
 
 
 echo $ac_n "checking for pthread_create in -lpthreads""... $ac_c" 1>&6
-echo "configure:4887: checking for pthread_create in -lpthreads" >&5
+echo "configure:4880: checking for pthread_create in -lpthreads" >&5
 echo "
     #include <pthread.h> 
     void *foo(void *v) { int a = 1;  } 
     int main() { 
         pthread_t t;
         if (!pthread_create(&t, 0, &foo, 0)) {
             pthread_join(t, 0);
         }
@@ -4900,17 +4893,17 @@ echo "
     rm -f dummy.c dummy${ac_exeext} ;
     if test "$_res" = "0"; then
         echo "$ac_t""yes" 1>&6
         _HAVE_PTHREADS=1 _PTHREAD_LDFLAGS="-lpthreads"
     else
         echo "$ac_t""no" 1>&6
         
 echo $ac_n "checking for pthread_create in -lpthread""... $ac_c" 1>&6
-echo "configure:4909: checking for pthread_create in -lpthread" >&5
+echo "configure:4902: checking for pthread_create in -lpthread" >&5
 echo "
     #include <pthread.h> 
     void *foo(void *v) { int a = 1;  } 
     int main() { 
         pthread_t t;
         if (!pthread_create(&t, 0, &foo, 0)) {
             pthread_join(t, 0);
         }
@@ -4922,17 +4915,17 @@ echo "
     rm -f dummy.c dummy${ac_exeext} ;
     if test "$_res" = "0"; then
         echo "$ac_t""yes" 1>&6
         _HAVE_PTHREADS=1 _PTHREAD_LDFLAGS="-lpthread"
     else
         echo "$ac_t""no" 1>&6
         
 echo $ac_n "checking for pthread_create in -lc_r""... $ac_c" 1>&6
-echo "configure:4931: checking for pthread_create in -lc_r" >&5
+echo "configure:4924: checking for pthread_create in -lc_r" >&5
 echo "
     #include <pthread.h> 
     void *foo(void *v) { int a = 1;  } 
     int main() { 
         pthread_t t;
         if (!pthread_create(&t, 0, &foo, 0)) {
             pthread_join(t, 0);
         }
@@ -4944,17 +4937,17 @@ echo "
     rm -f dummy.c dummy${ac_exeext} ;
     if test "$_res" = "0"; then
         echo "$ac_t""yes" 1>&6
         _HAVE_PTHREADS=1 _PTHREAD_LDFLAGS="-lc_r"
     else
         echo "$ac_t""no" 1>&6
         
 echo $ac_n "checking for pthread_create in -lc""... $ac_c" 1>&6
-echo "configure:4953: checking for pthread_create in -lc" >&5
+echo "configure:4946: checking for pthread_create in -lc" >&5
 echo "
     #include <pthread.h> 
     void *foo(void *v) { int a = 1;  } 
     int main() { 
         pthread_t t;
         if (!pthread_create(&t, 0, &foo, 0)) {
             pthread_join(t, 0);
         }
@@ -5094,17 +5087,17 @@ EOF
     fi
 fi
 
 
 if test -n "$USE_PTHREADS"; then
       rm -f conftest*
    ac_cv_have_dash_pthread=no
    echo $ac_n "checking whether ${CC-cc} accepts -pthread""... $ac_c" 1>&6
-echo "configure:5103: checking whether ${CC-cc} accepts -pthread" >&5
+echo "configure:5096: checking whether ${CC-cc} accepts -pthread" >&5
    echo 'int main() { return 0; }' | cat > conftest.c
    ${CC-cc} -pthread -o conftest conftest.c > conftest.out 2>&1
    if test $? -eq 0; then
 	if test -z "`egrep -i '(unrecognize|unknown)' conftest.out | grep pthread`" && test -z "`egrep -i '(error|incorrect)' conftest.out`" ; then
 	    ac_cv_have_dash_pthread=yes
 		case "$target_os" in
 	    freebsd*)
 # Freebsd doesn't use -pthread for compiles, it uses them for linking
@@ -5117,17 +5110,17 @@ echo "configure:5103: checking whether $
 	fi
     fi
     rm -f conftest*
     echo "$ac_t""$ac_cv_have_dash_pthread" 1>&6
 
 			    ac_cv_have_dash_pthreads=no
     if test "$ac_cv_have_dash_pthread" = "no"; then
 	    echo $ac_n "checking whether ${CC-cc} accepts -pthreads""... $ac_c" 1>&6
-echo "configure:5126: checking whether ${CC-cc} accepts -pthreads" >&5
+echo "configure:5119: checking whether ${CC-cc} accepts -pthreads" >&5
     	echo 'int main() { return 0; }' | cat > conftest.c
 	    ${CC-cc} -pthreads -o conftest conftest.c > conftest.out 2>&1
     	if test $? -eq 0; then
 	    	if test -z "`egrep -i '(unrecognize|unknown)' conftest.out | grep pthreads`" && test -z "`egrep -i '(error|incorrect)' conftest.out`" ; then
 			    ac_cv_have_dash_pthreads=yes
 			    CFLAGS="$CFLAGS -pthreads"
 			    CXXFLAGS="$CXXFLAGS -pthreads"
 		    fi
--- a/configure.in
+++ b/configure.in
@@ -1233,20 +1233,16 @@ case "$target" in
             LIBNSPR='$(dist_libdir)/libnspr$(MOD_MAJOR_VERSION).$(LIB_SUFFIX)'
             LIBPLC='$(dist_libdir)/libplc$(MOD_MAJOR_VERSION).$(LIB_SUFFIX)'
         else
             LIBNSPR='$(dist_libdir)/nspr$(MOD_MAJOR_VERSION).$(LIB_SUFFIX)'
             LIBPLC='$(dist_libdir)/plc$(MOD_MAJOR_VERSION).$(LIB_SUFFIX)'
         fi
     fi # GNU_CC
 
-    if test -n "$USE_STATIC_TLS"; then
-        AC_DEFINE(_PR_USE_STATIC_TLS)
-    fi
-
     if test "$OS_TARGET" = "WINNT"; then
         AC_DEFINE(WINNT)
     else
         AC_DEFINE(WIN95)
         AC_DEFINE(_PR_GLOBAL_THREADS_ONLY)
     fi
 
     if test "$CPU_ARCH" = "x86"; then
--- a/pr/include/md/_win95.h
+++ b/pr/include/md/_win95.h
@@ -404,41 +404,65 @@ extern PRStatus _PR_KillWindowsProcess(s
 #define _MD_INTERVAL_PER_SEC              _PR_MD_INTERVAL_PER_SEC
 #define _MD_INTERVAL_PER_MILLISEC()       (_PR_MD_INTERVAL_PER_SEC() / 1000)
 #define _MD_INTERVAL_PER_MICROSEC()       (_PR_MD_INTERVAL_PER_SEC() / 1000000)
 
 /* --- Native-Thread Specific Definitions ------------------------------- */
 
 extern struct PRThread * _MD_CURRENT_THREAD(void);
 
-#ifdef _PR_USE_STATIC_TLS
+extern BOOL _pr_use_static_tls;
+
 extern __declspec(thread) struct PRThread *_pr_currentThread;
-#define _MD_GET_ATTACHED_THREAD() _pr_currentThread
-#define _MD_SET_CURRENT_THREAD(_thread) (_pr_currentThread = (_thread))
+extern DWORD _pr_currentThreadIndex;
+
+#define _MD_GET_ATTACHED_THREAD() \
+    (_pr_use_static_tls ? _pr_currentThread \
+    : (PRThread *) TlsGetValue(_pr_currentThreadIndex))
+
+#define _MD_SET_CURRENT_THREAD(_thread) \
+    PR_BEGIN_MACRO \
+        if (_pr_use_static_tls) { \
+            _pr_currentThread = (_thread); \
+        } else { \
+            TlsSetValue(_pr_currentThreadIndex, (_thread)); \
+        } \
+    PR_END_MACRO
 
 extern __declspec(thread) struct PRThread *_pr_thread_last_run;
-#define _MD_LAST_THREAD() _pr_thread_last_run
-#define _MD_SET_LAST_THREAD(_thread) (_pr_thread_last_run = 0)
+extern DWORD _pr_lastThreadIndex;
+
+#define _MD_LAST_THREAD() \
+    (_pr_use_static_tls ? _pr_thread_last_run \
+    : (PRThread *) TlsGetValue(_pr_lastThreadIndex))
+
+#define _MD_SET_LAST_THREAD(_thread) \
+    PR_BEGIN_MACRO \
+        if (_pr_use_static_tls) { \
+            _pr_thread_last_run = 0; \
+        } else { \
+            TlsSetValue(_pr_lastThreadIndex, 0); \
+        } \
+    PR_END_MACRO
 
 extern __declspec(thread) struct _PRCPU *_pr_currentCPU;
-#define _MD_CURRENT_CPU() _pr_currentCPU
-#define _MD_SET_CURRENT_CPU(_cpu) (_pr_currentCPU = 0)
-#else /* _PR_USE_STATIC_TLS */
-extern DWORD _pr_currentThreadIndex;
-#define _MD_GET_ATTACHED_THREAD() ((PRThread *) TlsGetValue(_pr_currentThreadIndex))
-#define _MD_SET_CURRENT_THREAD(_thread) TlsSetValue(_pr_currentThreadIndex, (_thread))
+extern DWORD _pr_currentCPUIndex;
+
+#define _MD_CURRENT_CPU() \
+    (_pr_use_static_tls ? _pr_currentCPU \
+    : (struct _PRCPU *) TlsGetValue(_pr_currentCPUIndex))
 
-extern DWORD _pr_lastThreadIndex;
-#define _MD_LAST_THREAD() ((PRThread *) TlsGetValue(_pr_lastThreadIndex))
-#define _MD_SET_LAST_THREAD(_thread) TlsSetValue(_pr_lastThreadIndex, 0)
-
-extern DWORD _pr_currentCPUIndex;
-#define _MD_CURRENT_CPU() ((struct _PRCPU *) TlsGetValue(_pr_currentCPUIndex))
-#define _MD_SET_CURRENT_CPU(_cpu) TlsSetValue(_pr_currentCPUIndex, 0)
-#endif /* _PR_USE_STATIC_TLS */
+#define _MD_SET_CURRENT_CPU(_cpu) \
+    PR_BEGIN_MACRO \
+        if (_pr_use_static_tls) { \
+            _pr_currentCPU = 0; \
+        } else { \
+            TlsSetValue(_pr_currentCPUIndex, 0); \
+        } \
+    PR_END_MACRO
 
 /* --- Scheduler stuff --- */
 #define LOCK_SCHEDULER()                 0
 #define UNLOCK_SCHEDULER()               0
 #define _PR_LockSched()                	 0
 #define _PR_UnlockSched()                0
 
 /* --- Initialization stuff --- */
--- a/pr/src/md/windows/w95dllmain.c
+++ b/pr/src/md/windows/w95dllmain.c
@@ -31,31 +31,48 @@
  * may use your version of this file under either the MPL or the
  * GPL.
  */
 
 /*
  * The DLL entry point (DllMain) for NSPR.
  *
  * This is used to detach threads that were automatically attached by
- * nspr.
+ * nspr and to find out whether the NSPR DLL is statically or
+ * dynamically loaded.  When dynamically loaded, we cannot use static
+ * thread-local storage.  However, static TLS is faster than the
+ * TlsXXX() functions.  So we want to use static TLS whenever we can.
+ * A global variable _pr_use_static_tls is set in DllMain() during
+ * process attachment to indicate whether it is safe to use static
+ * TLS or not.
  */
 
 #include <windows.h>
 #include <primpl.h>
 
+extern BOOL _pr_use_static_tls;  /* defined in w95thred.c */
+
 BOOL WINAPI DllMain(
     HINSTANCE hinstDLL,
     DWORD fdwReason,
     LPVOID lpvReserved)
 {
 PRThread *me;
 
     switch (fdwReason) {
         case DLL_PROCESS_ATTACH:
+            /*
+             * If lpvReserved is NULL, we are dynamically loaded
+             * and therefore can't use static thread-local storage.
+             */
+            if (lpvReserved == NULL) {
+                _pr_use_static_tls = FALSE;
+            } else {
+                _pr_use_static_tls = TRUE;
+            }
             break;
         case DLL_THREAD_ATTACH:
             break;
         case DLL_THREAD_DETACH:
             if (_pr_initialized) {
                 me = _MD_GET_ATTACHED_THREAD();
                 if ((me != NULL) && (me->flags & _PR_ATTACHED))
                     _PRI_DetachThread();
--- a/pr/src/md/windows/w95thred.c
+++ b/pr/src/md/windows/w95thred.c
@@ -33,51 +33,49 @@
  */
 
 #include "primpl.h"
 #include <process.h>  /* for _beginthreadex() */
 
 extern void _PR_Win32InitTimeZone(void);  /* defined in ntmisc.c */
 
 /* --- globals ------------------------------------------------ */
-#ifdef _PR_USE_STATIC_TLS
+BOOL _pr_use_static_tls = TRUE;
 __declspec(thread) struct PRThread  *_pr_thread_last_run;
 __declspec(thread) struct PRThread  *_pr_currentThread;
 __declspec(thread) struct _PRCPU    *_pr_currentCPU;
-#else
 DWORD _pr_currentThreadIndex;
 DWORD _pr_lastThreadIndex;
 DWORD _pr_currentCPUIndex;
-#endif
 int                           _pr_intsOff = 0; 
 _PRInterruptTable             _pr_interruptTable[] = { { 0 } };
 
 void
 _PR_MD_EARLY_INIT()
 {
     _PR_Win32InitTimeZone();
 
-#ifndef _PR_USE_STATIC_TLS
-    _pr_currentThreadIndex = TlsAlloc();
-    _pr_lastThreadIndex = TlsAlloc();
-    _pr_currentCPUIndex = TlsAlloc();
-#endif
+    if (!_pr_use_static_tls) {
+        _pr_currentThreadIndex = TlsAlloc();
+        _pr_lastThreadIndex = TlsAlloc();
+        _pr_currentCPUIndex = TlsAlloc();
+    }
 }
 
 void _PR_MD_CLEANUP_BEFORE_EXIT(void)
 {
     _PR_NT_FreeSids();
 
     WSACleanup();
 
-#ifndef _PR_USE_STATIC_TLS
-    TlsFree(_pr_currentThreadIndex);
-    TlsFree(_pr_lastThreadIndex);
-    TlsFree(_pr_currentCPUIndex);
-#endif
+    if (!_pr_use_static_tls) {
+        TlsFree(_pr_currentThreadIndex);
+        TlsFree(_pr_lastThreadIndex);
+        TlsFree(_pr_currentCPUIndex);
+    }
 }
 
 PRStatus
 _PR_MD_INIT_THREAD(PRThread *thread)
 {
     if (thread->flags & (_PR_PRIMORDIAL | _PR_ATTACHED)) {
         /*
         ** Warning: