diff options
author | wtchang%redhat.com <devnull@localhost> | 2006-12-01 23:20:12 +0000 |
---|---|---|
committer | wtchang%redhat.com <devnull@localhost> | 2006-12-01 23:20:12 +0000 |
commit | 17bd8d73bb6e897e73a1b1e414c0aae09abe5f6a (patch) | |
tree | 02af714227c44e270d95440e6feb8b1b74c33f59 | |
parent | b07969053f43a7a46e25b1eb3d2f0b16f66e0ced (diff) | |
download | nspr-hg-17bd8d73bb6e897e73a1b1e414c0aae09abe5f6a.tar.gz |
Bugzilla Bug 354593: fixed a race condition in the creation of the lock
that protects localtime() by creating the lock during NSPR initialization.
r=aleksey.sanin,nelson.bolyard. The patch is contributed by Mark Stevans
<marks@coral8.com>.
Modified files: primpl.h prinit.c prtime.c ptthread.c
Tag: NSPRPUB_PRE_4_2_CLIENT_BRANCH
-rw-r--r-- | pr/include/private/primpl.h | 2 | ||||
-rw-r--r-- | pr/src/misc/prinit.c | 2 | ||||
-rw-r--r-- | pr/src/misc/prtime.c | 26 | ||||
-rw-r--r-- | pr/src/pthreads/ptthread.c | 1 |
4 files changed, 25 insertions, 6 deletions
diff --git a/pr/include/private/primpl.h b/pr/include/private/primpl.h index 1565d184..ca9e7c7c 100644 --- a/pr/include/private/primpl.h +++ b/pr/include/private/primpl.h @@ -1792,12 +1792,14 @@ extern void _PR_InitLinker(void); extern void _PR_InitAtomic(void); extern void _PR_InitCPUs(void); extern void _PR_InitDtoa(void); +extern void _PR_InitTime(void); extern void _PR_InitMW(void); extern void _PR_InitRWLocks(void); extern void _PR_NotifyCondVar(PRCondVar *cvar, PRThread *me); extern void _PR_CleanupThread(PRThread *thread); extern void _PR_CleanupCallOnce(void); extern void _PR_CleanupMW(void); +extern void _PR_CleanupTime(void); extern void _PR_CleanupDtoa(void); extern void _PR_ShutdownLinker(void); extern void _PR_CleanupEnv(void); diff --git a/pr/src/misc/prinit.c b/pr/src/misc/prinit.c index 3fb92f18..9ab3ddc9 100644 --- a/pr/src/misc/prinit.c +++ b/pr/src/misc/prinit.c @@ -241,6 +241,7 @@ static void _PR_InitStuff(void) _PR_InitLinker(); _PR_InitCallOnce(); _PR_InitDtoa(); + _PR_InitTime(); _PR_InitMW(); _PR_InitRWLocks(); @@ -420,6 +421,7 @@ PR_IMPLEMENT(PRStatus) PR_Cleanup() #endif _PR_CleanupMW(); + _PR_CleanupTime(); _PR_CleanupDtoa(); _PR_CleanupCallOnce(); _PR_ShutdownLinker(); diff --git a/pr/src/misc/prtime.c b/pr/src/misc/prtime.c index 57761970..4826c1c3 100644 --- a/pr/src/misc/prtime.c +++ b/pr/src/misc/prtime.c @@ -547,6 +547,8 @@ PR_NormalizeTime(PRExplodedTime *time, PRTimeParamFn params) extern struct tm *Maclocaltime(const time_t * t); #endif +#define HAVE_LOCALTIME_MONITOR 1 /* We use 'monitor' to serialize our calls + * to localtime(). */ static PRLock *monitor = NULL; static struct tm *MT_safe_localtime(const time_t *clock, struct tm *result) @@ -556,12 +558,7 @@ static struct tm *MT_safe_localtime(const time_t *clock, struct tm *result) * against NSPR threads only when the * NSPR thread system is activated. */ - if (needLock) { - if (monitor == NULL) { - monitor = PR_NewLock(); - } - PR_Lock(monitor); - } + if (needLock) PR_Lock(monitor); /* * Microsoft (all flavors) localtime() returns a NULL pointer if 'clock' @@ -606,6 +603,23 @@ static struct tm *MT_safe_localtime(const time_t *clock, struct tm *result) #endif /* definition of MT_safe_localtime() */ +void _PR_InitTime(void) +{ +#ifdef HAVE_LOCALTIME_MONITOR + monitor = PR_NewLock(); +#endif +} + +void _PR_CleanupTime(void) +{ +#ifdef HAVE_LOCALTIME_MONITOR + if (monitor) { + PR_DestroyLock(monitor); + monitor = NULL; + } +#endif +} + #if defined(XP_UNIX) || defined(XP_PC) || defined(XP_BEOS) PR_IMPLEMENT(PRTimeParameters) diff --git a/pr/src/pthreads/ptthread.c b/pr/src/pthreads/ptthread.c index 3a8303ae..edefb443 100644 --- a/pr/src/pthreads/ptthread.c +++ b/pr/src/pthreads/ptthread.c @@ -938,6 +938,7 @@ PR_IMPLEMENT(PRStatus) PR_Cleanup(void) PR_Unlock(pt_book.ml); _PR_CleanupMW(); + _PR_CleanupTime(); _PR_CleanupDtoa(); _PR_CleanupCallOnce(); _PR_ShutdownLinker(); |