7 #ifndef _LOCK_FREE_STACK_CLASS_HEADER_
8 #define _LOCK_FREE_STACK_CLASS_HEADER_
12 #ifndef A_UTILS_TAGGED_POINTER_AVALIABLE
22 #ifdef A_UTILS_TAGGED_POINTER_AVALIABLE
40 class A_UTILS_CAS_ALIGNMENT lock_free_stack
47 struct A_UTILS_CAS_ALIGNMENT cNode
49 tagged_ptr<cNode> m_pNext;
54 typedef tagged_ptr<cNode> tTaggedNodePtr;
57 tTaggedNodePtr m_pLast;
60 free_list<cNode, T> m_oFree;
75 lock_free_stack(
tUInt nReserve = 0,
tBool bGrow =
tTrue): m_pLast(nullptr), m_oFree(nReserve, bGrow)
82 virtual ~lock_free_stack()
86 while (
static_cast<tErrorCode>(ERR_NOERROR) == Pop(&oTmp));
98 cNode* pTmp = m_oFree.GetFreeNode();
105 pTmp->m_oData = oValue;
111 pTmp->m_pNext.Set(pOld.GetPtr());
113 while (!m_pLast.CompareAndSwap(pOld, pTmp));
129 tTaggedNodePtr pOldTos;
130 pOldTos.Set(m_pLast);
137 cNode* pNewTos = pOldTos->m_pNext.GetPtr();
139 if (m_pLast.CompareAndSwap(pOldTos, pNewTos))
141 *pValue = pOldTos->m_oData;
142 m_oFree.AddFreeNode(pOldTos.GetPtr());
151 lock_free_stack(
const lock_free_stack& oOther);
171 std::recursive_mutex m_oMutex;
172 std::stack<T> m_oStack;
203 std::lock_guard<std::recursive_mutex> oLck(m_oMutex);
204 m_oStack.push(oValue);
216 std::lock_guard<std::recursive_mutex> oLck(m_oMutex);
217 if (m_oStack.empty())
221 *pValue = m_oStack.top();
unsigned int tUInt
type definition for unsigned integer value (platform and compiler dependent type).
bool tBool
The tBool defines the type for the Values tTrue and tFalse (platform and compiler dependent).
Lock-free stack class that allows multiple writers and readers.
tErrorCode Pop(T *pValue)
Pops an element from the stack.
virtual ~lock_free_stack()
Destructor.
lock_free_stack(tUInt nReserve=0, tBool bGrow=tTrue)
Constructor.
tErrorCode Push(const T &oValue)
Pushes an element onto the stack.
#define tTrue
Value for tBool.
ADTF A_UTIL Namespace - Within adtf this is used as adtf::util or adtf_util.
C++11 POD type to distribute error codes between binary boundaries.
Copyright © Audi Electronics Venture GmbH.