summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qdatetime_p.h
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2015-01-14 16:33:03 -0800
committerThiago Macieira <thiago.macieira@intel.com>2015-03-07 19:22:21 +0000
commita8c74ddcf78604c9038ba2a2bea81e445e4b3c58 (patch)
tree766754fbd27e7b18a72c54871f0b2699d2ee5e33 /src/corelib/tools/qdatetime_p.h
parent84b9d071630a63a493773f612eefe83c8e68390d (diff)
Fix race condition in QDateTime::timeZone() and other methods
When timezone support for QDateTime was added, we decided it was a good idea to delay creating the QTimeZone object and checking that the time is valid in that timezone (including for local time) until the user requested that information. Unfortunately, QExplicitlySharedDataPointer returns a non-const T* in operator->(), which meant we were accidentally modifying the d pointer's contents in const methods, which in turn means those const methods were not thread-safe when operating on the same object. This commit changes the d pointer to QSharedDataPointer, which is safer in this regard and pointed out where the issues with constness were located. Since we can't lazily calculate QTimeZone anymore, we need to do it whenever the date, time or offset changes. Task-number: QTBUG-43703 Change-Id: Ic5d393bfd36e48a193fcffff13b9686ef4ef1454 Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'src/corelib/tools/qdatetime_p.h')
-rw-r--r--src/corelib/tools/qdatetime_p.h14
1 files changed, 5 insertions, 9 deletions
diff --git a/src/corelib/tools/qdatetime_p.h b/src/corelib/tools/qdatetime_p.h
index a139390a9d..b8934f7f70 100644
--- a/src/corelib/tools/qdatetime_p.h
+++ b/src/corelib/tools/qdatetime_p.h
@@ -79,10 +79,9 @@ public:
enum StatusFlag {
NullDate = 0x01,
NullTime = 0x02,
- ValidDate = 0x04,
- ValidTime = 0x08,
- ValidDateTime = 0x10,
- TimeZoneCached = 0x20,
+ ValidDate = 0x04, // just the date field
+ ValidTime = 0x08, // just the time field
+ ValidDateTime = 0x10, // the whole object (including timezone)
SetToStandardTime = 0x40,
SetToDaylightTime = 0x80
};
@@ -120,7 +119,7 @@ public:
DaylightStatus daylightStatus() const;
// Returns msecs since epoch, assumes offset value is current
- inline qint64 toMSecsSinceEpoch() const { return (m_msecs - (m_offsetFromUtc * 1000)); }
+ inline qint64 toMSecsSinceEpoch() const;
void checkValidDateTime();
void refreshDateTime();
@@ -133,14 +132,11 @@ public:
inline bool isValidDateTime() const { return m_status & ValidDateTime; }
inline void setValidDateTime() { m_status |= ValidDateTime; }
inline void clearValidDateTime() { m_status &= ~ValidDateTime; }
- inline bool isTimeZoneCached() const { return m_status & TimeZoneCached; }
- inline void setTimeZoneCached() { m_status |= TimeZoneCached; }
- inline void clearTimeZoneCached() { m_status &= ~TimeZoneCached; }
inline void clearSetToDaylightStatus() { m_status &= ~(SetToStandardTime | SetToDaylightTime); }
#ifndef QT_BOOTSTRAPPED
static qint64 zoneMSecsToEpochMSecs(qint64 msecs, const QTimeZone &zone,
- QDate *localDate, QTime *localTime);
+ QDate *localDate = 0, QTime *localTime = 0);
#endif // QT_BOOTSTRAPPED
static inline qint64 minJd() { return QDate::minJd(); }