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
This commit is contained in:
parent
603c73dbba
commit
fb7ce3e8cc
@ -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:
|
||||
|
||||
|
@ -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_
|
||||
|
@ -109,90 +109,6 @@ wxCUSTOM_TYPE_INFO(wxDateTime, wxToStringConverter<wxDateTime> , wxFromStringCon
|
||||
|
||||
#endif // wxUSE_EXTENDED_RTTI
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// conditional compilation
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#if defined(__MWERKS__) && wxUSE_UNICODE
|
||||
#include <wtime.h>
|
||||
#endif
|
||||
|
||||
#if defined(__DJGPP__) || defined(__WINE__)
|
||||
#include <sys/timeb.h>
|
||||
#include <values.h>
|
||||
#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
|
||||
// ----------------------------------------------------------------------------
|
||||
|
@ -80,6 +80,15 @@
|
||||
#include <SystemMgr.h>
|
||||
#endif
|
||||
|
||||
#if defined(__MWERKS__) && wxUSE_UNICODE
|
||||
#include <wtime.h>
|
||||
#endif
|
||||
|
||||
#if defined(__DJGPP__) || defined(__WINE__)
|
||||
#include <sys/timeb.h>
|
||||
#include <values.h>
|
||||
#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()
|
||||
|
Loading…
Reference in New Issue
Block a user