summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2012-08-14 03:11:17 +0000
committerDavid Robillard <d@drobilla.net>2012-08-14 03:11:17 +0000
commit3f6f6bf7ab75abf92ef2ef44c3327f59e238130a (patch)
treee5045584bdbe866153d409a4d61eb4b356dfee64
parent905cd5e70f449738c953ff84a0c935f9c0e4828e (diff)
downloadraul-3f6f6bf7ab75abf92ef2ef44c3327f59e238130a.tar.gz
raul-3f6f6bf7ab75abf92ef2ef44c3327f59e238130a.tar.bz2
raul-3f6f6bf7ab75abf92ef2ef44c3327f59e238130a.zip
Add atomic comparison operators.
git-svn-id: http://svn.drobilla.net/lad/trunk/raul@4684 a436a847-0d15-0410-975c-d299462d15a1
-rw-r--r--raul/AtomicInt.hpp5
-rw-r--r--raul/AtomicPtr.hpp5
-rw-r--r--test/atomic_test.cpp6
3 files changed, 16 insertions, 0 deletions
diff --git a/raul/AtomicInt.hpp b/raul/AtomicInt.hpp
index 2fd624c..172af6b 100644
--- a/raul/AtomicInt.hpp
+++ b/raul/AtomicInt.hpp
@@ -51,6 +51,11 @@ public:
inline int operator+(int val) const { return get() + val; }
inline int operator-(int val) const { return get() - val; }
+ inline bool operator==(const AtomicInt& other) const {
+ Raul::barrier();
+ return _val == other._val;
+ }
+
inline AtomicInt& operator+=(int val) {
__sync_fetch_and_add(&_val, val);
return *this;
diff --git a/raul/AtomicPtr.hpp b/raul/AtomicPtr.hpp
index 91c5c35..0dc369b 100644
--- a/raul/AtomicPtr.hpp
+++ b/raul/AtomicPtr.hpp
@@ -38,6 +38,11 @@ public:
return static_cast<T*>(_val);
}
+ inline bool operator==(const AtomicPtr& other) const {
+ Raul::barrier();
+ return _val == other._val;
+ }
+
inline void operator=(T* val) {
_val = val;
Raul::barrier();
diff --git a/test/atomic_test.cpp b/test/atomic_test.cpp
index e3a8d73..5b6260c 100644
--- a/test/atomic_test.cpp
+++ b/test/atomic_test.cpp
@@ -29,6 +29,9 @@ main()
AtomicInt i(0);
TEST(i == 0);
+ AtomicInt j(i);
+ TEST(i == j);
+
++i;
TEST(i == 1);
@@ -59,6 +62,9 @@ main()
AtomicPtr<int> p;
TEST(p.get() == NULL);
+ AtomicPtr<int> q(p);
+ TEST(p == q);
+
p = &five;
TEST(p.get() == &five);
TEST(*p.get() == 5);