summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2005-02-22 07:09:17 +0000
committerNick Mathewson <nickm@torproject.org>2005-02-22 07:09:17 +0000
commitd37f4dd8a916f8b910e17ff7915783271fe5ab26 (patch)
tree373d736e7c94742cacf54ba5fafc05b5b4b2f94b /src/common
parent70c3580f81dd560072209fe32c740c33d3781c67 (diff)
downloadtor-d37f4dd8a916f8b910e17ff7915783271fe5ab26.tar.gz
tor-d37f4dd8a916f8b910e17ff7915783271fe5ab26.zip
But on windows, localtime and gmtime _are_ threadsafe.
svn:r3654
Diffstat (limited to 'src/common')
-rw-r--r--src/common/compat.c31
1 files changed, 27 insertions, 4 deletions
diff --git a/src/common/compat.c b/src/common/compat.c
index d7ed324b49..095f1b2f71 100644
--- a/src/common/compat.c
+++ b/src/common/compat.c
@@ -753,14 +753,18 @@ void tor_gettimeofday(struct timeval *timeval) {
return;
}
+
+#if defined(TOR_IS_MULTITHREADED) && !defined(MS_WINDOWS)
+#define TIME_FNS_NEED_LOCKS
+#endif
+
#ifndef HAVE_LOCALTIME_R
+#ifdef TIME_FNS_NEED_LOCKS
struct tm *tor_localtime_r(const time_t *timep, struct tm *result)
{
struct tm *r;
-#ifdef TOR_IS_MULTITHREADED
static tor_mutex_t *m=NULL;
if (!m) { m=tor_mutex_new(); }
-#endif
tor_assert(result);
tor_mutex_acquire(m);
r = localtime(timep);
@@ -768,16 +772,25 @@ struct tm *tor_localtime_r(const time_t *timep, struct tm *result)
tor_mutex_release(m);
return result;
}
+#else
+struct tm *tor_localtime_r(const time_t *timep, struct tm *result)
+{
+ struct tm *r;
+ tor_assert(result);
+ r = localtime(timep);
+ memcpy(result, r, sizeof(struct tm));
+ return result;
+}
+#endif
#endif
#ifndef HAVE_GMTIME_R
+#ifdef TIME_FNS_NEED_LOCKS
struct tm *tor_gmtime_r(const time_t *timep, struct tm *result)
{
struct tm *r;
-#ifdef TOR_IS_MULTITHREADED
static tor_mutex_t *m=NULL;
if (!m) { m=tor_mutex_new(); }
-#endif
tor_assert(result);
tor_mutex_acquire(m);
r = gmtime(timep);
@@ -785,6 +798,16 @@ struct tm *tor_gmtime_r(const time_t *timep, struct tm *result)
tor_mutex_release(m);
return result;
}
+#else
+struct tm *tor_gmtime_r(const time_t *timep, struct tm *result)
+{
+ struct tm *r;
+ tor_assert(result);
+ r = gmtime(timep);
+ memcpy(result, r, sizeof(struct tm));
+ return result;
+}
+#endif
#endif
#ifdef USE_WIN32_THREADS