From fb7ce3e8cc980192d8ef0f7775a55206eb4c514a Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 27 Nov 2011 20:28:43 +0000 Subject: [PATCH] No changes, just moved wxLocaltime_r() and wxGmtime_r() to wx/time.h. These functions are used by wxGetTimeZone() defined in time.cpp and so need to be available from wx/time.h. This is also the most logical place for them. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@69846 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/datetime.h | 21 ----------- include/wx/time.h | 21 +++++++++++ src/common/datetime.cpp | 84 ----------------------------------------- src/common/time.cpp | 79 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 100 insertions(+), 105 deletions(-) diff --git a/include/wx/datetime.h b/include/wx/datetime.h index 6b5b7f0412..42279c2a38 100644 --- a/include/wx/datetime.h +++ b/include/wx/datetime.h @@ -53,27 +53,6 @@ struct _SYSTEMTIME; * 5. wxDateTimeHolidayAuthority for Easter and other christian feasts */ -/* Two wrapper functions for thread safety */ -#ifdef HAVE_LOCALTIME_R -#define wxLocaltime_r localtime_r -#else -WXDLLIMPEXP_BASE struct tm *wxLocaltime_r(const time_t*, struct tm*); -#if wxUSE_THREADS && !defined(__WINDOWS__) && !defined(__WATCOMC__) - // On Windows, localtime _is_ threadsafe! -#warning using pseudo thread-safe wrapper for localtime to emulate localtime_r -#endif -#endif - -#ifdef HAVE_GMTIME_R -#define wxGmtime_r gmtime_r -#else -WXDLLIMPEXP_BASE struct tm *wxGmtime_r(const time_t*, struct tm*); -#if wxUSE_THREADS && !defined(__WINDOWS__) && !defined(__WATCOMC__) - // On Windows, gmtime _is_ threadsafe! -#warning using pseudo thread-safe wrapper for gmtime to emulate gmtime_r -#endif -#endif - /* The three (main) classes declared in this header represent: diff --git a/include/wx/time.h b/include/wx/time.h index d6ff8ba04e..8b79d3ec57 100644 --- a/include/wx/time.h +++ b/include/wx/time.h @@ -53,4 +53,25 @@ wxLongLong WXDLLIMPEXP_BASE wxGetUTCTimeUSec(); #endif #endif // HAVE_GETTIMEOFDAY +/* Two wrapper functions for thread safety */ +#ifdef HAVE_LOCALTIME_R +#define wxLocaltime_r localtime_r +#else +WXDLLIMPEXP_BASE struct tm *wxLocaltime_r(const time_t*, struct tm*); +#if wxUSE_THREADS && !defined(__WINDOWS__) && !defined(__WATCOMC__) + // On Windows, localtime _is_ threadsafe! +#warning using pseudo thread-safe wrapper for localtime to emulate localtime_r +#endif +#endif + +#ifdef HAVE_GMTIME_R +#define wxGmtime_r gmtime_r +#else +WXDLLIMPEXP_BASE struct tm *wxGmtime_r(const time_t*, struct tm*); +#if wxUSE_THREADS && !defined(__WINDOWS__) && !defined(__WATCOMC__) + // On Windows, gmtime _is_ threadsafe! +#warning using pseudo thread-safe wrapper for gmtime to emulate gmtime_r +#endif +#endif + #endif // _WX_TIME_H_ diff --git a/src/common/datetime.cpp b/src/common/datetime.cpp index 066ac07047..90038a27c3 100644 --- a/src/common/datetime.cpp +++ b/src/common/datetime.cpp @@ -109,90 +109,6 @@ wxCUSTOM_TYPE_INFO(wxDateTime, wxToStringConverter , wxFromStringCon #endif // wxUSE_EXTENDED_RTTI - -// ---------------------------------------------------------------------------- -// conditional compilation -// ---------------------------------------------------------------------------- - -#if defined(__MWERKS__) && wxUSE_UNICODE - #include -#endif - -#if defined(__DJGPP__) || defined(__WINE__) - #include - #include -#endif - -// NB: VC8 safe time functions could/should be used for wxMSW as well probably -#if defined(__WXWINCE__) && defined(__VISUALC8__) - -struct tm *wxLocaltime_r(const time_t *t, struct tm* tm) -{ - __time64_t t64 = *t; - return _localtime64_s(tm, &t64) == 0 ? tm : NULL; -} - -struct tm *wxGmtime_r(const time_t* t, struct tm* tm) -{ - __time64_t t64 = *t; - return _gmtime64_s(tm, &t64) == 0 ? tm : NULL; -} - -#else // !wxWinCE with VC8 - -#if (!defined(HAVE_LOCALTIME_R) || !defined(HAVE_GMTIME_R)) && wxUSE_THREADS && !defined(__WINDOWS__) -static wxMutex timeLock; -#endif - -#ifndef HAVE_LOCALTIME_R -struct tm *wxLocaltime_r(const time_t* ticks, struct tm* temp) -{ -#if wxUSE_THREADS && !defined(__WINDOWS__) - // No need to waste time with a mutex on windows since it's using - // thread local storage for localtime anyway. - wxMutexLocker locker(timeLock); -#endif - - // Borland CRT crashes when passed 0 ticks for some reason, see SF bug 1704438 -#ifdef __BORLANDC__ - if ( !*ticks ) - return NULL; -#endif - - const tm * const t = localtime(ticks); - if ( !t ) - return NULL; - - memcpy(temp, t, sizeof(struct tm)); - return temp; -} -#endif // !HAVE_LOCALTIME_R - -#ifndef HAVE_GMTIME_R -struct tm *wxGmtime_r(const time_t* ticks, struct tm* temp) -{ -#if wxUSE_THREADS && !defined(__WINDOWS__) - // No need to waste time with a mutex on windows since it's - // using thread local storage for gmtime anyway. - wxMutexLocker locker(timeLock); -#endif - -#ifdef __BORLANDC__ - if ( !*ticks ) - return NULL; -#endif - - const tm * const t = gmtime(ticks); - if ( !t ) - return NULL; - - memcpy(temp, gmtime(ticks), sizeof(struct tm)); - return temp; -} -#endif // !HAVE_GMTIME_R - -#endif // wxWinCE with VC8/other platforms - // ---------------------------------------------------------------------------- // macros // ---------------------------------------------------------------------------- diff --git a/src/common/time.cpp b/src/common/time.cpp index 3b60d27438..03df19ec62 100644 --- a/src/common/time.cpp +++ b/src/common/time.cpp @@ -80,6 +80,15 @@ #include #endif +#if defined(__MWERKS__) && wxUSE_UNICODE + #include +#endif + +#if defined(__DJGPP__) || defined(__WINE__) + #include + #include +#endif + namespace { @@ -93,6 +102,76 @@ const int MICROSECONDS_PER_SECOND = 1000*1000; // implementation // ============================================================================ +// NB: VC8 safe time functions could/should be used for wxMSW as well probably +#if defined(__WXWINCE__) && defined(__VISUALC8__) + +struct tm *wxLocaltime_r(const time_t *t, struct tm* tm) +{ + __time64_t t64 = *t; + return _localtime64_s(tm, &t64) == 0 ? tm : NULL; +} + +struct tm *wxGmtime_r(const time_t* t, struct tm* tm) +{ + __time64_t t64 = *t; + return _gmtime64_s(tm, &t64) == 0 ? tm : NULL; +} + +#else // !wxWinCE with VC8 + +#if (!defined(HAVE_LOCALTIME_R) || !defined(HAVE_GMTIME_R)) && wxUSE_THREADS && !defined(__WINDOWS__) +static wxMutex timeLock; +#endif + +#ifndef HAVE_LOCALTIME_R +struct tm *wxLocaltime_r(const time_t* ticks, struct tm* temp) +{ +#if wxUSE_THREADS && !defined(__WINDOWS__) + // No need to waste time with a mutex on windows since it's using + // thread local storage for localtime anyway. + wxMutexLocker locker(timeLock); +#endif + + // Borland CRT crashes when passed 0 ticks for some reason, see SF bug 1704438 +#ifdef __BORLANDC__ + if ( !*ticks ) + return NULL; +#endif + + const tm * const t = localtime(ticks); + if ( !t ) + return NULL; + + memcpy(temp, t, sizeof(struct tm)); + return temp; +} +#endif // !HAVE_LOCALTIME_R + +#ifndef HAVE_GMTIME_R +struct tm *wxGmtime_r(const time_t* ticks, struct tm* temp) +{ +#if wxUSE_THREADS && !defined(__WINDOWS__) + // No need to waste time with a mutex on windows since it's + // using thread local storage for gmtime anyway. + wxMutexLocker locker(timeLock); +#endif + +#ifdef __BORLANDC__ + if ( !*ticks ) + return NULL; +#endif + + const tm * const t = gmtime(ticks); + if ( !t ) + return NULL; + + memcpy(temp, gmtime(ticks), sizeof(struct tm)); + return temp; +} +#endif // !HAVE_GMTIME_R + +#endif // wxWinCE with VC8/other platforms + // returns the time zone in the C sense, i.e. the difference UTC - local // (in seconds) int wxGetTimeZone() -- 2.45.2