Not exactly an Atomic implementation - If you use shared resources, this helps you protecting the access with a Mutex.
Work in progress...
Diff: SharedObject.cpp
- Revision:
- 3:1069ef627cff
- Parent:
- 2:16cab88c1203
diff -r 16cab88c1203 -r 1069ef627cff SharedObject.cpp --- a/SharedObject.cpp Fri Jul 19 05:34:48 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,43 +0,0 @@ -#include "SharedObject.h" - -template<class T> -SharedObject<T>::SharedObject (const T& value) -{ - _readwrite_mutex.lock(); - _value = value; - _readwrite_mutex.unlock(); -} - -template<class T> -SharedObject<T>::SharedObject () -{ - _readwrite_mutex.unlock(); -} - -template<class T> -void SharedObject<T>::get (T& value_destination) const -{ - _readwrite_mutex.lock(); - value_destination = _value; - _readwrite_mutex.unlock(); -} -template<class T> -SharedObject<T>::operator T () const -{ - T tmp_value; - get(tmp_value); - return tmp_value; -} - -template<class T> -void SharedObject<T>::set (const T& new_value) -{ - _readwrite_mutex.lock(); - _value = new_value; - _readwrite_mutex.unlock(); -} -template<class T> -void SharedObject<T>::operator= (const T& new_value) -{ - set(new_value); -} \ No newline at end of file