From: Stefan Neis Date: Sun, 18 Dec 2005 19:24:11 +0000 (+0000) Subject: Added implementation for wxLocaltime_r/wxGmtime_r. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/cf44a61c2410fab7cc9b71c5f2578296e44c28e7?ds=inline Added implementation for wxLocaltime_r/wxGmtime_r. Improved handling of windows compilers. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@36438 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/datetime.h b/include/wx/datetime.h index 42d9e4f926..2f331299ad 100644 --- a/include/wx/datetime.h +++ b/include/wx/datetime.h @@ -57,15 +57,21 @@ class WXDLLIMPEXP_BASE wxDateSpan; #define wxLocaltime_r localtime_r #else struct tm *wxLocaltime_r(const time_t*, struct tm*); +#if !defined(__WINDOWS__) + // 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 struct tm *wxGmtime_r(const time_t*, struct tm*); +#if !defined(__WINDOWS__) + // 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/src/common/datetime.cpp b/src/common/datetime.cpp index 8448eb1a5e..12732e144b 100644 --- a/src/common/datetime.cpp +++ b/src/common/datetime.cpp @@ -169,6 +169,36 @@ wxCUSTOM_TYPE_INFO(wxDateTime, wxToStringConverter , wxFromStringCon #endif #endif // !WX_TIMEZONE && !WX_GMTOFF_IN_TM +#if wxUSE_THREADS +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(timeLock); +#endif + memcpy(temp, localtime(ticks), sizeof(struct tm)); + return temp; +} +#endif + +#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(timeLock); +#endif + memcpy(temp, gmtime(ticks), sizeof(struct tm)); + return temp; +} +#endif + // ---------------------------------------------------------------------------- // macros // ----------------------------------------------------------------------------