Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
SharedObject.h@0:6c75b6083087, 2013-07-19 (annotated)
- Committer:
- MatteoT
- Date:
- Fri Jul 19 03:28:14 2013 +0000
- Revision:
- 0:6c75b6083087
- Child:
- 1:fe38610c777b
Experiment
Who changed what in which revision?
| User | Revision | Line number | New 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 | 0:6c75b6083087 | 34 | inline void get (T& value_destination) const; |
| MatteoT | 0:6c75b6083087 | 35 | |
| MatteoT | 0:6c75b6083087 | 36 | /** Sets the value of the shared resource with the specified new_value. |
| MatteoT | 0:6c75b6083087 | 37 | */ |
| MatteoT | 0:6c75b6083087 | 38 | inline void set (const T& new_value); |
| MatteoT | 0:6c75b6083087 | 39 | }; |
| MatteoT | 0:6c75b6083087 | 40 | |
| MatteoT | 0:6c75b6083087 | 41 | |
| MatteoT | 0:6c75b6083087 | 42 | #endif |