This class implements a lock-free stack.
More...
#include "nn/nlib/LockFree.h"
template<class T>
class nn::nlib::LockFreeStack< T >
This class implements a lock-free stack.
- Template Parameters
-
T | The type of elements to be placed in a stack. This type must be POD . |
- Description
- The
Push()
and Pop()
member functions are thread-safe. If you specify a pointer type for T
, executing DestructorForLockFree
automatically deletes objects of the T
type placed in the stack.
- Sample code
LockFreeStack<MyClass*> stack;
e = stack.Init(1024);
}
.....
MyClass* elem = new MyClass();
.....
e = stack.Push(elem);
}
.....
e = stack.Pop(x);
}
.....
Definition at line 463 of file LockFree.h.
◆ PopType
◆ ~LockFreeStack()
Destructor.
- Description
- Uses
DestructorForLockFree
to delete each of remaining elements, if any. If necessary, specialize a function template to perform necessary processing..
Definition at line 467 of file LockFree.h.
◆ Init()
Initializes the stack. This is not thread-safe.
- Parameters
-
[in] | count | The number of elements that can be placed in the stack. |
- Return values
-
0 | Success. |
ENOMEM | Memory allocation has failed. |
EALREADY | Already initialized. |
Definition at line 471 of file LockFree.h.
◆ Pop()
Picks up an element from the stack and stores it in x. This is thread-safe.
- Parameters
-
[in] | x | The region that stores elements picked up from the stack. |
- Return values
-
0 | Success. |
EAGAIN | The stack is empty. |
Definition at line 478 of file LockFree.h.
◆ PopUnsafe()
Picks up an element from the stack and stores it in x. This is not thread-safe.
- Parameters
-
[in] | x | The region that stores elements picked up from the stack. |
- Return values
-
0 | Success. |
EAGAIN | The stack is empty. |
Definition at line 482 of file LockFree.h.
◆ Push()
Places the element x in the stack. This is thread-safe.
- Parameters
-
[in] | x | The element to be placed in the stack. |
- Return values
-
0 | Success. |
EAGAIN | The stack is full. |
Definition at line 477 of file LockFree.h.
◆ PushUnsafe()
Places the element x in the stack. This is not thread-safe.
- Parameters
-
[in] | x | The element to be placed in the stack. |
- Return values
-
0 | Success. |
EAGAIN | The stack is full. |
Definition at line 480 of file LockFree.h.
The documentation for this class was generated from the following files: