summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwtc <devnull@localhost>1998-05-08 23:30:48 +0000
committerwtc <devnull@localhost>1998-05-08 23:30:48 +0000
commit6cd7f0eafc968de1cc3b90cbbac35cec2f2013ac (patch)
treea72395df86fd76946d8ead08e844615dd30d3bf6
parent0e35899d3fcad44d6f7c5776ad0feadda19ae8ea (diff)
downloadnspr-hg-NSPRPUB_19980508_BRANCH.tar.gz
Copied latest stuff from /m/src/ns/nspr20.NSPRPUB_19980508_BRANCH
-rw-r--r--config/NEWS-OS.mk2
-rw-r--r--config/OS2.mk2
-rw-r--r--config/SINIX.mk2
-rw-r--r--config/SunOS5.mk5
-rw-r--r--config/WIN32.mk38
-rw-r--r--config/arch.mk6
-rw-r--r--config/win16.mk2
-rw-r--r--pr/include/md/_os2.h5
-rw-r--r--pr/include/md/_unixos.h11
-rw-r--r--pr/include/md/_win16.h2
-rw-r--r--pr/include/md/_win95.h15
-rw-r--r--pr/include/md/_winnt.h28
-rw-r--r--pr/include/prclist.h6
-rw-r--r--pr/include/prlog.h87
-rw-r--r--pr/src/io/prlog.c47
-rw-r--r--pr/src/linking/prlink.c2
-rw-r--r--pr/src/md/unix/pthreads_user.c6
-rw-r--r--pr/src/md/unix/solaris.c2
-rw-r--r--pr/src/md/unix/unix.c12
-rw-r--r--pr/src/md/windows/ntio.c10
-rw-r--r--pr/src/md/windows/ntthread.c45
-rw-r--r--pr/src/misc/prenv.c12
-rw-r--r--pr/src/pthreads/ptsynch.c6
-rw-r--r--pr/src/threads/combined/prucpu.c2
-rw-r--r--pr/tests/Makefile10
-rw-r--r--pr/tests/logger.c37
-rw-r--r--pr/tests/sleep.c4
-rw-r--r--pr/tests/time.c2
28 files changed, 323 insertions, 85 deletions
diff --git a/config/NEWS-OS.mk b/config/NEWS-OS.mk
index e9db770d..b0307c02 100644
--- a/config/NEWS-OS.mk
+++ b/config/NEWS-OS.mk
@@ -37,7 +37,7 @@ G++INCLUDES =
#OS_LIBS = -lsocket -lnsl -lgen -lresolv
PLATFORM_FLAGS = -Xa -fullwarn -DSONY
-PORT_FLAGS = -DSYSV -DSVR4 -D__svr4 -D__svr4__ -D_PR_LOCAL_THREADS_ONLY
+PORT_FLAGS = -DSYSV -DSVR4 -D__svr4 -D__svr4__ -D_PR_LOCAL_THREADS_ONLY -DHAVE_SVID_GETTOD
OS_CFLAGS = $(PLATFORM_FLAGS) $(PORT_FLAGS)
diff --git a/config/OS2.mk b/config/OS2.mk
index 61084f69..184d3dd2 100644
--- a/config/OS2.mk
+++ b/config/OS2.mk
@@ -74,7 +74,7 @@ DEFINES += -D_X86_
DEFINES += -D_PR_GLOBAL_THREADS_ONLY
# Name of the binary code directories
-ifeq ($(CPU_ARCH),x386)
+ifeq ($(CPU_ARCH),x86)
ifdef MOZ_LITE
OBJDIR_NAME = $(subst OS2,NAV,$(OS_CONFIG))$(OBJDIR_TAG).OBJ
else
diff --git a/config/SINIX.mk b/config/SINIX.mk
index 5711aeb2..1be48be5 100644
--- a/config/SINIX.mk
+++ b/config/SINIX.mk
@@ -53,7 +53,7 @@ MKSHLIB = $(LD) -G -z defs -h $(@:$(OBJDIR)/%.so=%.so)
#DSO_LDOPTS = -G -W l,-Blargedynsym
endif
-ODD_CFLAGS += -DSVR4 -DSNI -DRELIANTUNIX -Dsinix -D_SVID_GETTOD
+ODD_CFLAGS += -DSVR4 -DSNI -DRELIANTUNIX -Dsinix -DHAVE_SVID_GETTOD
# On SINIX 5.43, need to define IP_MULTICAST in order to get the
# IP multicast macro and struct definitions in netinet/in.h.
diff --git a/config/SunOS5.mk b/config/SunOS5.mk
index 76881adb..d4775ce5 100644
--- a/config/SunOS5.mk
+++ b/config/SunOS5.mk
@@ -105,11 +105,6 @@ endif
ifeq (5.5,$(findstring 5.5,$(OS_RELEASE)))
OS_DEFINES += -DSOLARIS2_5
-SOL_CFLAGS = -D_SVID_GETTOD
-endif
-
-ifeq ($(OS_RELEASE),5.6)
-SOL_CFLAGS = -D_SVID_GETTOD
endif
ifneq ($(LOCAL_THREADS_ONLY),1)
diff --git a/config/WIN32.mk b/config/WIN32.mk
index 6036367e..3f21c79c 100644
--- a/config/WIN32.mk
+++ b/config/WIN32.mk
@@ -29,6 +29,22 @@ ifdef PR_CLIENT_BUILD_WINDOWS
SHELL = $(MOZ_TOOLS_FLIPPED)/bin/shmsdos.exe
endif
+#
+# On NT, we use static thread local storage by default because it
+# gives us better performance. However, we can't use static TLS
+# on Alpha NT because the Alpha version of MSVC does not seem to
+# support the -GT flag, which is necessary to make static TLS safe
+# for fibers.
+#
+# On Win95, we use the TlsXXX() functions by default because that
+# allows us to load the NSPR DLL at run time using LoadLibrary().
+#
+ifeq ($(OS_TARGET),WINNT)
+ifneq ($(CPU_ARCH),ALPHA)
+USE_STATIC_TLS = 1
+endif
+endif
+
CC = cl
CCC = cl
LINK = link
@@ -96,17 +112,31 @@ endif
endif
DEFINES += -DWIN32
-ifeq ($(OS_TARGET),WINNT)
+ifeq ($(USE_STATIC_TLS),1)
+DEFINES += -D_PR_USE_STATIC_TLS
+endif
+
+#
+# NSPR uses fibers on NT. Therefore, if we use static local
+# storage (i.e., __declspec(thread) variables), we need the -GT
+# flag to turn off certain compiler optimizations so that fibers
+# can use static TLS safely.
#
-# Win NT needs -GT so that fibers can work
+# Also, we optimize for Pentium (-G5) on NT.
#
+ifeq ($(OS_TARGET),WINNT)
+ifeq ($(USE_STATIC_TLS),1)
OS_CFLAGS += -GT
+endif
+ifeq ($(CPU_ARCH),x86)
+OS_CFLAGS += -G5
+endif
DEFINES += -DWINNT
else
DEFINES += -DWIN95 -D_PR_GLOBAL_THREADS_ONLY
endif
-ifeq ($(CPU_ARCH),x386)
+ifeq ($(CPU_ARCH),x86)
DEFINES += -D_X86_
else
ifeq ($(CPU_ARCH),MIPS)
@@ -122,7 +152,7 @@ endif
# Name of the binary code directories
-ifeq ($(CPU_ARCH),x386)
+ifeq ($(CPU_ARCH),x86)
CPU_ARCH_TAG =
else
CPU_ARCH_TAG = $(CPU_ARCH)
diff --git a/config/arch.mk b/config/arch.mk
index 466be8a4..aee7e3ae 100644
--- a/config/arch.mk
+++ b/config/arch.mk
@@ -144,7 +144,7 @@ endif
ifeq ($(OS_ARCH), WINNT)
CPU_ARCH := $(shell uname -p)
ifeq ($(CPU_ARCH),I386)
- CPU_ARCH = x386
+ CPU_ARCH = x86
endif
else
#
@@ -167,7 +167,7 @@ ifeq ($(OS_ARCH), Windows_NT)
# MKS's uname -m returns "586" on a Pentium machine.
#
ifneq (,$(findstring 86,$(CPU_ARCH)))
- CPU_ARCH = x386
+ CPU_ARCH = x86
endif
else
#
@@ -181,7 +181,7 @@ ifeq ($(OS_ARCH), CYGWIN32_NT)
# GNU-Win32's uname -m returns "i686" on a Pentium Pro machine.
#
ifneq (,$(findstring 86,$(CPU_ARCH)))
- CPU_ARCH = x386
+ CPU_ARCH = x86
endif
endif
endif
diff --git a/config/win16.mk b/config/win16.mk
index d6db9427..268b7b65 100644
--- a/config/win16.mk
+++ b/config/win16.mk
@@ -85,7 +85,7 @@ DLL := $(addprefix $(OBJDIR)/, $(DLL))
endif
-CPU_ARCH = x386
+CPU_ARCH = x86
OS_CFLAGS = -ml -3 -bd -zc -zu -bt=windows -d_X86_ -dWIN16 -d_WINDLL
OS_EXE_CFLAGS = -ml -3 -bt=windows -d_X86_ -dWIN16
OS_LIB_FLAGS = -c -iro -n
diff --git a/pr/include/md/_os2.h b/pr/include/md/_os2.h
index acdf4c64..ab67224a 100644
--- a/pr/include/md/_os2.h
+++ b/pr/include/md/_os2.h
@@ -402,11 +402,6 @@ PR_IMPLEMENT(void) _PR_MD_ENSURE_TLS();
#define _MD_CURRENT_CPU() pThreadLocalStorage->_pr_currentCPU
#define _MD_SET_CURRENT_CPU(_cpu) _PR_MD_ENSURE_TLS(); pThreadLocalStorage->_pr_currentCPU = (_cpu)
-/* lth. #define _MD_SET_INTSOFF(_val) (_pr_ints_off = (_val)) */
-/* lth. #define _MD_GET_INTSOFF() _pr_ints_off */
-/* lth. #define _MD_INCREMENT_INTSOFF() (_pr_ints_off++) */
-/* lth. #define _MD_DECREMENT_INTSOFF() (_pr_ints_off--) */
-
/* --- Scheduler stuff --- */
#define LOCK_SCHEDULER() 0
#define UNLOCK_SCHEDULER() 0
diff --git a/pr/include/md/_unixos.h b/pr/include/md/_unixos.h
index 106de3d3..d8895aa7 100644
--- a/pr/include/md/_unixos.h
+++ b/pr/include/md/_unixos.h
@@ -464,6 +464,17 @@ extern PRStatus _MD_MemUnmap(void *addr, PRUint32 size);
extern PRStatus _MD_CloseFileMap(struct PRFileMap *fmap);
#define _MD_CLOSE_FILE_MAP _MD_CloseFileMap
+/*
+ * The standard (XPG4) gettimeofday() (from BSD) takes two arguments.
+ * On some SVR4 derivatives, gettimeofday() takes only one argument.
+ * The GETTIMEOFDAY macro is intended to hide this difference.
+ */
+#ifdef HAVE_SVID_GETTOD
+#define GETTIMEOFDAY(tp) gettimeofday(tp)
+#else
+#define GETTIMEOFDAY(tp) gettimeofday((tp), NULL)
+#endif
+
#if defined(LINUX) && defined(_PR_PTHREADS) && !(__GLIBC__ >= 2)
#define _PR_NEED_FAKE_POLL
#endif
diff --git a/pr/include/md/_win16.h b/pr/include/md/_win16.h
index dec2a1df..bb8ba5a3 100644
--- a/pr/include/md/_win16.h
+++ b/pr/include/md/_win16.h
@@ -45,8 +45,6 @@
#define HAVE_SOCKET_KEEPALIVE
#define _PR_HAVE_ATOMIC_OPS
-typedef char * caddr_t;
-
/* --- Common User-Thread/Native-Thread Definitions --------------------- */
extern struct PRLock *_pr_schedLock;
diff --git a/pr/include/md/_win95.h b/pr/include/md/_win95.h
index 7b412923..9cfbc1b4 100644
--- a/pr/include/md/_win95.h
+++ b/pr/include/md/_win95.h
@@ -39,9 +39,6 @@
#define HAVE_SOCKET_KEEPALIVE
#define _PR_HAVE_ATOMIC_OPS
-typedef char * caddr_t;
-typedef int ptrdiff_t; /* used in prnetdb.h */
-
/* --- Common User-Thread/Native-Thread Definitions --------------------- */
/* --- Globals --- */
@@ -378,15 +375,15 @@ extern __declspec(thread) struct PRThread *_pr_currentThread;
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))
+#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))
+#define _MD_SET_CURRENT_CPU(_cpu) (_pr_currentCPU = 0)
#else /* _PR_USE_STATIC_TLS */
extern DWORD _pr_currentThreadIndex;
#define _MD_CURRENT_THREAD() ((PRThread *) TlsGetValue(_pr_currentThreadIndex))
-#define _MD_SET_CURRENT_THREAD(_thread) TlsSetValue(_pr_currentThreadIndex, _thread)
+#define _MD_SET_CURRENT_THREAD(_thread) TlsSetValue(_pr_currentThreadIndex, (_thread))
extern DWORD _pr_lastThreadIndex;
#define _MD_LAST_THREAD() ((PRThread *) TlsGetValue(_pr_lastThreadIndex))
@@ -397,12 +394,6 @@ extern DWORD _pr_currentCPUIndex;
#define _MD_SET_CURRENT_CPU(_cpu) TlsSetValue(_pr_currentCPUIndex, 0)
#endif /* _PR_USE_STATIC_TLS */
-// wtc. extern __declspec(thread) PRUintn _pr_ints_off;
-// lth. #define _MD_SET_INTSOFF(_val) (_pr_ints_off = (_val))
-// lth. #define _MD_GET_INTSOFF() _pr_ints_off
-// lth. #define _MD_INCREMENT_INTSOFF() (_pr_ints_off++)
-// lth. #define _MD_DECREMENT_INTSOFF() (_pr_ints_off--)
-
/* --- Scheduler stuff --- */
#define LOCK_SCHEDULER() 0
#define UNLOCK_SCHEDULER() 0
diff --git a/pr/include/md/_winnt.h b/pr/include/md/_winnt.h
index ba2a6a10..7695e5f6 100644
--- a/pr/include/md/_winnt.h
+++ b/pr/include/md/_winnt.h
@@ -50,10 +50,6 @@
#define HAVE_SOCKET_KEEPALIVE
#define _PR_HAVE_ATOMIC_OPS
-typedef char * caddr_t;
-typedef int ptrdiff_t; /* used in prnetdb.h */
-
-
/* --- Common User-Thread/Native-Thread Definitions --------------------- */
/* --- Globals --- */
@@ -374,6 +370,8 @@ extern PRStatus _PR_KillWindowsProcess(struct PRProcess *process);
/* --- Native-Thread Specific Definitions ------------------------------- */
+#ifdef _PR_USE_STATIC_TLS
+
extern __declspec(thread) struct PRThread *_pr_current_fiber;
#define _MD_CURRENT_THREAD() _pr_current_fiber
#define _MD_SET_CURRENT_THREAD(_thread) (_pr_current_fiber = (_thread))
@@ -389,8 +387,26 @@ extern __declspec(thread) struct _PRCPU *_pr_current_cpu;
extern __declspec(thread) PRUintn _pr_ints_off;
#define _MD_SET_INTSOFF(_val) (_pr_ints_off = (_val))
#define _MD_GET_INTSOFF() _pr_ints_off
-#define _MD_INCREMENT_INTSOFF() (_pr_ints_off++)
-#define _MD_DECREMENT_INTSOFF() (_pr_ints_off--)
+
+#else /* _PR_USE_STATIC_TLS */
+
+extern DWORD _pr_currentFiberIndex;
+#define _MD_CURRENT_THREAD() ((PRThread *) TlsGetValue(_pr_currentFiberIndex))
+#define _MD_SET_CURRENT_THREAD(_thread) TlsSetValue(_pr_currentFiberIndex, (_thread))
+
+extern DWORD _pr_lastFiberIndex;
+#define _MD_LAST_THREAD() ((PRThread *) TlsGetValue(_pr_lastFiberIndex))
+#define _MD_SET_LAST_THREAD(_thread) TlsSetValue(_pr_lastFiberIndex, (_thread))
+
+extern DWORD _pr_currentCPUIndex;
+#define _MD_CURRENT_CPU() ((struct _PRCPU *) TlsGetValue(_pr_currentCPUIndex))
+#define _MD_SET_CURRENT_CPU(_cpu) TlsSetValue(_pr_currentCPUIndex, (_cpu))
+
+extern DWORD _pr_intsOffIndex;
+#define _MD_SET_INTSOFF(_val) TlsSetValue(_pr_intsOffIndex, (LPVOID) (_val))
+#define _MD_GET_INTSOFF() ((PRUintn) TlsGetValue(_pr_intsOffIndex))
+
+#endif /* _PR_USE_STATIC_TLS */
/* --- Initialization stuff --- */
#define _MD_INIT_LOCKS()
diff --git a/pr/include/prclist.h b/pr/include/prclist.h
index 6cba6959..f1215d48 100644
--- a/pr/include/prclist.h
+++ b/pr/include/prclist.h
@@ -59,6 +59,12 @@ struct PRCListStr {
#define PR_NEXT_LINK(_e) \
((_e)->next)
/*
+** Return the element preceding element "_e"
+*/
+#define PR_PREV_LINK(_e) \
+ ((_e)->prev)
+
+/*
** Append an element "_e" to the end of the list "_l"
*/
#define PR_APPEND_LINK(_e,_l) PR_INSERT_BEFORE(_e,_l)
diff --git a/pr/include/prlog.h b/pr/include/prlog.h
index 2605300b..ba31361a 100644
--- a/pr/include/prlog.h
+++ b/pr/include/prlog.h
@@ -24,30 +24,91 @@
PR_BEGIN_EXTERN_C
/*
+** prlog.h -- Declare interfaces to NSPR's Logging service
**
-** Define in your environment a NSPR_LOG_MODULES variable. The value of
-** this variable has the form:
+** NSPR provides a logging service that is used by NSPR itself and is
+** available to client programs.
**
-** <moduleName>:<value>[, <moduleName>:<value>]*
+** To use the service from a client program, you should create a
+** PRLogModuleInfo structure by calling PR_NewLogModule(). After
+** creating the LogModule, you can write to the log using the PR_LOG()
+** macro.
+**
+** Initialization of the log service is handled by NSPR initialization.
+**
+** At execution time, you must enable the log service. To enable the
+** log service, set the environment variable: NSPR_LOG_MODULES
+** variable.
**
-** where moduleName is one of named modules that support debugging (see
-** the header file for a particular module for more specific
-** information). Value is one of the enum PRLogModuleLevel's legal
-** values.
+** NSPR_LOG_MODULES variable has the form:
**
-** Special modules exist for controlling the logging facility:
-** sync -- do unbuffered logging
-** bufsize:size -- use a buffer of "size" bytes
+** <moduleName>:<value>[, <moduleName>:<value>]*
+**
+** Where:
+** <moduleName> is the name passed to PR_NewLogModule().
+** <value> is a numeric constant, e.g. 5. This value is the maximum
+** value of a log event, enumerated by PRLogModuleLevel, that you want
+** written to the log.
+**
+** For example: to record all events of greater value than or equal to
+** PR_LOG_ERROR for a LogModule names "gizmo", say:
+**
+** set NSPR_LOG_MODULES=gizmo:2
+**
+** Note that you must specify the numeric value of PR_LOG_ERROR.
+**
+** Special LogModule names are provided for controlling NSPR's log
+** service at execution time. These controls should be set in the
+** NSPR_LOG_MODULES environment variable at execution time to affect
+** NSPR's log service for your application.
+**
+** The special LogModule "all" enables all LogModules. To enable all
+** LogModule calls to PR_LOG(), say:
+**
+** set NSPR_LOG_MODULES=all:5
+**
+** The special LogModule name "sync" tells the NSPR log service to do
+** unbuffered logging.
+**
+** The special LogModule name "buffsize:<size>" tells NSPR to set the
+** log buffer to <size>.
**
-** Define in your environment NSPR_LOG_FILE to specify the log file to
-** use unless the default of "stderr" is acceptable.
+** The environment variable NSPR_LOG_FILE specifies the log file to use
+** unless the default of "stderr" is acceptable.
**
** To put log messages in your programs, use the PR_LOG macro:
**
** PR_LOG(<module>, <level>, (<printfString>, <args>*));
**
** Where <module> is the address of a PRLogModuleInfo structure, and
-** <level> is one of the following levels:
+** <level> is one of the levels defined by the enumeration:
+** PRLogModuleLevel. <args> is a printf() style of argument list. That
+** is: (fmtstring, ...).
+**
+** Example:
+**
+** main() {
+** PRIntn one = 1;
+** PRLogModuleInfo * myLm = PR_NewLogModule("gizmo");
+** PR_LOG( myLm, PR_LOG_ALWAYS, ("Log this! %d\n", one));
+** return;
+** }
+**
+** Note the use of printf() style arguments as the third agrument(s) to
+** PR_LOG().
+**
+** After compiling and linking you application, set the environment:
+**
+** SET NSPR_LOGMODULES=gizmo:5
+** SET NSPR_LOG_FILE=logfile.txt
+**
+** When you execute your application, the string "Log this! 1" will be
+** written to the file "logfile.txt".
+**
+** Note to NSPR engineers: a number of PRLogModuleInfo structures are
+** defined and initialized in prinit.c. See this module for ideas on
+** what to log where.
+**
*/
typedef enum PRLogModuleLevel {
diff --git a/pr/src/io/prlog.c b/pr/src/io/prlog.c
index cd1b6d4e..1ab6a9b4 100644
--- a/pr/src/io/prlog.c
+++ b/pr/src/io/prlog.c
@@ -249,6 +249,52 @@ void _PR_LogCleanup(void)
#endif /* PR_LOGGING */
+static void _PR_SetLogModuleLevel( PRLogModuleInfo *lm )
+{
+#ifdef PR_LOGGING
+ char *ev;
+
+ ev = PR_GetEnv("NSPR_LOG_MODULES");
+ if (ev && ev[0]) {
+ char module[64];
+ PRBool isSync = PR_FALSE;
+ PRIntn evlen = strlen(ev), pos = 0;
+ PRInt32 bufSize = DEFAULT_BUF_SIZE;
+ while (pos < evlen) {
+ PRIntn level = 1, count = 0, delta = 0;
+ PRLogModuleInfo *lm = logModules;
+ PRBool skip_modcheck;
+
+ count = sscanf(&ev[pos], "%64[A-Za-z0-9]%n:%d%n",
+ module, &delta, &level, &delta);
+ pos += delta;
+ if (count == 0) break;
+
+ /*
+ ** If count == 2, then we got module and level. If count
+ ** == 1, then level defaults to 1 (module enabled).
+ */
+ skip_modcheck = (0 == strcasecmp (module, "all")) ? PR_TRUE : PR_FALSE;
+ while (lm != NULL)
+ {
+ if (skip_modcheck)
+ lm->level = (PRLogModuleLevel)level;
+ else if (strcasecmp(module, lm->name) == 0)
+ {
+ lm->level = level;
+ break;
+ }
+ lm = lm->next;
+ }
+ /*found:*/
+ count = sscanf(&ev[pos], " , %n", &delta);
+ pos += delta;
+ if (count == -1) break;
+ }
+ }
+#endif /* PR_LOGGING */
+} /* end _PR_SetLogModuleLevel() */
+
PR_IMPLEMENT(PRLogModuleInfo*) PR_NewLogModule(const char *name)
{
PRLogModuleInfo *lm;
@@ -262,6 +308,7 @@ PR_IMPLEMENT(PRLogModuleInfo*) PR_NewLogModule(const char *name)
lm->next = logModules;
logModules = lm;
}
+ _PR_SetLogModuleLevel(lm);
return lm;
}
diff --git a/pr/src/linking/prlink.c b/pr/src/linking/prlink.c
index 53a9ae94..93f0b45a 100644
--- a/pr/src/linking/prlink.c
+++ b/pr/src/linking/prlink.c
@@ -946,6 +946,8 @@ PR_LoadStaticLibrary(const char *name, const PRStaticLinkTable *slt)
PRLibrary *lm=NULL;
PRLibrary* result = NULL;
+ if (!_pr_initialized) _PR_ImplicitInitialization();
+
/* See if library is already loaded */
PR_EnterMonitor(pr_linker_lock);
diff --git a/pr/src/md/unix/pthreads_user.c b/pr/src/md/unix/pthreads_user.c
index efc3ff70..63908b21 100644
--- a/pr/src/md/unix/pthreads_user.c
+++ b/pr/src/md/unix/pthreads_user.c
@@ -238,11 +238,7 @@ PRUint32 ticks = PR_TicksPerSecond();
tmo.tv_nsec);
/* pthreads wants this in absolute time, off we go ... */
-#if defined(SOLARIS) && defined(_SVID_GETTOD)
- (void)gettimeofday(&now);
-#else
- (void)gettimeofday(&now, NULL);
-#endif
+ (void)GETTIMEOFDAY(&now);
/* that one's usecs, this one's nsecs - grrrr! */
tmo.tv_sec += now.tv_sec;
tmo.tv_nsec += (PT_NANOPERMICRO * now.tv_usec);
diff --git a/pr/src/md/unix/solaris.c b/pr/src/md/unix/solaris.c
index 8658ebbb..b102aa36 100644
--- a/pr/src/md/unix/solaris.c
+++ b/pr/src/md/unix/solaris.c
@@ -799,7 +799,7 @@ _pr_solx86_clock_gettime(clockid_t clock_id, struct timespec *tp)
return -1;
}
- gettimeofday(&tv);
+ gettimeofday(&tv, NULL);
tp->tv_sec = tv.tv_sec;
tp->tv_nsec = tv.tv_usec * 1000;
return 0;
diff --git a/pr/src/md/unix/unix.c b/pr/src/md/unix/unix.c
index e4da4a25..ae13fb53 100644
--- a/pr/src/md/unix/unix.c
+++ b/pr/src/md/unix/unix.c
@@ -2857,11 +2857,7 @@ PR_Now(void)
struct timeval tv;
PRInt64 s, us, s2us;
-#if (defined(SOLARIS) && defined(_SVID_GETTOD)) || defined(SONY)
- gettimeofday(&tv);
-#else
- gettimeofday(&tv, 0);
-#endif
+ GETTIMEOFDAY(&tv);
LL_I2L(s2us, PR_USEC_PER_SEC);
LL_I2L(s, tv.tv_sec);
LL_I2L(us, tv.tv_usec);
@@ -2875,11 +2871,7 @@ PRIntervalTime _PR_UNIX_GetInterval()
struct timeval time;
PRIntervalTime ticks;
-#if defined(_SVID_GETTOD) || defined(SONY)
- (void)gettimeofday(&time); /* fallicy of course */
-#else
- (void)gettimeofday(&time, NULL); /* fallicy of course */
-#endif
+ (void)GETTIMEOFDAY(&time); /* fallicy of course */
ticks = (PRUint32)time.tv_sec * PR_MSEC_PER_SEC; /* that's in milliseconds */
ticks += (PRUint32)time.tv_usec / PR_USEC_PER_MSEC; /* so's that */
return ticks;
diff --git a/pr/src/md/windows/ntio.c b/pr/src/md/windows/ntio.c
index c41b0ab3..f2938b72 100644
--- a/pr/src/md/windows/ntio.c
+++ b/pr/src/md/windows/ntio.c
@@ -45,7 +45,13 @@ static struct _MDLock _pr_recycle_lock;
static PRInt32 _pr_recycle_array[RECYCLE_SIZE];
static PRInt32 _pr_recycle_tail = 0;
+#ifdef _PR_USE_STATIC_TLS
__declspec(thread) PRThread *_pr_io_restarted_io = NULL;
+#else
+DWORD _pr_io_restartedIOIndex; /* The thread local storage slot for each
+ * thread is initialized to NULL. */
+#endif
+
PRBool _nt_version_gets_lockfile_completion;
struct _MDLock _pr_ioq_lock;
@@ -471,7 +477,11 @@ _NT_ResumeIO(PRThread *thread, PRIntervalTime ticks)
PRBool fWait = PR_TRUE;
if (!_PR_IS_NATIVE_THREAD(thread)) {
+#ifdef _PR_USE_STATIC_TLS
_pr_io_restarted_io = thread;
+#else
+ TlsSetValue(_pr_io_restartedIOIndex, thread);
+#endif
} else {
_PR_THREAD_LOCK(thread);
if (!thread->io_pending)
diff --git a/pr/src/md/windows/ntthread.c b/pr/src/md/windows/ntthread.c
index 91257aaf..d751581b 100644
--- a/pr/src/md/windows/ntthread.c
+++ b/pr/src/md/windows/ntthread.c
@@ -24,15 +24,25 @@ extern void _PR_Win32InitTimeZone(void); /* defined in ntmisc.c */
/* --- globals ------------------------------------------------ */
PRLock *_pr_schedLock = NULL;
_PRInterruptTable _pr_interruptTable[] = { { 0 } };
+
+#ifdef _PR_USE_STATIC_TLS
__declspec(thread) PRThread *_pr_current_fiber;
__declspec(thread) PRThread *_pr_fiber_last_run;
__declspec(thread) _PRCPU *_pr_current_cpu;
__declspec(thread) PRUintn _pr_ints_off;
+#else /* _PR_USE_STATIC_TLS */
+DWORD _pr_currentFiberIndex;
+DWORD _pr_lastFiberIndex;
+DWORD _pr_currentCPUIndex;
+DWORD _pr_intsOffIndex;
+#endif /* _PR_USE_STATIC_TLS */
_MDLock _nt_idleLock;
PRCList _nt_idleList;
PRUint32 _nt_idleCount;
+#ifdef _PR_USE_STATIC_TLS
+
extern __declspec(thread) PRThread *_pr_io_restarted_io;
/* Must check the restarted_io *before* decrementing no_sched to 0 */
@@ -41,6 +51,21 @@ extern __declspec(thread) PRThread *_pr_io_restarted_io;
_nt_handle_restarted_io(_pr_io_restarted_io); \
_PR_MD_LAST_THREAD()->no_sched = 0;
+#else /* _PR_USE_STATIC_TLS */
+
+extern DWORD _pr_io_restartedIOIndex;
+
+/* Must check the restarted_io *before* decrementing no_sched to 0 */
+#define POST_SWITCH_WORK() \
+PR_BEGIN_MACRO \
+ PRThread *restarted_io = (PRThread *) TlsGetValue(_pr_io_restartedIOIndex); \
+ if (restarted_io) \
+ _nt_handle_restarted_io(restarted_io); \
+ _PR_MD_LAST_THREAD()->no_sched = 0; \
+PR_END_MACRO
+
+#endif /* _PR_USE_STATIC_TLS */
+
void
_nt_handle_restarted_io(PRThread *restarted_io)
{
@@ -69,7 +94,11 @@ _nt_handle_restarted_io(PRThread *restarted_io)
_PR_THREAD_UNLOCK(restarted_io);
+#ifdef _PR_USE_STATIC_TLS
_pr_io_restarted_io = NULL;
+#else
+ TlsSetValue(_pr_io_restartedIOIndex, NULL);
+#endif
}
void
@@ -87,11 +116,27 @@ _PR_MD_EARLY_INIT()
PR_ASSERT(0);
}
#endif
+
+#ifndef _PR_USE_STATIC_TLS
+ _pr_currentFiberIndex = TlsAlloc();
+ _pr_lastFiberIndex = TlsAlloc();
+ _pr_currentCPUIndex = TlsAlloc();
+ _pr_intsOffIndex = TlsAlloc();
+ _pr_io_restartedIOIndex = TlsAlloc();
+#endif
}
void _PR_MD_CLEANUP_BEFORE_EXIT(void)
{
WSACleanup();
+
+#ifndef _PR_USE_STATIC_TLS
+ TlsFree(_pr_currentFiberIndex);
+ TlsFree(_pr_lastFiberIndex);
+ TlsFree(_pr_currentCPUIndex);
+ TlsFree(_pr_intsOffIndex);
+ TlsFree(_pr_io_restartedIOIndex);
+#endif
}
void
diff --git a/pr/src/misc/prenv.c b/pr/src/misc/prenv.c
index b6b36fad..716e1d5f 100644
--- a/pr/src/misc/prenv.c
+++ b/pr/src/misc/prenv.c
@@ -25,14 +25,16 @@
#define _PR_LOCK_ENV()
#define _PR_UNLOCK_ENV()
#elif defined(_PR_LOCAL_THREADS_ONLY)
+extern _PRCPU * _pr_primordialCPU;
+static PRIntn _is;
#define _PR_NEW_LOCK_ENV()
-#define _PR_LOCK_ENV() { PRIntn _is; _PR_INTSOFF(_is)
-#define _PR_UNLOCK_ENV() _PR_INTSON(_is); }
+#define _PR_LOCK_ENV() if (_pr_primordialCPU) _PR_INTSOFF(_is);
+#define _PR_UNLOCK_ENV() if (_pr_primordialCPU) _PR_INTSON(_is);
#else
-static PRLock *_pr_envLock;
+static PRLock *_pr_envLock = NULL;
#define _PR_NEW_LOCK_ENV() {_pr_envLock = PR_NewLock();}
-#define _PR_LOCK_ENV() PR_Lock(_pr_envLock)
-#define _PR_UNLOCK_ENV() PR_Unlock(_pr_envLock)
+#define _PR_LOCK_ENV() { if (_pr_envLock) PR_Lock(_pr_envLock); }
+#define _PR_UNLOCK_ENV() { if (_pr_envLock) PR_Unlock(_pr_envLock); }
#endif
/************************************************************************/
diff --git a/pr/src/pthreads/ptsynch.c b/pr/src/pthreads/ptsynch.c
index f3fa4711..128486eb 100644
--- a/pr/src/pthreads/ptsynch.c
+++ b/pr/src/pthreads/ptsynch.c
@@ -230,11 +230,7 @@ static PRIntn pt_TimedWait(
tmo.tv_nsec = (PRInt32)PR_IntervalToMicroseconds(PT_NANOPERMICRO * tmo.tv_nsec);
/* pthreads wants this in absolute time, off we go ... */
-#if defined(SOLARIS) && defined(_SVID_GETTOD)
- (void)gettimeofday(&now);
-#else
- (void)gettimeofday(&now, NULL);
-#endif
+ (void)GETTIMEOFDAY(&now);
/* that one's usecs, this one's nsecs - grrrr! */
tmo.tv_sec += now.tv_sec;
tmo.tv_nsec += (PT_NANOPERMICRO * now.tv_usec);
diff --git a/pr/src/threads/combined/prucpu.c b/pr/src/threads/combined/prucpu.c
index d528a2c6..99ad4d83 100644
--- a/pr/src/threads/combined/prucpu.c
+++ b/pr/src/threads/combined/prucpu.c
@@ -18,7 +18,7 @@
#include "primpl.h"
-_PRCPU *_pr_primordialCPU;
+_PRCPU *_pr_primordialCPU = NULL;
PRInt32 _pr_md_idle_cpus; /* number of idle cpus */
/*
diff --git a/pr/tests/Makefile b/pr/tests/Makefile
index 9b456944..9c96e3d3 100644
--- a/pr/tests/Makefile
+++ b/pr/tests/Makefile
@@ -49,6 +49,7 @@ CSRCS = \
cvar2.c \
dceemu.c \
dlltest.c \
+ dtoa.c \
exit.c \
fileio.c \
forktest.c \
@@ -73,6 +74,7 @@ CSRCS = \
multiwait.c \
many_cv.c \
nbconn.c \
+ nblayer.c \
nonblock.c \
op_2long.c \
op_filnf.c \
@@ -97,6 +99,7 @@ CSRCS = \
servr_kk.c \
servr_ku.c \
servr_uk.c \
+ short_thread.c \
sigpipe.c \
socket.c \
sockopt.c \
@@ -108,6 +111,7 @@ CSRCS = \
suspend.c \
switch.c \
system.c \
+ testbit.c \
testfile.c \
threads.c \
thruput.c \
@@ -409,6 +413,10 @@ LOGFILE = /dev/null
endif
endif
+ifeq ($(OS_TARGET),Linux)
+ECHO = /bin/echo
+endif
+
ALWAYS:
runtests:: $(PROGS) ALWAYS
@@ -423,6 +431,6 @@ runtests:: $(PROGS) ALWAYS
$(ECHO) "\t\t\tPassed"; \
else \
$(ECHO) "\t\t\tFAILED"; \
- fi \
+ fi; \
done
@$(ECHO) "\nEND\t\t`date`\n"
diff --git a/pr/tests/logger.c b/pr/tests/logger.c
index 5282f845..38780273 100644
--- a/pr/tests/logger.c
+++ b/pr/tests/logger.c
@@ -34,6 +34,19 @@
extern void SetupMacPrintfLog(char *logFile);
#endif
+/* lth. re-define PR_LOG() */
+#if 0
+#undef PR_LOG_TEST
+#undef PR_LOG
+#define PR_LOG_TEST(_module,_level) ((_module)->level <= (_level))
+#define PR_LOG(_module,_level,_args) \
+ { \
+ if (PR_LOG_TEST(_module,_level)) \
+ PR_LogPrint _args ; \
+ }
+#endif
+
+
static void Error(const char* msg)
{
printf("\t%s\n", msg);
@@ -65,6 +78,28 @@ static void PR_CALLBACK forked(void *arg)
PR_LogPrint("%s forked thread exiting\n", (const char*)arg);
}
+static void UserLogStuff( void )
+{
+ PRLogModuleInfo *myLM;
+ PRIntn i;
+
+ myLM = PR_NewLogModule( "userStuff" );
+ if (! myLM )
+ {
+ printf("UserLogStuff(): can't create new log module\n" );
+ return;
+ }
+
+ PR_LOG( myLM, PR_LOG_NOTICE, ("Log a Notice %d\n", 1 ));
+
+ for (i = 0; i < 10 ; i++ )
+ {
+ PR_LOG( myLM, PR_LOG_DEBUG, ("Log Debug number: %d\n", i));
+ PR_Sleep( 300 );
+ }
+
+} /* end UserLogStuff() */
+
int main(PRIntn argc, const char **argv)
{
PRThread *thread;
@@ -94,6 +129,8 @@ int main(PRIntn argc, const char **argv)
PR_LOCAL_THREAD, PR_JOINABLE_THREAD, 0);
PR_LogPrint("%s joining thread\n", argv[0]);
+ UserLogStuff();
+
PR_JoinThread(thread);
PR_LogFlush();
diff --git a/pr/tests/sleep.c b/pr/tests/sleep.c
index cc4eb524..97af7074 100644
--- a/pr/tests/sleep.c
+++ b/pr/tests/sleep.c
@@ -25,10 +25,10 @@
#include <unistd.h>
#include <sys/time.h>
-#if defined(SOLARIS)
+#if defined(HAVE_SVID_GETTOD)
#define GTOD(_a) gettimeofday(_a)
#else
-#define GTOD(_a) gettimeofday(_a, NULL)
+#define GTOD(_a) gettimeofday((_a), NULL)
#endif
static PRIntn rv = 0;
diff --git a/pr/tests/time.c b/pr/tests/time.c
index 8fad1f2c..84a30870 100644
--- a/pr/tests/time.c
+++ b/pr/tests/time.c
@@ -87,7 +87,7 @@ static void timeGettimeofday(void)
struct timeval tp;
for (;index--;)
- rv = gettimeofday(&tp);
+ rv = gettimeofday(&tp, NULL);
}
static void timePRTime32(void)