14 #ifndef HTGS_PRIORITYBLOCKINGQUEUE_HPP 15 #define HTGS_PRIORITYBLOCKINGQUEUE_HPP 17 #include <condition_variable> 41 this->queueActiveMaxSize = 0;
44 this->dequeueLockTime = 0;
45 this->dequeueWaitTime = 0;
46 this->enqueueLockTime = 0;
47 this->enqueueWaitTime = 0;
58 this->queueActiveMaxSize = 0;
61 this->dequeueLockTime = 0;
62 this->dequeueWaitTime = 0;
63 this->enqueueLockTime = 0;
64 this->enqueueWaitTime = 0;
82 std::cerr << __FILE__ <<
":" << __LINE__
83 <<
"ERROR: Requesting remaining capacity on BlockingQueue that does not have a max size" << std::endl;
103 std::unique_lock<std::mutex> lock(this->
mutex);
115 T res = this->
queue.top();
128 auto start = std::chrono::high_resolution_clock::now();
130 std::unique_lock<std::mutex> lock(this->
mutex);
132 auto end = std::chrono::high_resolution_clock::now();
133 this->enqueueLockTime += std::chrono::duration_cast<std::chrono::microseconds>(end - start).count();
137 start = std::chrono::high_resolution_clock::now();
141 end = std::chrono::high_resolution_clock::now();
142 this->enqueueWaitTime += std::chrono::duration_cast<std::chrono::microseconds>(end - start).count();
148 if (
queue.size() > queueActiveMaxSize)
149 queueActiveMaxSize =
queue.size();
163 auto start = std::chrono::high_resolution_clock::now();
165 std::unique_lock<std::mutex> lock(this->
mutex);
167 auto end = std::chrono::high_resolution_clock::now();
168 this->dequeueLockTime += std::chrono::duration_cast<std::chrono::microseconds>(end - start).count();
170 start = std::chrono::high_resolution_clock::now();
175 end = std::chrono::high_resolution_clock::now();
176 this->dequeueWaitTime += std::chrono::duration_cast<std::chrono::microseconds>(end - start).count();
178 T res = this->
queue.top();
191 std::unique_lock<std::mutex> lock(this->
mutex);
192 if (this->
condition.wait_for(lock, std::chrono::microseconds(timeout),
193 [=] { return !this->queue.empty(); })) {
194 T res = this->
queue.top();
202 unsigned long long int getEnqueueLockTime()
const {
203 return enqueueLockTime;
205 unsigned long long int getDequeueLockTime()
const {
206 return dequeueLockTime;
208 unsigned long long int getEnqueueWaitTime()
const {
209 return enqueueWaitTime;
211 unsigned long long int getDequeueWaitTime()
const {
212 return dequeueWaitTime;
217 size_t getQueueActiveMaxSize()
const {
218 return queueActiveMaxSize;
221 void resetMaxQueueSize() {
222 queueActiveMaxSize = 0;
228 unsigned long long int enqueueLockTime;
229 unsigned long long int dequeueLockTime;
230 unsigned long long int enqueueWaitTime;
231 unsigned long long int dequeueWaitTime;
234 size_t queueActiveMaxSize;
243 #endif //HTGS_PRIORITYBLOCKINGQUEUE_HPP size_t size()
Gets the number of elements in the priority queue.
Definition: PriorityBlockingQueue.hpp:102
std::priority_queue< T, std::vector< T >, IData > queue
The priority queue.
Definition: PriorityBlockingQueue.hpp:237
T poll(size_t timeout)
Polls for data given the specified timeout time in microseconds.
Definition: PriorityBlockingQueue.hpp:190
PriorityBlockingQueue(size_t qSize)
Creates a priority blocking queue that will block a data requester when the queue is empty or full...
Definition: PriorityBlockingQueue.hpp:55
size_t remainingCapacity()
Gets the remaining capacity of the priority queue based on the queueSize.
Definition: PriorityBlockingQueue.hpp:80
PriorityBlockingQueue()
Creates a priority blocking queue that will only block a data requester when the queue is empty...
Definition: PriorityBlockingQueue.hpp:38
std::condition_variable condition
The condition variable used for waking up waiting threads.
Definition: PriorityBlockingQueue.hpp:239
void Enqueue(T const &value)
Adds an element into the priority queue.
Definition: PriorityBlockingQueue.hpp:126
Class to hold any type of data.
Definition: IData.hpp:60
bool isEmpty()
Gets whether the priority queue is empty or not.
Definition: PriorityBlockingQueue.hpp:94
Implements the IData class, which is used for all data types entering/leaving a task graph...
Creates a thread-safe priority queue that will wait when no data is available and can block if the qu...
Definition: PriorityBlockingQueue.hpp:33
std::mutex mutex
The mutex to ensure thread safety.
Definition: PriorityBlockingQueue.hpp:238
size_t queueSize
The maximum size of the queue, set to -1 for infinite size.
Definition: PriorityBlockingQueue.hpp:236
~PriorityBlockingQueue()
Destructor.
Definition: PriorityBlockingQueue.hpp:71
T Dequeue()
Removes an element from the priority queue.
Definition: PriorityBlockingQueue.hpp:161
Definition: Bookkeeper.hpp:23