* localtime.cc (tzset): Guard by a muto for thread safety.

This commit is contained in:
Corinna Vinschen 2007-12-11 16:14:24 +00:00
parent 3623cfa399
commit ea5bc3721f
2 changed files with 13 additions and 3 deletions

View File

@ -1,3 +1,7 @@
2007-12-11 Corinna Vinschen <corinna@vinschen.de>
* localtime.cc (tzset): Guard by a muto for thread safety.
2007-12-11 Dave Korn <dave.korn@artimi.com> 2007-12-11 Dave Korn <dave.korn@artimi.com>
* cygheap.cc (_csbrk): Don't request zero bytes from VirtualAlloc, * cygheap.cc (_csbrk): Don't request zero bytes from VirtualAlloc,

View File

@ -6,6 +6,7 @@
#include "winsup.h" #include "winsup.h"
#include "cygerrno.h" #include "cygerrno.h"
#include "sync.h"
#include <windows.h> #include <windows.h>
#define STD_INSPIRED #define STD_INSPIRED
#define lint #define lint
@ -1470,19 +1471,22 @@ tzsetwall P((void))
settzname(); settzname();
} }
static NO_COPY muto tzset_guard;
extern "C" void extern "C" void
tzset P((void)) tzset P((void))
{ {
tzset_guard.init ("tzset_guard")->acquire ();
const char * name = getenv("TZ"); const char * name = getenv("TZ");
if (name == NULL) { if (name == NULL) {
if (!lcl_is_set) if (!lcl_is_set)
tzsetwall(); tzsetwall();
return; goto out;
} }
if (lcl_is_set > 0 && strcmp(lcl_TZname, name) == 0) if (lcl_is_set > 0 && strcmp(lcl_TZname, name) == 0)
return; goto out;
lcl_is_set = (strlen(name) < sizeof (lcl_TZname)); lcl_is_set = (strlen(name) < sizeof (lcl_TZname));
if (lcl_is_set) if (lcl_is_set)
strcpy(lcl_TZname, name); strcpy(lcl_TZname, name);
@ -1492,7 +1496,7 @@ tzset P((void))
lclptr = (struct state *) malloc(sizeof *lclptr); lclptr = (struct state *) malloc(sizeof *lclptr);
if (lclptr == NULL) { if (lclptr == NULL) {
settzname(); /* all we can do */ settzname(); /* all we can do */
return; goto out;
} }
} }
#endif /* defined ALL_STATE */ #endif /* defined ALL_STATE */
@ -1510,6 +1514,8 @@ tzset P((void))
gmtload(lclptr); gmtload(lclptr);
} }
settzname(); settzname();
out:
tzset_guard.release ();
} }
/* /*