MutexedQueue inherits must use std::deque instead of std::list
parent
94b3950958
commit
2f0107f4a7
|
@ -200,12 +200,12 @@ public:
|
||||||
bool empty()
|
bool empty()
|
||||||
{
|
{
|
||||||
JMutexAutoLock lock(m_mutex);
|
JMutexAutoLock lock(m_mutex);
|
||||||
return (m_size.GetValue() == 0);
|
return (m_queue.size() == 0);
|
||||||
}
|
}
|
||||||
void push_back(T t)
|
void push_back(T t)
|
||||||
{
|
{
|
||||||
JMutexAutoLock lock(m_mutex);
|
JMutexAutoLock lock(m_mutex);
|
||||||
m_list.push_back(t);
|
m_queue.push_back(t);
|
||||||
m_size.Post();
|
m_size.Post();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -214,34 +214,28 @@ public:
|
||||||
*/
|
*/
|
||||||
T pop_frontNoEx(u32 wait_time_max_ms)
|
T pop_frontNoEx(u32 wait_time_max_ms)
|
||||||
{
|
{
|
||||||
if (m_size.Wait(wait_time_max_ms))
|
if (m_size.Wait(wait_time_max_ms)) {
|
||||||
{
|
|
||||||
JMutexAutoLock lock(m_mutex);
|
JMutexAutoLock lock(m_mutex);
|
||||||
|
|
||||||
typename std::list<T>::iterator begin = m_list.begin();
|
T t = m_queue.front();
|
||||||
T t = *begin;
|
m_queue.pop_front();
|
||||||
m_list.erase(begin);
|
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
return T();
|
return T();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
T pop_front(u32 wait_time_max_ms)
|
T pop_front(u32 wait_time_max_ms)
|
||||||
{
|
{
|
||||||
if (m_size.Wait(wait_time_max_ms))
|
if (m_size.Wait(wait_time_max_ms)) {
|
||||||
{
|
|
||||||
JMutexAutoLock lock(m_mutex);
|
JMutexAutoLock lock(m_mutex);
|
||||||
|
|
||||||
typename std::list<T>::iterator begin = m_list.begin();
|
T t = m_queue.front();
|
||||||
T t = *begin;
|
m_queue.pop_front();
|
||||||
m_list.erase(begin);
|
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
throw ItemNotFoundException("MutexedQueue: queue is empty");
|
throw ItemNotFoundException("MutexedQueue: queue is empty");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -252,26 +246,21 @@ public:
|
||||||
|
|
||||||
JMutexAutoLock lock(m_mutex);
|
JMutexAutoLock lock(m_mutex);
|
||||||
|
|
||||||
typename std::list<T>::iterator begin = m_list.begin();
|
T t = m_queue.front();
|
||||||
T t = *begin;
|
m_queue.pop_front();
|
||||||
m_list.erase(begin);
|
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
T pop_back(u32 wait_time_max_ms=0)
|
T pop_back(u32 wait_time_max_ms=0)
|
||||||
{
|
{
|
||||||
if (m_size.Wait(wait_time_max_ms))
|
if (m_size.Wait(wait_time_max_ms)) {
|
||||||
{
|
|
||||||
JMutexAutoLock lock(m_mutex);
|
JMutexAutoLock lock(m_mutex);
|
||||||
|
|
||||||
typename std::list<T>::iterator last = m_list.end();
|
T t = m_queue.back();
|
||||||
last--;
|
m_queue.pop_back();
|
||||||
T t = *last;
|
|
||||||
m_list.erase(last);
|
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
throw ItemNotFoundException("MutexedQueue: queue is empty");
|
throw ItemNotFoundException("MutexedQueue: queue is empty");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -281,18 +270,14 @@ public:
|
||||||
*/
|
*/
|
||||||
T pop_backNoEx(u32 wait_time_max_ms=0)
|
T pop_backNoEx(u32 wait_time_max_ms=0)
|
||||||
{
|
{
|
||||||
if (m_size.Wait(wait_time_max_ms))
|
if (m_size.Wait(wait_time_max_ms)) {
|
||||||
{
|
|
||||||
JMutexAutoLock lock(m_mutex);
|
JMutexAutoLock lock(m_mutex);
|
||||||
|
|
||||||
typename std::list<T>::iterator last = m_list.end();
|
T t = m_queue.back();
|
||||||
last--;
|
m_queue.pop_back();
|
||||||
T t = *last;
|
|
||||||
m_list.erase(last);
|
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
return T();
|
return T();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -303,10 +288,8 @@ public:
|
||||||
|
|
||||||
JMutexAutoLock lock(m_mutex);
|
JMutexAutoLock lock(m_mutex);
|
||||||
|
|
||||||
typename std::list<T>::iterator last = m_list.end();
|
T t = m_queue.back();
|
||||||
last--;
|
m_queue.pop_back();
|
||||||
T t = *last;
|
|
||||||
m_list.erase(last);
|
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -316,15 +299,13 @@ protected:
|
||||||
return m_mutex;
|
return m_mutex;
|
||||||
}
|
}
|
||||||
|
|
||||||
// NEVER EVER modify the >>list<< you got by using this function!
|
std::deque<T> & getQueue()
|
||||||
// You may only modify it's content
|
|
||||||
std::list<T> & getList()
|
|
||||||
{
|
{
|
||||||
return m_list;
|
return m_queue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::deque<T> m_queue;
|
||||||
JMutex m_mutex;
|
JMutex m_mutex;
|
||||||
std::list<T> m_list;
|
|
||||||
JSemaphore m_size;
|
JSemaphore m_size;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -130,9 +130,9 @@ public:
|
||||||
/*
|
/*
|
||||||
If the caller is already on the list, only update CallerData
|
If the caller is already on the list, only update CallerData
|
||||||
*/
|
*/
|
||||||
for(typename std::list< GetRequest<Key, T, Caller, CallerData> >::iterator
|
for(typename std::deque< GetRequest<Key, T, Caller, CallerData> >::iterator
|
||||||
i = m_queue.getList().begin();
|
i = m_queue.getQueue().begin();
|
||||||
i != m_queue.getList().end(); ++i)
|
i != m_queue.getQueue().end(); ++i)
|
||||||
{
|
{
|
||||||
GetRequest<Key, T, Caller, CallerData> &request = *i;
|
GetRequest<Key, T, Caller, CallerData> &request = *i;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue