diff options
-rw-r--r-- | raul/AtomicInt.hpp | 5 | ||||
-rw-r--r-- | raul/AtomicPtr.hpp | 5 | ||||
-rw-r--r-- | test/atomic_test.cpp | 6 |
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); |