diff options
author | wtchang%redhat.com <devnull@localhost> | 2006-12-01 00:34:12 +0000 |
---|---|---|
committer | wtchang%redhat.com <devnull@localhost> | 2006-12-01 00:34:12 +0000 |
commit | ba08b5901f3847c2a13b12c621f675ffb1abe2ed (patch) | |
tree | 0d652512472a66ac0e7c392adfec3a0f57576ebe | |
parent | 14393c712f846a22ff486ff72ef8cf31b57d075a (diff) | |
download | nspr-hg-ba08b5901f3847c2a13b12c621f675ffb1abe2ed.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: NSPR_4_6_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 eebcb841..1388f94f 100644 --- a/pr/include/private/primpl.h +++ b/pr/include/private/primpl.h @@ -1780,12 +1780,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 1ecfb3d1..db36b212 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 cf5554b2..17d13bcd 100644 --- a/pr/src/misc/prtime.c +++ b/pr/src/misc/prtime.c @@ -569,6 +569,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) @@ -578,12 +580,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' @@ -628,6 +625,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 c8b41c11..778a4a7f 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(); |