|
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.
|
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 casacore::sisco::ConditionalQueue< T >::max_size_, casacore::sisco::ConditionalQueue< T >::pop_condition_, casacore::sisco::ConditionalQueue< T >::push_condition_, and casacore::sisco::ConditionalQueue< T >::values_.
|
inline |
Makes PopIf return false once the queue is empty.
Definition at line 104 of file ConditionalQueue.h.
References casacore::sisco::ConditionalQueue< T >::is_finished_, and casacore::sisco::ConditionalQueue< T >::push_condition_.
|
inlineprivate |
Definition at line 121 of file ConditionalQueue.h.
References casacore::sisco::ConditionalQueue< T >::values_.
Referenced by casacore::sisco::ConditionalQueue< T >::PopIf().
|
inline |
Definition at line 117 of file ConditionalQueue.h.
References casacore::sisco::ConditionalQueue< T >::max_size_.
|
inline |
Notify the queue that the condition for values might have changed.
Definition at line 99 of file ConditionalQueue.h.
References casacore::sisco::ConditionalQueue< T >::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 casacore::sisco::ConditionalQueue< T >::GetNext(), casacore::sisco::ConditionalQueue< T >::is_finished_, casacore::sisco::ConditionalQueue< T >::pop_condition_, casacore::sisco::ConditionalQueue< T >::push_condition_, and casacore::sisco::ConditionalQueue< T >::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 casacore::sisco::ConditionalQueue< T >::max_size_, casacore::sisco::ConditionalQueue< T >::pop_condition_, casacore::sisco::ConditionalQueue< T >::push_condition_, casacore::value(), and casacore::sisco::ConditionalQueue< T >::values_.
|
inline |
Definition at line 112 of file ConditionalQueue.h.
References casacore::sisco::ConditionalQueue< T >::values_.
|
private |
Definition at line 130 of file ConditionalQueue.h.
Referenced by casacore::sisco::ConditionalQueue< T >::Finish(), and casacore::sisco::ConditionalQueue< T >::PopIf().
|
private |
Definition at line 131 of file ConditionalQueue.h.
Referenced by casacore::sisco::ConditionalQueue< T >::Emplace(), casacore::sisco::ConditionalQueue< T >::MaxSize(), and casacore::sisco::ConditionalQueue< T >::Push().
|
private |
Definition at line 132 of file ConditionalQueue.h.
Referenced by casacore::sisco::ConditionalQueue< T >::Emplace(), casacore::sisco::ConditionalQueue< T >::PopIf(), and casacore::sisco::ConditionalQueue< T >::Push().
|
private |
Definition at line 133 of file ConditionalQueue.h.
Referenced by casacore::sisco::ConditionalQueue< T >::Emplace(), casacore::sisco::ConditionalQueue< T >::Finish(), casacore::sisco::ConditionalQueue< T >::NotifyOneChange(), casacore::sisco::ConditionalQueue< T >::PopIf(), and casacore::sisco::ConditionalQueue< T >::Push().
|
private |
Definition at line 129 of file ConditionalQueue.h.
Referenced by casacore::sisco::ConditionalQueue< T >::Emplace(), casacore::sisco::ConditionalQueue< T >::GetNext(), casacore::sisco::ConditionalQueue< T >::PopIf(), casacore::sisco::ConditionalQueue< T >::Push(), and casacore::sisco::ConditionalQueue< T >::Size().