Add base::concurrent_queue::empty() member function

This commit is contained in:
David Capello 2015-04-06 11:52:04 -03:00
parent e4667149f4
commit c76a47b33f

View File

@ -1,5 +1,5 @@
// Aseprite Base Library // Aseprite Base Library
// Copyright (c) 2001-2014 David Capello // Copyright (c) 2001-2015 David Capello
// //
// This file is released under the terms of the MIT license. // This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information. // Read LICENSE.txt for more information.
@ -25,6 +25,15 @@ namespace base {
~concurrent_queue() { ~concurrent_queue() {
} }
bool empty() const {
bool result;
{
scoped_lock hold(m_mutex);
result = m_queue.empty();
}
return result;
}
void push(const T& value) { void push(const T& value) {
scoped_lock hold(m_mutex); scoped_lock hold(m_mutex);
m_queue.push(value); m_queue.push(value);
@ -45,7 +54,7 @@ namespace base {
private: private:
std::queue<T> m_queue; std::queue<T> m_queue;
mutex m_mutex; mutable mutex m_mutex;
DISABLE_COPYING(concurrent_queue); DISABLE_COPYING(concurrent_queue);
}; };