Add top_and_pop fn to TSQueue

This commit is contained in:
Stephen Seo 2019-08-30 15:55:43 +09:00
parent ee85ced0e0
commit 0167c4953b

View file

@ -25,6 +25,7 @@ class TSQueue {
bool push(const T &data);
T top();
bool pop();
T top_and_pop();
void clear();
void changeCapacity(unsigned int newCapacity);
unsigned int size();
@ -96,6 +97,14 @@ bool TSQueue<T>::pop() {
return true;
}
template <typename T>
T TSQueue<T>::top_and_pop() {
std::lock_guard<std::mutex> lock(mutex);
T value = rb.top();
rb.pop();
return value;
}
template <typename T>
void TSQueue<T>::clear() {
std::lock_guard<std::mutex> lock(mutex);