diff options
author | Nick Mathewson <nickm@torproject.org> | 2005-02-22 07:03:03 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2005-02-22 07:03:03 +0000 |
commit | 70c3580f81dd560072209fe32c740c33d3781c67 (patch) | |
tree | a914e5d669ef9bf6d7b3ed79a07157cd676c9c61 /src/common/compat.h | |
parent | d01718841e5bc3d365191e74bebbccee48c8b045 (diff) | |
download | tor-70c3580f81dd560072209fe32c740c33d3781c67.tar.gz tor-70c3580f81dd560072209fe32c740c33d3781c67.zip |
Patch to localtime/gmtime handling: use the _r variants where available. Use mutexes to fake _r where necessary. Make mutexes no-ops where no threading is enabled.
svn:r3653
Diffstat (limited to 'src/common/compat.h')
-rw-r--r-- | src/common/compat.h | 38 |
1 files changed, 30 insertions, 8 deletions
diff --git a/src/common/compat.h b/src/common/compat.h index 8efc63e9d6..ec433ddd7b 100644 --- a/src/common/compat.h +++ b/src/common/compat.h @@ -104,6 +104,18 @@ struct timeval { void tor_gettimeofday(struct timeval *timeval); +#ifdef HAVE_LOCALTIME_R +#define tor_localtime_r localtime_r +#else +struct tm *tor_localtime_r(const time_t *timep, struct tm *result); +#endif + +#ifdef HAVE_GMTIME_R +#define tor_gmtime_r gmtime_r +#else +struct tm *tor_gmtime_r(const time_t *timep, struct tm *result); +#endif + /* ===== File compatibility */ int replace_file(const char *from, const char *to); @@ -192,14 +204,6 @@ char *get_user_homedir(const char *username); int spawn_func(int (*func)(void *), void *data); void spawn_exit(void); -/* Because we use threads instead of processes on Windows, we need locking on - * Windows. On Unixy platforms, these functions are no-ops. */ -typedef struct tor_mutex_t tor_mutex_t; -tor_mutex_t *tor_mutex_new(void); -void tor_mutex_acquire(tor_mutex_t *m); -void tor_mutex_release(tor_mutex_t *m); -void tor_mutex_free(tor_mutex_t *m); -unsigned long tor_get_thread_id(void); #if defined(MS_WINDOWS) #define USE_WIN32_THREADS @@ -211,5 +215,23 @@ unsigned long tor_get_thread_id(void); #undef TOR_IS_MULTITHREADED #endif +/* Because we use threads instead of processes on Windows, we need locking on + * Windows. On Unixy platforms, these functions are no-ops. */ +typedef struct tor_mutex_t tor_mutex_t; +#ifdef TOR_IS_MULTITHREADED +tor_mutex_t *tor_mutex_new(void); +void tor_mutex_acquire(tor_mutex_t *m); +void tor_mutex_release(tor_mutex_t *m); +void tor_mutex_free(tor_mutex_t *m); +unsigned long tor_get_thread_id(void); +#else +#define tor_mutex_new() ((tor_mutex_t*)tor_malloc(sizeof(int))) +#define tor_mutex_acquire(m) do { } while (0) +#define tor_mutex_release(m) do { } while (0) +#define tor_mutex_free(m) do { tor_free(m); } while(0) +#define tor_get_thread_id() (1UL) +#endif + + #endif |