|
casacore
|
A queue with a limited size and the ability to query only specific values. More...
#include <ConditionalQueue.h>
Public Member Functions | |
| ConditionalQueue (size_t max_size) | |
| ~ConditionalQueue ()=default | |
| void | Push (T &&value, std::unique_lock< std::mutex > &lock) |
| Place a new object at the end of the queue. | |
| template<typename... Args> | |
| void | Emplace (std::unique_lock< std::mutex > &lock, Args &&... args) |
| Same as Push(), but constructs in place. | |
| template<typename Condition> | |
| bool | PopIf (T &result, std::unique_lock< std::mutex > &lock, Condition condition) |
| Pop an object from the queue for which a specified condition holds. | |
| void | NotifyOneChange () |
| Notify the queue that the condition for values might have changed. | |
| void | Finish (std::unique_lock< std::mutex > &lock) |
| Makes PopIf return false once the queue is empty. | |
| size_t | Size (std::unique_lock< std::mutex > &lock) const |
| size_t | MaxSize () const |
Private Member Functions | |
| template<typename Condition> | |
| std::list< T >::iterator | GetNext (Condition &condition) |
Private Attributes | |
| std::list< T > | values_ |
| bool | is_finished_ |
| size_t | max_size_ |
| std::condition_variable | pop_condition_ |
| std::condition_variable | push_condition_ |
A queue with a limited size and the ability to query only specific values.
The queue is synchronized, but the caller needs to maintain a mutex.
The reason for this is that if the condition requires locking, the same lock can be used for the queue operations and the condition.
Definition at line 20 of file ConditionalQueue.h.
|
inline |
Definition at line 22 of file ConditionalQueue.h.
References max_size_.
|
default |
|
inline |
Same as Push(), but constructs in place.
We need to notify all, because if only one thread is awoken that is looking for a specific condition that is not met, the signal is lost while another nother thread's condition may be met.
Definition at line 50 of file ConditionalQueue.h.
References max_size_, pop_condition_, push_condition_, and values_.
|
inline |
Makes PopIf return false once the queue is empty.
Definition at line 104 of file ConditionalQueue.h.
References is_finished_, and push_condition_.
|
inlineprivate |
|
inline |
Definition at line 117 of file ConditionalQueue.h.
References max_size_.
|
inline |
Notify the queue that the condition for values might have changed.
Definition at line 99 of file ConditionalQueue.h.
References push_condition_.
|
inline |
Pop an object from the queue for which a specified condition holds.
The lock must be owned on entry and will be locked on exit, but may be temporary unlocked during the function.
The condition must be a callable function that takes a value as function parameter and returns a bool. The lock will always be owned when the condition function is called.
If this thread emptied the finished queue while another thread is waiting for a value, it needs to be notified to finish.
Definition at line 72 of file ConditionalQueue.h.
References GetNext(), is_finished_, pop_condition_, push_condition_, and values_.
|
inline |
Place a new object at the end of the queue.
The lock must be owned on entry and will be locked on exit, but may be temporary unlocked during the function.
If the queue is full, the method will block until space is available.
We need to notify all, because if only one thread is awoken that is looking for a specific condition that is not met, the signal is lost while another nother thread's condition may be met.
Definition at line 34 of file ConditionalQueue.h.
References max_size_, casacore::NewDelAllocator< T >::value, pop_condition_, push_condition_, and values_.
|
inline |
Definition at line 112 of file ConditionalQueue.h.
References values_.
|
private |
Definition at line 130 of file ConditionalQueue.h.
|
private |
Definition at line 131 of file ConditionalQueue.h.
Referenced by ConditionalQueue(), Emplace(), MaxSize(), and Push().
|
private |
Definition at line 132 of file ConditionalQueue.h.
|
private |
Definition at line 133 of file ConditionalQueue.h.
Referenced by Emplace(), Finish(), NotifyOneChange(), PopIf(), and Push().
|
private |