Matteo Terruzzi / SharedObject
Revision:
0:6c75b6083087
Child:
1:fe38610c777b
diff -r 000000000000 -r 6c75b6083087 SharedObject.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SharedObject.h	Fri Jul 19 03:28:14 2013 +0000
@@ -0,0 +1,42 @@
+#ifndef _SHAREDOBJECT_H_
+#define _SHAREDOBJECT_H_
+
+#include "mbed.h"
+#include "rtos.h"
+
+/** Template class used to protect a shared resource with a Mutex.
+ */
+template <class T>
+class SharedObject
+{
+
+    /** get/set controll mutex
+     */
+    Mutex _readwrite_mutex;
+
+    /** value of the object
+     */
+    T _value;
+
+public:
+
+    /** Resource constructor.
+     *  @param value sets the initial value of the resource.
+     */
+    SharedObject (const T& value);
+
+    /** Resource constructor without initial value.
+     */
+    SharedObject ();
+
+    /** Sets the specified value_destination with the value of the shared resource.
+     */
+    inline void get (T& value_destination) const;
+
+    /** Sets the value of the shared resource with the specified new_value.
+     */
+    inline void set (const T& new_value);
+};
+
+
+#endif
\ No newline at end of file