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() and DequeueUnsafe(). 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...
 

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 622 of file LockFree.h.

Member Typedef Documentation

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

The type for the argument of Dequeue() and DequeueUnsafe().

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

Definition at line 624 of file LockFree.h.

Constructor & Destructor Documentation

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 628 of file LockFree.h.

Member Function Documentation

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 643 of file LockFree.h.

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 653 of file LockFree.h.

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 649 of file LockFree.h.

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 632 of file LockFree.h.


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