зеркало из https://github.com/mozilla/pjs.git
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
This commit is contained in:
Родитель
5cfa671f7b
Коммит
d84d5973fb
|
@ -115,16 +115,6 @@ 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
|
||||
|
|
|
@ -3787,13 +3787,6 @@ 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
|
||||
|
@ -4150,17 +4143,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: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*
|
||||
|
@ -4675,12 +4668,12 @@ 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. */
|
||||
|
@ -4703,7 +4696,7 @@ dlopen();
|
|||
|
||||
; 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
|
||||
|
@ -4722,7 +4715,7 @@ 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
|
||||
|
@ -4730,7 +4723,7 @@ 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
|
||||
|
@ -4741,7 +4734,7 @@ 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
|
||||
|
@ -4769,13 +4762,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: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
|
||||
|
@ -4793,7 +4786,7 @@ 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
|
||||
|
@ -4817,12 +4810,12 @@ 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. */
|
||||
|
@ -4845,7 +4838,7 @@ $ac_func();
|
|||
|
||||
; 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
|
||||
|
@ -4883,7 +4876,7 @@ 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; }
|
||||
|
@ -4905,7 +4898,7 @@ echo "
|
|||
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; }
|
||||
|
@ -4927,7 +4920,7 @@ echo "
|
|||
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; }
|
||||
|
@ -4949,7 +4942,7 @@ echo "
|
|||
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; }
|
||||
|
@ -5099,7 +5092,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: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
|
||||
|
@ -5122,7 +5115,7 @@ echo "configure:5103: 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: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
|
||||
|
|
|
@ -1238,10 +1238,6 @@ 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
|
||||
|
|
|
@ -409,31 +409,55 @@ extern PRStatus _PR_KillWindowsProcess(struct PRProcess *process);
|
|||
|
||||
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_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_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
|
||||
|
||||
/* --- Scheduler stuff --- */
|
||||
#define LOCK_SCHEDULER() 0
|
||||
|
|
|
@ -36,12 +36,20 @@
|
|||
* 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,
|
||||
|
@ -51,6 +59,15 @@ 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;
|
||||
|
|
|
@ -38,15 +38,13 @@
|
|||
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 } };
|
||||
|
||||
|
@ -55,11 +53,11 @@ _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)
|
||||
|
@ -68,11 +66,11 @@ void _PR_MD_CLEANUP_BEFORE_EXIT(void)
|
|||
|
||||
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
|
||||
|
|
Загрузка…
Ссылка в новой задаче