From e97087c610f81fcfb3c19b1e80ab34fb76667424 Mon Sep 17 00:00:00 2001 From: "wtc%netscape.com" Date: Sat, 27 Apr 2002 03:12:25 +0000 Subject: [PATCH] Backed out the fix for bug 121975. It doesn't work on Windows 95. Modified Files: configure configure.in WIN32.mk _win95.h w95dllmain.c w95thred.c git-svn-id: svn://10.0.0.236/trunk@120074 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/nsprpub/config/WIN32.mk | 10 +++ mozilla/nsprpub/configure | 49 ++++++++------- mozilla/nsprpub/configure.in | 4 ++ mozilla/nsprpub/pr/include/md/_win95.h | 62 ++++++------------- .../nsprpub/pr/src/md/windows/w95dllmain.c | 19 +----- mozilla/nsprpub/pr/src/md/windows/w95thred.c | 24 +++---- 6 files changed, 75 insertions(+), 93 deletions(-) diff --git a/mozilla/nsprpub/config/WIN32.mk b/mozilla/nsprpub/config/WIN32.mk index 2d914e6f60e..f002c074d4b 100644 --- a/mozilla/nsprpub/config/WIN32.mk +++ b/mozilla/nsprpub/config/WIN32.mk @@ -115,6 +115,16 @@ 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 diff --git a/mozilla/nsprpub/configure b/mozilla/nsprpub/configure index d2fb9bc28f5..bbd9de534b9 100755 --- a/mozilla/nsprpub/configure +++ b/mozilla/nsprpub/configure @@ -3796,6 +3796,13 @@ EOF 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 @@ -4152,17 +4159,17 @@ EOF ac_safe=`echo "machine/builtins.h" | sed 'y%./+-%__p_%'` echo $ac_n "checking for machine/builtins.h""... $ac_c" 1>&6 -echo "configure:4156: checking for machine/builtins.h" >&5 +echo "configure:4163: 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 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:4166: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } +{ (eval echo configure:4173: \"$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* @@ -4677,12 +4684,12 @@ esac if test -z "$SKIP_LIBRARY_CHECKS"; then echo $ac_n "checking for dlopen""... $ac_c" 1>&6 -echo "configure:4681: checking for dlopen" >&5 +echo "configure:4688: 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 <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:4716: \"$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 @@ -4724,7 +4731,7 @@ else echo "$ac_t""no" 1>&6 echo $ac_n "checking for dlopen in -ldl""... $ac_c" 1>&6 -echo "configure:4728: checking for dlopen in -ldl" >&5 +echo "configure:4735: 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 @@ -4732,7 +4739,7 @@ else ac_save_LIBS="$LIBS" LIBS="-ldl $LIBS" cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:4754: \"$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 @@ -4771,13 +4778,13 @@ fi if test $ac_cv_prog_gcc = yes; then echo $ac_n "checking whether ${CC-cc} needs -traditional""... $ac_c" 1>&6 -echo "configure:4775: checking whether ${CC-cc} needs -traditional" >&5 +echo "configure:4782: 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 < Autoconf TIOCGETP @@ -4795,7 +4802,7 @@ rm -f conftest* if test $ac_cv_prog_gcc_traditional = no; then cat > conftest.$ac_ext < Autoconf TCGETA @@ -4819,12 +4826,12 @@ fi for ac_func in lchown strerror do echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 -echo "configure:4823: checking for $ac_func" >&5 +echo "configure:4830: 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 <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:4858: \"$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 @@ -4885,7 +4892,7 @@ fi echo $ac_n "checking for pthread_create in -lpthreads""... $ac_c" 1>&6 -echo "configure:4889: checking for pthread_create in -lpthreads" >&5 +echo "configure:4896: checking for pthread_create in -lpthreads" >&5 echo " #include void *foo(void *v) { int a = 1; } @@ -4907,7 +4914,7 @@ echo " echo "$ac_t""no" 1>&6 echo $ac_n "checking for pthread_create in -lpthread""... $ac_c" 1>&6 -echo "configure:4911: checking for pthread_create in -lpthread" >&5 +echo "configure:4918: checking for pthread_create in -lpthread" >&5 echo " #include void *foo(void *v) { int a = 1; } @@ -4929,7 +4936,7 @@ echo " echo "$ac_t""no" 1>&6 echo $ac_n "checking for pthread_create in -lc_r""... $ac_c" 1>&6 -echo "configure:4933: checking for pthread_create in -lc_r" >&5 +echo "configure:4940: checking for pthread_create in -lc_r" >&5 echo " #include void *foo(void *v) { int a = 1; } @@ -4951,7 +4958,7 @@ echo " echo "$ac_t""no" 1>&6 echo $ac_n "checking for pthread_create in -lc""... $ac_c" 1>&6 -echo "configure:4955: checking for pthread_create in -lc" >&5 +echo "configure:4962: checking for pthread_create in -lc" >&5 echo " #include void *foo(void *v) { int a = 1; } @@ -5101,7 +5108,7 @@ 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:5105: checking whether ${CC-cc} accepts -pthread" >&5 +echo "configure:5112: 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 @@ -5124,7 +5131,7 @@ echo "configure:5105: checking whether ${CC-cc} accepts -pthread" >&5 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:5128: checking whether ${CC-cc} accepts -pthreads" >&5 +echo "configure:5135: 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 diff --git a/mozilla/nsprpub/configure.in b/mozilla/nsprpub/configure.in index 007d355d74a..47772bbdbab 100644 --- a/mozilla/nsprpub/configure.in +++ b/mozilla/nsprpub/configure.in @@ -1247,6 +1247,10 @@ case "$target" in 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 diff --git a/mozilla/nsprpub/pr/include/md/_win95.h b/mozilla/nsprpub/pr/include/md/_win95.h index a94abbd6d8a..86b39d5dc04 100644 --- a/mozilla/nsprpub/pr/include/md/_win95.h +++ b/mozilla/nsprpub/pr/include/md/_win95.h @@ -409,55 +409,31 @@ extern PRStatus _PR_KillWindowsProcess(struct PRProcess *process); extern struct PRThread * _MD_CURRENT_THREAD(void); -extern BOOL _pr_use_static_tls; - +#ifdef _PR_USE_STATIC_TLS extern __declspec(thread) struct PRThread *_pr_currentThread; -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 +#define _MD_GET_ATTACHED_THREAD() _pr_currentThread +#define _MD_SET_CURRENT_THREAD(_thread) (_pr_currentThread = (_thread)) extern __declspec(thread) struct PRThread *_pr_thread_last_run; -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 +#define _MD_LAST_THREAD() _pr_thread_last_run +#define _MD_SET_LAST_THREAD(_thread) (_pr_thread_last_run = 0) 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_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() \ - (_pr_use_static_tls ? _pr_currentCPU \ - : (struct _PRCPU *) TlsGetValue(_pr_currentCPUIndex)) - -#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 +#define _MD_CURRENT_CPU() ((struct _PRCPU *) TlsGetValue(_pr_currentCPUIndex)) +#define _MD_SET_CURRENT_CPU(_cpu) TlsSetValue(_pr_currentCPUIndex, 0) +#endif /* _PR_USE_STATIC_TLS */ /* --- Scheduler stuff --- */ #define LOCK_SCHEDULER() 0 diff --git a/mozilla/nsprpub/pr/src/md/windows/w95dllmain.c b/mozilla/nsprpub/pr/src/md/windows/w95dllmain.c index f5c1bca9ae5..f6e8d59c445 100644 --- a/mozilla/nsprpub/pr/src/md/windows/w95dllmain.c +++ b/mozilla/nsprpub/pr/src/md/windows/w95dllmain.c @@ -36,20 +36,12 @@ * The DLL entry point (DllMain) for NSPR. * * This is used to detach threads that were automatically attached by - * 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. + * nspr. */ #include #include -extern BOOL _pr_use_static_tls; /* defined in w95thred.c */ - BOOL WINAPI DllMain( HINSTANCE hinstDLL, DWORD fdwReason, @@ -59,15 +51,6 @@ 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; diff --git a/mozilla/nsprpub/pr/src/md/windows/w95thred.c b/mozilla/nsprpub/pr/src/md/windows/w95thred.c index 918db7b4c3c..f8a70043c50 100644 --- a/mozilla/nsprpub/pr/src/md/windows/w95thred.c +++ b/mozilla/nsprpub/pr/src/md/windows/w95thred.c @@ -38,13 +38,15 @@ extern void _PR_Win32InitTimeZone(void); /* defined in ntmisc.c */ /* --- globals ------------------------------------------------ */ -BOOL _pr_use_static_tls = TRUE; +#ifdef _PR_USE_STATIC_TLS __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 } }; @@ -53,11 +55,11 @@ _PR_MD_EARLY_INIT() { _PR_Win32InitTimeZone(); - if (!_pr_use_static_tls) { - _pr_currentThreadIndex = TlsAlloc(); - _pr_lastThreadIndex = TlsAlloc(); - _pr_currentCPUIndex = TlsAlloc(); - } +#ifndef _PR_USE_STATIC_TLS + _pr_currentThreadIndex = TlsAlloc(); + _pr_lastThreadIndex = TlsAlloc(); + _pr_currentCPUIndex = TlsAlloc(); +#endif } void _PR_MD_CLEANUP_BEFORE_EXIT(void) @@ -66,11 +68,11 @@ void _PR_MD_CLEANUP_BEFORE_EXIT(void) WSACleanup(); - if (!_pr_use_static_tls) { - TlsFree(_pr_currentThreadIndex); - TlsFree(_pr_lastThreadIndex); - TlsFree(_pr_currentCPUIndex); - } +#ifndef _PR_USE_STATIC_TLS + TlsFree(_pr_currentThreadIndex); + TlsFree(_pr_lastThreadIndex); + TlsFree(_pr_currentCPUIndex); +#endif } PRStatus