diff options
author | Bradley T. Hughes <bradley.hughes@nokia.com> | 2011-09-29 11:52:33 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-12-02 13:21:32 +0100 |
commit | 409b3b42a233ca58c075a75f35be5ba9b351c7de (patch) | |
tree | e88cdf48672600a4400e1566ea4405ffc38470b0 /tests/auto/corelib/thread/qatomicpointer | |
parent | 3a72240d86dc85f1f2e7d47752953d83c43369c5 (diff) |
Remove cast and assignment operators from QAtomicInt and QAtomicPointer
This is a source incompatible change. There is concern that the
convenience of the implicit cast and assignment operators can lead to
misuse. Several commits have already been done that remove excess use
of the implicit cast, which is a *volatile* read every time it's used.
Users of the QAtomic* API should have to think about when they are
loading the value, and if they do or don't need the acquire memory
barrier on load. The code that people would write using this API is
meant to be multi-threaded, concurrent, and correct. The API should not
allow them to inadvertently, possibly unknowingly, shoot themselves
in the foot.
SC-break-rubber-stamped-by: Lars Knoll
Change-Id: I88fbc26d9db7b5ec80a58ad6271ffa13bbfd191f
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests/auto/corelib/thread/qatomicpointer')
-rw-r--r-- | tests/auto/corelib/thread/qatomicpointer/tst_qatomicpointer.cpp | 82 |
1 files changed, 6 insertions, 76 deletions
diff --git a/tests/auto/corelib/thread/qatomicpointer/tst_qatomicpointer.cpp b/tests/auto/corelib/thread/qatomicpointer/tst_qatomicpointer.cpp index 73266205af..6be25f3dd3 100644 --- a/tests/auto/corelib/thread/qatomicpointer/tst_qatomicpointer.cpp +++ b/tests/auto/corelib/thread/qatomicpointer/tst_qatomicpointer.cpp @@ -55,11 +55,7 @@ private slots: void constructor(); void copy_constructor(); - void equality_operator(); - void inequality_operator(); void assignment_operator(); - void star_operator(); - void dereference_operator(); void isTestAndSetNative(); void isTestAndSetWaitFree(); @@ -157,52 +153,6 @@ void tst_QAtomicPointer::copy_constructor() QCOMPARE(atomic3_copy.load(), atomic3.load()); } -void tst_QAtomicPointer::equality_operator() -{ - void *one = this; - void *two = &one; - void *three = &two; - - QAtomicPointer<void> atomic1 = one; - QAtomicPointer<void> atomic2 = two; - QAtomicPointer<void> atomic3 = three; - - QVERIFY(atomic1 == one); - QVERIFY(!(atomic1 == two)); - QVERIFY(!(atomic1 == three)); - - QVERIFY(!(atomic2 == one)); - QVERIFY(atomic2 == two); - QVERIFY(!(atomic2 == three)); - - QVERIFY(!(atomic3 == one)); - QVERIFY(!(atomic3 == two)); - QVERIFY(atomic3 == three); -} - -void tst_QAtomicPointer::inequality_operator() -{ - void *one = this; - void *two = &one; - void *three = &two; - - QAtomicPointer<void> atomic1 = one; - QAtomicPointer<void> atomic2 = two; - QAtomicPointer<void> atomic3 = three; - - QVERIFY(!(atomic1 != one)); - QVERIFY(atomic1 != two); - QVERIFY(atomic1 != three); - - QVERIFY(atomic2 != one); - QVERIFY(!(atomic2 != two)); - QVERIFY(atomic2 != three); - - QVERIFY(atomic3 != one); - QVERIFY(atomic3 != two); - QVERIFY(!(atomic3 != three)); -} - void tst_QAtomicPointer::assignment_operator() { void *one = this; @@ -213,37 +163,17 @@ void tst_QAtomicPointer::assignment_operator() QAtomicPointer<void> atomic2 = two; QAtomicPointer<void> atomic3 = three; - QVERIFY(atomic1 == one); - QVERIFY(atomic2 == two); - QVERIFY(atomic3 == three); + QVERIFY(atomic1.load() == one); + QVERIFY(atomic2.load() == two); + QVERIFY(atomic3.load() == three); atomic1 = two; atomic2 = three; atomic3 = one; - QVERIFY(atomic1 == two); - QVERIFY(atomic2 == three); - QVERIFY(atomic3 == one); -} - -struct Type -{ - inline const Type *self() const - { return this; } -}; - -void tst_QAtomicPointer::star_operator() -{ - Type t; - QAtomicPointer<Type> p = &t; - QCOMPARE((*p).self(), t.self()); -} - -void tst_QAtomicPointer::dereference_operator() -{ - Type t; - QAtomicPointer<Type> p = &t; - QCOMPARE(p->self(), t.self()); + QVERIFY(atomic1.load() == two); + QVERIFY(atomic2.load() == three); + QVERIFY(atomic3.load() == one); } void tst_QAtomicPointer::isTestAndSetNative() |