summaryrefslogtreecommitdiffstats
path: root/src/corelib/thread/qmutex.h
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@nokia.com>2010-03-01 21:40:04 (GMT)
committerThiago Macieira <thiago.macieira@nokia.com>2010-03-02 13:56:11 (GMT)
commitc1b067ea8169e1d37e2a120334406f1f115298bb (patch)
tree327f48290a23ff77e88f277830a29879d38ad8ad /src/corelib/thread/qmutex.h
parent6711f49a6c08c08759cb2185bf202d4b316d33df (diff)
downloadQt-c1b067ea8169e1d37e2a120334406f1f115298bb.zip
Qt-c1b067ea8169e1d37e2a120334406f1f115298bb.tar.gz
Qt-c1b067ea8169e1d37e2a120334406f1f115298bb.tar.bz2
Fix strict-aliasing breakage with SunCC: the union trick is a GCC extension.
It's probably also an MSVC extension, because the MSVC compiler has never complained about this fact, nor generated unintended code. Anyway, the only way is to reinterpret_cast the quintptr. It's not an aliasing violation to do it because we never access the integer as anything other than quintptr. Reviewed-By: Bradley T. Hughes
Diffstat (limited to 'src/corelib/thread/qmutex.h')
-rw-r--r--src/corelib/thread/qmutex.h15
1 files changed, 6 insertions, 9 deletions
diff --git a/src/corelib/thread/qmutex.h b/src/corelib/thread/qmutex.h
index 80b50fc..677412e 100644
--- a/src/corelib/thread/qmutex.h
+++ b/src/corelib/thread/qmutex.h
@@ -95,7 +95,7 @@ class Q_CORE_EXPORT QMutexLocker
{
public:
inline explicit QMutexLocker(QMutex *m)
- : mtx(m)
+ : val(reinterpret_cast<quintptr>(m))
{
Q_ASSERT_X((val & quintptr(1u)) == quintptr(0),
"QMutexLocker", "QMutex pointer is misaligned");
@@ -105,19 +105,19 @@ public:
inline void unlock()
{
- if (mtx) {
+ if (val) {
if ((val & quintptr(1u)) == quintptr(1u)) {
val &= ~quintptr(1u);
- mtx->unlock();
+ mutex()->unlock();
}
}
}
inline void relock()
{
- if (mtx) {
+ if (val) {
if ((val & quintptr(1u)) == quintptr(0u)) {
- mtx->lock();
+ mutex()->lock();
val |= quintptr(1u);
}
}
@@ -140,10 +140,7 @@ public:
private:
Q_DISABLE_COPY(QMutexLocker)
- union {
- QMutex *mtx;
- quintptr val;
- };
+ quintptr val;
};
#else // QT_NO_THREAD