A simple thread-safe data container that can support multiple writers and readers.
More...
|
| LockedContainer () |
| Create the container and the data it contains. More...
|
|
| LockedContainer (const T &initialValue) |
| Create the container and the data it contains. More...
|
|
| LockedContainer (T &&initialValue) |
| Create the container and the data it contains. More...
|
|
| ~LockedContainer () |
| Destroy the container and the data it contains.
|
|
void | set (const T &value) |
| Write (copy) new data into the container. More...
|
|
void | set (T &&value) |
| Write (move) new data into the container. More...
|
|
void | get (T *value) const |
| Read (copy) the data from the container. More...
|
|
void | take (T *value) |
| Move the data out of the container. More...
|
|
bool | tryGetChanged (T *value) const |
| Read (copy) the data from the container if it has been modified since the last access. More...
|
|
bool | tryTakeChanged (T *value) |
| Move the data out of the container if it has been modified since the last access. More...
|
|
template<typename T>
class SurgSim::Framework::LockedContainer< T >
A simple thread-safe data container that can support multiple writers and readers.
The type of the contained data is determined by the template argument, and should satisfy the following:
- It must be either default-constructable or copy-constructable or move-constructable. In other words, construction must be possible using either
T()
or T(const T&)
or T(T&&)
, or compiler-generated equivalents.
- It must be either copy-assignable or move-assignable. In other words, assignment must be possible using either
operator=(const T&)
or operator=(T&&)
, or compiler-generated equivalents. (If it is only move-assignable, then you can't get the value in the container without erasing it.)
Note that STL container types, plain-old-data structs, and most other things you might want to use satisfy those requirements.
The container will create and manage an extra internal instance of the data object.
The interface has been designed to be incredibly simple. The trade-off is that the overhead of reading or writing to the container is significant (Each write incurs either a copy or a move of the data, plus a mutex lock/unlock. Each read incurs a copy, plus a mutex lock/unlock. Applications that write and read heavily may also become mutex-bound.)
Writers write the data by calling the set method, which copies or moves the data into internal storage. Readers read the data by calling the get method, which copies the data from internal storage.
- Template Parameters
-