diff options
author | João Abecasis <joao@abecasis.name> | 2009-08-31 15:05:51 (GMT) |
---|---|---|
committer | João Abecasis <joao@abecasis.name> | 2009-08-31 16:15:45 (GMT) |
commit | e70980b2aacbc758a0cd1e2246633278f7c505ab (patch) | |
tree | ee19500748f62181afbf424438c6ff03d12d7912 /tests | |
parent | 06a4cdba05e4865d02a09a5633c31c462ac00014 (diff) | |
download | Qt-e70980b2aacbc758a0cd1e2246633278f7c505ab.zip Qt-e70980b2aacbc758a0cd1e2246633278f7c505ab.tar.gz Qt-e70980b2aacbc758a0cd1e2246633278f7c505ab.tar.bz2 |
Refactoring qatomic_windows.h
Consolidated Interlocked* declarations and API implementation through
macro hackery, (hopefully) for improved readability and maintainability.
Fixes anti-aliasing warnings with MinGW in qatomic_windows.h. Gcc
builds now use inline assembly for atomic operations, instead of relying
on Interlocked* functions which aren't consistently declared across
implementations (mingw32, mingw-w64, wine... others?).
Drops support for VC 6 and MetroWerks.
Reviewed-by: Thiago Macieira
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qatomicint/tst_qatomicint.cpp | 44 | ||||
-rw-r--r-- | tests/auto/qatomicpointer/tst_qatomicpointer.cpp | 48 |
2 files changed, 92 insertions, 0 deletions
diff --git a/tests/auto/qatomicint/tst_qatomicint.cpp b/tests/auto/qatomicint/tst_qatomicint.cpp index c3ea31d..5fde633 100644 --- a/tests/auto/qatomicint/tst_qatomicint.cpp +++ b/tests/auto/qatomicint/tst_qatomicint.cpp @@ -59,6 +59,8 @@ public: ~tst_QAtomicInt(); private slots: + void warningFree(); + // QAtomicInt members void constructor_data(); void constructor(); @@ -101,6 +103,9 @@ private slots: void testAndSet_loop(); void fetchAndAdd_loop(); void fetchAndAdd_threadedLoop(); + +private: + static void warningFreeHelper(); }; tst_QAtomicInt::tst_QAtomicInt() @@ -109,6 +114,45 @@ tst_QAtomicInt::tst_QAtomicInt() tst_QAtomicInt::~tst_QAtomicInt() { } +void tst_QAtomicInt::warningFreeHelper() +{ + Q_ASSERT(false); + // The code below is bogus, and shouldn't be run. We're looking for warnings, only. + + QBasicAtomicInt i = Q_BASIC_ATOMIC_INITIALIZER(0); + + int expectedValue = 0; + int newValue = 0; + int valueToAdd = 0; + + i.ref(); + i.deref(); + + i.testAndSetRelaxed(expectedValue, newValue); + i.testAndSetAcquire(expectedValue, newValue); + i.testAndSetRelease(expectedValue, newValue); + i.testAndSetOrdered(expectedValue, newValue); + + i.fetchAndStoreRelaxed(newValue); + i.fetchAndStoreAcquire(newValue); + i.fetchAndStoreRelease(newValue); + i.fetchAndStoreOrdered(newValue); + + i.fetchAndAddRelaxed(valueToAdd); + i.fetchAndAddAcquire(valueToAdd); + i.fetchAndAddRelease(valueToAdd); + i.fetchAndAddOrdered(valueToAdd); +} + +void tst_QAtomicInt::warningFree() +{ + // This is a compile time check for warnings. + // No need for actual work here. + + void (*foo)() = &warningFreeHelper; + (void)foo; +} + void tst_QAtomicInt::constructor_data() { QTest::addColumn<int>("value"); diff --git a/tests/auto/qatomicpointer/tst_qatomicpointer.cpp b/tests/auto/qatomicpointer/tst_qatomicpointer.cpp index b9636a0..c1e0efd 100644 --- a/tests/auto/qatomicpointer/tst_qatomicpointer.cpp +++ b/tests/auto/qatomicpointer/tst_qatomicpointer.cpp @@ -58,6 +58,8 @@ public: ~tst_QAtomicPointer(); private slots: + void warningFree(); + void constructor(); void copy_constructor(); void equality_operator(); @@ -78,6 +80,9 @@ private slots: void isFetchAndAddWaitFree(); void fetchAndAdd_data(); void fetchAndAdd(); + +private: + static void warningFreeHelper(); }; tst_QAtomicPointer::tst_QAtomicPointer() @@ -86,6 +91,49 @@ tst_QAtomicPointer::tst_QAtomicPointer() tst_QAtomicPointer::~tst_QAtomicPointer() { } +struct WFHC +{ + void bar() {} +}; + +void tst_QAtomicPointer::warningFreeHelper() +{ + Q_ASSERT(false); + // The code below is bogus, and shouldn't be run. We're looking for warnings, only. + + QBasicAtomicPointer<WFHC> p = Q_BASIC_ATOMIC_INITIALIZER(0); + + p->bar(); + + WFHC *expectedValue = 0; + WFHC *newValue = 0; + qptrdiff valueToAdd = 0; + + p.testAndSetRelaxed(expectedValue, newValue); + p.testAndSetAcquire(expectedValue, newValue); + p.testAndSetRelease(expectedValue, newValue); + p.testAndSetOrdered(expectedValue, newValue); + + p.fetchAndStoreRelaxed(newValue); + p.fetchAndStoreAcquire(newValue); + p.fetchAndStoreRelease(newValue); + p.fetchAndStoreOrdered(newValue); + + p.fetchAndAddRelaxed(valueToAdd); + p.fetchAndAddAcquire(valueToAdd); + p.fetchAndAddRelease(valueToAdd); + p.fetchAndAddOrdered(valueToAdd); +} + +void tst_QAtomicPointer::warningFree() +{ + // This is a compile time check for warnings. + // No need for actual work here. + + void (*foo)() = &warningFreeHelper; + (void)foo; +} + void tst_QAtomicPointer::constructor() { void *one = this; |