Not exactly an Atomic implementation - If you use shared resources, this helps you protecting the access with a Mutex.

Work in progress...

Files at this revision

API Documentation at this revision

Comitter:
MatteoT
Date:
Fri Jul 19 05:34:48 2013 +0000
Parent:
1:fe38610c777b
Child:
3:1069ef627cff
Commit message:
refactor

Changed in this revision

SharedObject.cpp Show annotated file Show diff for this revision Revisions of this file
SharedObject.h Show annotated file Show diff for this revision Revisions of this file
--- a/SharedObject.cpp	Fri Jul 19 04:47:19 2013 +0000
+++ b/SharedObject.cpp	Fri Jul 19 05:34:48 2013 +0000
@@ -21,6 +21,13 @@
     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)
@@ -28,4 +35,9 @@
     _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
--- a/SharedObject.h	Fri Jul 19 04:47:19 2013 +0000
+++ b/SharedObject.h	Fri Jul 19 05:34:48 2013 +0000
@@ -32,10 +32,14 @@
     /** Sets the specified value_destination with the value of the shared resource.
      */
     void get (T& value_destination) const;
+    ///Returns the value of the shared resource (may be slower than get).
+    operator T () const;
 
     /** Sets the value of the shared resource with the specified new_value.
      */
     void set (const T& new_value);
+    ///Alias of set.
+    void operator= (const T& new_value);
 };