nlib
nn::nlib::LockFreePriorityQueue< T > Class Template Reference

Wraps nlib_mq with a class implementing a lock-free queue with a priority set. More...

#include "nn/nlib/LockFree.h"

Public Types

typedef UniquePtr< T, DestructorForLockFree< T > > DequeueType
 The type for the argument of Dequeue(). More...
 

Public Member Functions

 LockFreePriorityQueue () noexcept
 Instantiates the object with default parameters (default constructor).
 
 ~LockFreePriorityQueue () noexcept
 Destructor. More...
 
errno_t Init (size_t max_size) noexcept
 Initializes the queue. This is not thread-safe. More...
 
errno_t Close () noexcept
 Closes the queue and restores it to the state before its initialization. This is not thread-safe. More...
 
errno_t Enqueue (T *obj, int prio) noexcept
 Adds an element to the queue. This is thread-safe. More...
 
errno_t Dequeue (DequeueType &obj, int *prio) noexcept
 Picks up an element from the queue. This is thread-safe. More...
 
void SwapUnsafe (LockFreePriorityQueue &rhs) noexcept
 Swaps an object. This is not thread-safe.
 

Detailed Description

template<class T>
class nn::nlib::LockFreePriorityQueue< T >

Wraps nlib_mq with a class implementing a lock-free queue with a priority set.

Template Parameters
TThe queue element type.
Description
If necessary, DestructorForLockFree<T> must be specialized to write code for destructing elements of the type T. If Enqueue() is executed while Dequeue() is being executed, Dequeue() may not return the element with the highest priority.

Definition at line 650 of file LockFree.h.

Member Typedef Documentation

◆ DequeueType

template<class T >
nn::nlib::LockFreePriorityQueue< T >::DequeueType

The type for the argument of Dequeue().

Description
The typedef defines UniquePtr so that executing DestructorForLockFree automatically destructs the relevant objects.

Definition at line 652 of file LockFree.h.

Constructor & Destructor Documentation

◆ ~LockFreePriorityQueue()

template<class T >
nn::nlib::LockFreePriorityQueue< T >::~LockFreePriorityQueue ( )
inlinenoexcept

Destructor.

Description
Any elements remaining in the queue are destructed by DestructorForLockFree<T>.

Definition at line 656 of file LockFree.h.

Member Function Documentation

◆ Close()

template<class T >
nn::nlib::LockFreePriorityQueue< T >::Close ( )
inlinenoexcept

Closes the queue and restores it to the state before its initialization. This is not thread-safe.

Returns
Returns 0 on success.
Description
Any elements remaining in the queue are destructed by DestructorForLockFree<T>.

Definition at line 671 of file LockFree.h.

◆ Dequeue()

template<class T >
nn::nlib::LockFreePriorityQueue< T >::Dequeue ( DequeueType obj,
int *  prio 
)
inlinenoexcept

Picks up an element from the queue. This is thread-safe.

Parameters
[out]objAn object picked up from the queue.
[out]prioThe priority of obj.
Returns
The value returned by nlib_mq_receive().

Definition at line 681 of file LockFree.h.

◆ Enqueue()

template<class T >
nn::nlib::LockFreePriorityQueue< T >::Enqueue ( T *  obj,
int  prio 
)
inlinenoexcept

Adds an element to the queue. This is thread-safe.

Parameters
[in]objA pointer to the element.
[in]prioThe priority in the range of 0 to 31 inclusive.
Returns
The value returned by nlib_mq_send().

Definition at line 677 of file LockFree.h.

◆ Init()

template<class T >
nn::nlib::LockFreePriorityQueue< T >::Init ( size_t  max_size)
inlinenoexcept

Initializes the queue. This is not thread-safe.

Parameters
[in]max_sizeThe maximum number of elements that can be stored in the queue.
Return values
0Success.
EINVALmax_size exceeds INT32_MAX.
EALREADYAlready initialized.
Othererrors returned by nlib_mq_open().

Definition at line 660 of file LockFree.h.


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