summaryrefslogtreecommitdiffstats
path: root/src/corelib/thread/qreadwritelock.h
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@nokia.com>2010-03-02 14:20:06 (GMT)
committerThiago Macieira <thiago.macieira@nokia.com>2010-03-03 10:14:32 (GMT)
commitffc3dc445afe38d006e1fb036b9b90ff19fa204e (patch)
tree400aaf9bfcbfc4181f35dd82c5e1aff65c828eac /src/corelib/thread/qreadwritelock.h
parent9b50db437abb5766751d00e5c51fadd0bc79b6d4 (diff)
downloadQt-ffc3dc445afe38d006e1fb036b9b90ff19fa204e.zip
Qt-ffc3dc445afe38d006e1fb036b9b90ff19fa204e.tar.gz
Qt-ffc3dc445afe38d006e1fb036b9b90ff19fa204e.tar.bz2
Follow-up to c1b067e: fix aliasing in QReadWriteLock too.
The same pattern used in QMutexLocker was used in QReadLocker and QWriteLocker. Reviewed-by: Trust Me
Diffstat (limited to 'src/corelib/thread/qreadwritelock.h')
-rw-r--r--src/corelib/thread/qreadwritelock.h30
1 files changed, 12 insertions, 18 deletions
diff --git a/src/corelib/thread/qreadwritelock.h b/src/corelib/thread/qreadwritelock.h
index 278b8d4..9521ac3 100644
--- a/src/corelib/thread/qreadwritelock.h
+++ b/src/corelib/thread/qreadwritelock.h
@@ -96,19 +96,19 @@ public:
inline void unlock()
{
- if (q_lock) {
+ if (q_val) {
if ((q_val & quintptr(1u)) == quintptr(1u)) {
q_val &= ~quintptr(1u);
- q_lock->unlock();
+ readWriteLock()->unlock();
}
}
}
inline void relock()
{
- if (q_lock) {
+ if (q_val) {
if ((q_val & quintptr(1u)) == quintptr(0u)) {
- q_lock->lockForRead();
+ readWriteLock()->lockForRead();
q_val |= quintptr(1u);
}
}
@@ -119,14 +119,11 @@ public:
private:
Q_DISABLE_COPY(QReadLocker)
- union {
- QReadWriteLock *q_lock;
- quintptr q_val;
- };
+ quintptr q_val;
};
inline QReadLocker::QReadLocker(QReadWriteLock *areadWriteLock)
- : q_lock(areadWriteLock)
+ : q_val(reinterpret_cast<quintptr>(areadWriteLock))
{
Q_ASSERT_X((q_val & quintptr(1u)) == quintptr(0),
"QReadLocker", "QReadWriteLock pointer is misaligned");
@@ -143,19 +140,19 @@ public:
inline void unlock()
{
- if (q_lock) {
+ if (q_val) {
if ((q_val & quintptr(1u)) == quintptr(1u)) {
q_val &= ~quintptr(1u);
- q_lock->unlock();
+ readWriteLock()->unlock();
}
}
}
inline void relock()
{
- if (q_lock) {
+ if (q_val) {
if ((q_val & quintptr(1u)) == quintptr(0u)) {
- q_lock->lockForWrite();
+ readWriteLock()->lockForWrite();
q_val |= quintptr(1u);
}
}
@@ -167,14 +164,11 @@ public:
private:
Q_DISABLE_COPY(QWriteLocker)
- union{
- QReadWriteLock *q_lock;
- quintptr q_val;
- };
+ quintptr q_val;
};
inline QWriteLocker::QWriteLocker(QReadWriteLock *areadWriteLock)
- : q_lock(areadWriteLock)
+ : q_val(reinterpret_cast<quintptr>(areadWriteLock))
{
Q_ASSERT_X((q_val & quintptr(1u)) == quintptr(0),
"QWriteLocker", "QReadWriteLock pointer is misaligned");