From 0167c4953beaac1738efef47ddbb8182960cd8ab Mon Sep 17 00:00:00 2001 From: Stephen Seo Date: Fri, 30 Aug 2019 15:55:43 +0900 Subject: [PATCH] Add top_and_pop fn to TSQueue --- cpp_impl/src/TSQueue.hpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/cpp_impl/src/TSQueue.hpp b/cpp_impl/src/TSQueue.hpp index 947f76c..1985eee 100644 --- a/cpp_impl/src/TSQueue.hpp +++ b/cpp_impl/src/TSQueue.hpp @@ -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::pop() { return true; } +template +T TSQueue::top_and_pop() { + std::lock_guard lock(mutex); + T value = rb.top(); + rb.pop(); + return value; +} + template void TSQueue::clear() { std::lock_guard lock(mutex); -- 2.49.0