From f8aa3ee7621758b35ba52a5b17972fa4144710ae Mon Sep 17 00:00:00 2001 From: David Robillard Date: Fri, 11 Jan 2013 03:35:17 +0000 Subject: Use C++11 atomics. git-svn-id: http://svn.drobilla.net/lad/trunk/raul@4916 a436a847-0d15-0410-975c-d299462d15a1 --- test/atomic_test.cpp | 76 ---------------------------------------------------- test/queue_test.cpp | 8 +++--- test/thread_test.cpp | 4 +-- 3 files changed, 6 insertions(+), 82 deletions(-) delete mode 100644 test/atomic_test.cpp (limited to 'test') 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 - - 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 . -*/ - -#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 p; - TEST(p.get() == NULL); - - AtomicPtr 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 #include +#include #include #include #include -#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 read_count; + std::atomic 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 . */ +#include #include -#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 var(0); -Raul::AtomicInt n_errors(0); +std::atomic n_errors(0); class Waiter : public Raul::Thread { public: -- cgit v1.2.1