Foundation
Loading...
Searching...
No Matches
Classes | Public Member Functions | Private Attributes | List of all members
Foundation::Atomics::Stack< T > Class Template Reference

Atomic, unbounded LIFO stack with lock-free push and pop operations. More...

#include <Stack.hpp>

Classes

struct  Node
 
struct  PTag
 

Public Member Functions

 Stack (Allocator *alloc)
 Construct the Stack.
 
template<typename U >
void Push (U &&value)
 Push a value onto the stack.
 
bool Pop (T &out)
 Pop a value from the stack.
 

Private Attributes

Atomic< PTagmTop {}
 
AllocatormAlloc
 

Detailed Description

template<typename T>
class Foundation::Atomics::Stack< T >

Atomic, unbounded LIFO stack with lock-free push and pop operations.

Note
Memory allocations are performed on each push and deallocations on each pop. This also requires a thread-safe Allocator, which Core provides.
Consider MPMCQueue for a bounded, allocation-free alternative.
Template Parameters
TData type.

Constructor & Destructor Documentation

◆ Stack()

template<typename T >
Foundation::Atomics::Stack< T >::Stack ( Allocator alloc)
inline

Construct the Stack.

Parameters
allocAllocator to use for element allocations.

Member Function Documentation

◆ Pop()

template<typename T >
bool Foundation::Atomics::Stack< T >::Pop ( T out)
inline

Pop a value from the stack.

Parameters
outReference to receive the popped value. This is only valid if the function returns true.
Note
Multiple threads may call this concurrently.
Returns
True if a value was popped, false if the stack was empty.

◆ Push()

template<typename T >
template<typename U >
void Foundation::Atomics::Stack< T >::Push ( U &&  value)
inline

Push a value onto the stack.

Note
Multiple threads may call this concurrently.
Template Parameters
UType of the value to push. May be different from T, but must be convertible to T.
Parameters
valueThe value to push. This is forwarded to T's constructor.

Member Data Documentation

◆ mAlloc

template<typename T >
Allocator* Foundation::Atomics::Stack< T >::mAlloc
private

◆ mTop

template<typename T >
Atomic<PTag> Foundation::Atomics::Stack< T >::mTop {}
private

The documentation for this class was generated from the following file: