aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCorinna Vinschen <corinna@vinschen.de>2007-12-11 16:14:33 +0000
committerCorinna Vinschen <corinna@vinschen.de>2007-12-11 16:14:33 +0000
commit010ed82365239363ae070b21472ee8e407ebb127 (patch)
tree28a860cb4543f05dc3d12fcb79dbe7d27d90ac1a
parent6d389d39edf4f4c30dbd02db567d9c0e01eb7e09 (diff)
downloadnewlib-010ed82365239363ae070b21472ee8e407ebb127.zip
newlib-010ed82365239363ae070b21472ee8e407ebb127.tar.gz
newlib-010ed82365239363ae070b21472ee8e407ebb127.tar.bz2
* localtime.cc (tzset): Guard by a muto for thread safety.
-rw-r--r--winsup/cygwin/ChangeLog4
-rw-r--r--winsup/cygwin/localtime.cc12
2 files changed, 13 insertions, 3 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog
index 4cf3f78..ca28c9b 100644
--- a/winsup/cygwin/ChangeLog
+++ b/winsup/cygwin/ChangeLog
@@ -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>
* cygheap.cc (_csbrk): Don't request zero bytes from VirtualAlloc,
diff --git a/winsup/cygwin/localtime.cc b/winsup/cygwin/localtime.cc
index a2f415f..3d08cc6 100644
--- a/winsup/cygwin/localtime.cc
+++ b/winsup/cygwin/localtime.cc
@@ -6,6 +6,7 @@
#include "winsup.h"
#include "cygerrno.h"
+#include "sync.h"
#include <windows.h>
#define STD_INSPIRED
#define lint
@@ -1470,19 +1471,22 @@ tzsetwall P((void))
settzname();
}
+static NO_COPY muto tzset_guard;
+
extern "C" void
tzset P((void))
{
+ tzset_guard.init ("tzset_guard")->acquire ();
const char * name = getenv("TZ");
if (name == NULL) {
if (!lcl_is_set)
tzsetwall();
- return;
+ goto out;
}
if (lcl_is_set > 0 && strcmp(lcl_TZname, name) == 0)
- return;
+ goto out;
lcl_is_set = (strlen(name) < sizeof (lcl_TZname));
if (lcl_is_set)
strcpy(lcl_TZname, name);
@@ -1492,7 +1496,7 @@ tzset P((void))
lclptr = (struct state *) malloc(sizeof *lclptr);
if (lclptr == NULL) {
settzname(); /* all we can do */
- return;
+ goto out;
}
}
#endif /* defined ALL_STATE */
@@ -1510,6 +1514,8 @@ tzset P((void))
gmtload(lclptr);
}
settzname();
+out:
+ tzset_guard.release ();
}
/*