Jamba
3.0.2
|
#include <Concurrent.h>
Inherited by pongasoft::Utils::Concurrent::LockFree::AtomicValue< T >, and pongasoft::Utils::Concurrent::LockFree::SingleElementQueue< T >.
Classes | |
struct | Element |
Public Member Functions | |
bool | __isLockFree () const |
bool | isEmpty () const |
SingleElementStorage (std::unique_ptr< T > iElement, bool iIsEmpty) noexcept | |
~SingleElementStorage () | |
Protected Member Functions | |
std::unique_ptr< Element > | __newElement () const |
std::unique_ptr< T > | __newT () const |
std::unique_ptr< Element > | load (std::unique_ptr< Element > iElement) |
std::unique_ptr< Element > | store (std::unique_ptr< Element > iElement) |
Private Attributes | |
std::atomic< Element * > | fSingleElement |
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...)
T
is a real type, not a primitive.. maybe there is a way to write a primitive version (if that becomes a necessity)
|
inlinenoexcept |
|
inline |
|
inline |
Used (from test) to make sure that it is a lock free implementation. Relies on an atomic pointer and in general the implementation should be lock free but we make sure here.
|
inlineprotected |
|
inlineprotected |
|
inline |
|
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...
|
inlineprotected |
Stores an element in the storage. Replaces the current one if there is one. In order to avoid copy and memory allocation, the storage assumes ownership of the element provided and as result returns the one it replaces.
|
private |