diff options
author | David Robillard <d@drobilla.net> | 2013-01-11 03:35:17 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2013-01-11 03:35:17 +0000 |
commit | f8aa3ee7621758b35ba52a5b17972fa4144710ae (patch) | |
tree | 2bf934c558b5c97f858be03101fa1544ecf6835d /test | |
parent | 77d36f84343baa0864e742834be15c0296dc4389 (diff) | |
download | raul-f8aa3ee7621758b35ba52a5b17972fa4144710ae.tar.gz raul-f8aa3ee7621758b35ba52a5b17972fa4144710ae.tar.bz2 raul-f8aa3ee7621758b35ba52a5b17972fa4144710ae.zip |
Use C++11 atomics.
git-svn-id: http://svn.drobilla.net/lad/trunk/raul@4916 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'test')
-rw-r--r-- | test/atomic_test.cpp | 76 | ||||
-rw-r--r-- | test/queue_test.cpp | 8 | ||||
-rw-r--r-- | test/thread_test.cpp | 4 |
3 files changed, 6 insertions, 82 deletions
diff --git a/test/atomic_test.cpp b/test/atomic_test.cpp deleted file mode 100644 index 5b6260c..0000000 --- a/test/atomic_test.cpp +++ /dev/null @@ -1,76 +0,0 @@ -/* - This file is part of Raul. - Copyright 2007-2012 David Robillard <http://drobilla.net> - - Raul is free software: you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation, either version 3 of the License, or any later version. - - Raul is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Raul. If not, see <http://www.gnu.org/licenses/>. -*/ - -#include "raul/AtomicInt.hpp" -#include "raul/AtomicPtr.hpp" - -using namespace std; -using namespace Raul; - -#define TEST(cond) { if (!(cond)) return 1; } - -int -main() -{ - /* TODO: Actually test functionality... */ - AtomicInt i(0); - TEST(i == 0); - - AtomicInt j(i); - TEST(i == j); - - ++i; - TEST(i == 1); - - --i; - TEST(i == 0); - - TEST(i + 1 == 1); - TEST(i - 1 == -1); - - i += 2; - TEST(i == 2); - - i -= 4; - TEST(i == -2); - - TEST(i.compare_and_exchange(-2, 0)); - TEST(i == 0); - - TEST(i.exchange_and_add(5) == 0); - TEST(i == 5); - - i = 1; - TEST(i == 1); - TEST(i.decrement_and_test()); - - int five = 5; - int seven = 7; - AtomicPtr<int> p; - TEST(p.get() == NULL); - - AtomicPtr<int> q(p); - TEST(p == q); - - p = &five; - TEST(p.get() == &five); - TEST(*p.get() == 5); - TEST(p.compare_and_exchange(&five, &seven)); - TEST(p.get() == &seven); - TEST(*p.get() = 7); - - return 0; -} diff --git a/test/queue_test.cpp b/test/queue_test.cpp index bcdf039..b13c13f 100644 --- a/test/queue_test.cpp +++ b/test/queue_test.cpp @@ -19,11 +19,11 @@ #include <stdlib.h> #include <algorithm> +#include <atomic> #include <iostream> #include <string> #include <vector> -#include "raul/AtomicInt.hpp" #include "raul/SRMWQueue.hpp" #include "raul/SRSWQueue.hpp" #include "raul/Thread.hpp" @@ -41,8 +41,8 @@ static const unsigned PUSHES_PER_ITERATION = 3; struct Record { Record() : read_count(0), write_count(0) {} - AtomicInt read_count; - AtomicInt write_count; + std::atomic<int> read_count; + std::atomic<int> write_count; }; Record data[NUM_DATA]; @@ -90,7 +90,7 @@ data_is_sane() { unsigned ret = 0; for (unsigned i = 0; i < NUM_DATA; ++i) { - unsigned diff = abs(data[i].read_count.get() - data[i].write_count.get()); + unsigned diff = abs(data[i].read_count.load() - data[i].write_count.load()); ret += diff; } diff --git a/test/thread_test.cpp b/test/thread_test.cpp index f823936..f59894f 100644 --- a/test/thread_test.cpp +++ b/test/thread_test.cpp @@ -14,9 +14,9 @@ along with Raul. If not, see <http://www.gnu.org/licenses/>. */ +#include <atomic> #include <iostream> -#include "raul/AtomicInt.hpp" #include "raul/Semaphore.hpp" #include "raul/Thread.hpp" #include "raul/ThreadVar.hpp" @@ -25,7 +25,7 @@ using namespace std; using namespace Raul; Raul::ThreadVar<int> var(0); -Raul::AtomicInt n_errors(0); +std::atomic<int> n_errors(0); class Waiter : public Raul::Thread { public: |