template<typename T>
class pongasoft::Utils::Concurrent::LockFree::SingleElementStorage< T >
This (internal) class stores a single element.
This implementation is NOT fully thread safe. It is only thread safe as long as load is called by a single thread and store is called by another single thread as well (if load and store are called by the same thread it is obviously thread safe since it would be mono thread...)
- Todo
- the implementation somehow assumes that T is a real type, not a primitive.. maybe there is a way to write a primitive version (if that becomes a necessity)
template<typename T>
| std::unique_ptr< Element > load |
( |
std::unique_ptr< Element > | iElement | ) |
|
|
inlineprotected |
Loads an element from storage.
In order to avoid copy and memory allocation, the api actually takes an element to replace the one that is returned. The correct usage pattern should be:
if(!isEmpty()) myPtr = std::move(load(std::move(myPtr)));
That way you are guaranteed that what load returns will have a fNew flag set to true...
- Returns
- element with flag fNew set to true if there was a new element, false otherwise