Matteo Terruzzi / SharedObject

SharedObject.h

Committer:
MatteoT
Date:
2013-07-19
Revision:
0:6c75b6083087
Child:
1:fe38610c777b

File content as of revision 0:6c75b6083087:

#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