nlib
|
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 | |
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. | |
Constructor, Destructor, and Initialization | |
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... | |
Wraps nlib_mq
with a class implementing a lock-free queue with a priority set.
T | The queue element type. |
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. kNumThread
threads and received by kNumThread
threads. Note that those tasks are received from the queue in the order of their precedence from highest to lowest. Definition at line 622 of file LockFree.h.
nn::nlib::LockFreePriorityQueue< T >::DequeueType |
The type for the argument of Dequeue()
.
UniquePtr
so that executing DestructorForLockFree
automatically destructs the relevant objects. Definition at line 624 of file LockFree.h.
|
inlinenoexcept |
Destructor.
DestructorForLockFree
to delete each of remaining elements, if any. If necessary, specialize a function template to perform necessary processing.. Definition at line 626 of file LockFree.h.
|
inlinenoexcept |
Closes the queue and restores it to the state before its initialization. This is not thread-safe.
0
on success.DestructorForLockFree<T>
. Definition at line 641 of file LockFree.h.
|
inlinenoexcept |
Picks up an element from the queue. This is thread-safe.
[out] | obj | An object picked up from the queue. |
[out] | prio | The priority of obj. |
nlib_mq_receive()
. Definition at line 651 of file LockFree.h.
|
inlinenoexcept |
Adds an element to the queue. This is thread-safe.
[in] | obj | A pointer to the element. |
[in] | prio | The priority in the range of 0 to 31 inclusive. |
nlib_mq_send()
. Definition at line 647 of file LockFree.h.
|
inlinenoexcept |
Initializes the queue. This is not thread-safe.
[in] | max_size | The maximum number of elements that can be stored in the queue. |
0 | Success. |
EINVAL | max_size exceeds INT32_MAX . |
EALREADY | Already initialized. |
Other | errors returned by nlib_mq_open() . |
Definition at line 630 of file LockFree.h.
© Nintendo Co., Ltd. All rights reserved.