[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] But on windows, localtime and gmtime _are_ threadsafe.
Update of /home/or/cvsroot/tor/src/common
In directory moria.mit.edu:/tmp/cvs-serv7915/src/common
Modified Files:
compat.c
Log Message:
But on windows, localtime and gmtime _are_ threadsafe.
Index: compat.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/common/compat.c,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -d -r1.39 -r1.40
--- compat.c 22 Feb 2005 07:03:02 -0000 1.39
+++ compat.c 22 Feb 2005 07:09:17 -0000 1.40
@@ -753,14 +753,18 @@
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 @@
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 @@
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