Matteo Terruzzi / SharedObject
Committer:
MatteoT
Date:
Fri Jul 19 05:34:48 2013 +0000
Revision:
2:16cab88c1203
Parent:
1:fe38610c777b
Child:
3:1069ef627cff
refactor

Who changed what in which revision?

UserRevisionLine numberNew contents of line
MatteoT 0:6c75b6083087 1 #ifndef _SHAREDOBJECT_H_
MatteoT 0:6c75b6083087 2 #define _SHAREDOBJECT_H_
MatteoT 0:6c75b6083087 3
MatteoT 0:6c75b6083087 4 #include "mbed.h"
MatteoT 0:6c75b6083087 5 #include "rtos.h"
MatteoT 0:6c75b6083087 6
MatteoT 0:6c75b6083087 7 /** Template class used to protect a shared resource with a Mutex.
MatteoT 0:6c75b6083087 8 */
MatteoT 0:6c75b6083087 9 template <class T>
MatteoT 0:6c75b6083087 10 class SharedObject
MatteoT 0:6c75b6083087 11 {
MatteoT 0:6c75b6083087 12
MatteoT 0:6c75b6083087 13 /** get/set controll mutex
MatteoT 0:6c75b6083087 14 */
MatteoT 0:6c75b6083087 15 Mutex _readwrite_mutex;
MatteoT 0:6c75b6083087 16
MatteoT 0:6c75b6083087 17 /** value of the object
MatteoT 0:6c75b6083087 18 */
MatteoT 0:6c75b6083087 19 T _value;
MatteoT 0:6c75b6083087 20
MatteoT 0:6c75b6083087 21 public:
MatteoT 0:6c75b6083087 22
MatteoT 0:6c75b6083087 23 /** Resource constructor.
MatteoT 0:6c75b6083087 24 * @param value sets the initial value of the resource.
MatteoT 0:6c75b6083087 25 */
MatteoT 0:6c75b6083087 26 SharedObject (const T& value);
MatteoT 0:6c75b6083087 27
MatteoT 0:6c75b6083087 28 /** Resource constructor without initial value.
MatteoT 0:6c75b6083087 29 */
MatteoT 0:6c75b6083087 30 SharedObject ();
MatteoT 0:6c75b6083087 31
MatteoT 0:6c75b6083087 32 /** Sets the specified value_destination with the value of the shared resource.
MatteoT 0:6c75b6083087 33 */
MatteoT 1:fe38610c777b 34 void get (T& value_destination) const;
MatteoT 2:16cab88c1203 35 ///Returns the value of the shared resource (may be slower than get).
MatteoT 2:16cab88c1203 36 operator T () const;
MatteoT 0:6c75b6083087 37
MatteoT 0:6c75b6083087 38 /** Sets the value of the shared resource with the specified new_value.
MatteoT 0:6c75b6083087 39 */
MatteoT 1:fe38610c777b 40 void set (const T& new_value);
MatteoT 2:16cab88c1203 41 ///Alias of set.
MatteoT 2:16cab88c1203 42 void operator= (const T& new_value);
MatteoT 0:6c75b6083087 43 };
MatteoT 0:6c75b6083087 44
MatteoT 0:6c75b6083087 45
MatteoT 0:6c75b6083087 46 #endif