diff options
author | Loic Blot <loic.blot@unix-experience.fr> | 2015-03-05 20:54:36 +0100 |
---|---|---|
committer | Loic Blot <loic.blot@unix-experience.fr> | 2015-03-17 17:12:20 +0100 |
commit | 2f0107f4a7e82019a68ae3c0572886622d9d49bf (patch) | |
tree | 58e9aa428df19e23dc2db3d8577107e193dba3c6 /src/util | |
parent | 94b3950958c643c39c60b382c85f833593a718d0 (diff) | |
download | minetest-2f0107f4a7e82019a68ae3c0572886622d9d49bf.tar.gz minetest-2f0107f4a7e82019a68ae3c0572886622d9d49bf.tar.bz2 minetest-2f0107f4a7e82019a68ae3c0572886622d9d49bf.zip |
MutexedQueue inherits must use std::deque instead of std::list
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/container.h | 69 | ||||
-rw-r--r-- | src/util/thread.h | 6 |
2 files changed, 28 insertions, 47 deletions
diff --git a/src/util/container.h b/src/util/container.h index 7945df54b..936c46d61 100644 --- a/src/util/container.h +++ b/src/util/container.h @@ -200,12 +200,12 @@ public: bool empty() { JMutexAutoLock lock(m_mutex); - return (m_size.GetValue() == 0); + return (m_queue.size() == 0); } void push_back(T t) { JMutexAutoLock lock(m_mutex); - m_list.push_back(t); + m_queue.push_back(t); m_size.Post(); } @@ -214,34 +214,28 @@ public: */ 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); - typename std::list<T>::iterator begin = m_list.begin(); - T t = *begin; - m_list.erase(begin); + T t = m_queue.front(); + m_queue.pop_front(); return t; } - else - { + else { return T(); } } 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); - typename std::list<T>::iterator begin = m_list.begin(); - T t = *begin; - m_list.erase(begin); + T t = m_queue.front(); + m_queue.pop_front(); return t; } - else - { + else { throw ItemNotFoundException("MutexedQueue: queue is empty"); } } @@ -252,26 +246,21 @@ public: JMutexAutoLock lock(m_mutex); - typename std::list<T>::iterator begin = m_list.begin(); - T t = *begin; - m_list.erase(begin); + T t = m_queue.front(); + m_queue.pop_front(); return t; } 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); - typename std::list<T>::iterator last = m_list.end(); - last--; - T t = *last; - m_list.erase(last); + T t = m_queue.back(); + m_queue.pop_back(); return t; } - else - { + else { throw ItemNotFoundException("MutexedQueue: queue is empty"); } } @@ -281,18 +270,14 @@ public: */ 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); - typename std::list<T>::iterator last = m_list.end(); - last--; - T t = *last; - m_list.erase(last); + T t = m_queue.back(); + m_queue.pop_back(); return t; } - else - { + else { return T(); } } @@ -303,10 +288,8 @@ public: JMutexAutoLock lock(m_mutex); - typename std::list<T>::iterator last = m_list.end(); - last--; - T t = *last; - m_list.erase(last); + T t = m_queue.back(); + m_queue.pop_back(); return t; } @@ -316,15 +299,13 @@ protected: return m_mutex; } - // NEVER EVER modify the >>list<< you got by using this function! - // You may only modify it's content - std::list<T> & getList() + std::deque<T> & getQueue() { - return m_list; + return m_queue; } + std::deque<T> m_queue; JMutex m_mutex; - std::list<T> m_list; JSemaphore m_size; }; diff --git a/src/util/thread.h b/src/util/thread.h index 8b3c33621..eda9c0ca2 100644 --- a/src/util/thread.h +++ b/src/util/thread.h @@ -130,9 +130,9 @@ public: /* If the caller is already on the list, only update CallerData */ - for(typename std::list< GetRequest<Key, T, Caller, CallerData> >::iterator - i = m_queue.getList().begin(); - i != m_queue.getList().end(); ++i) + for(typename std::deque< GetRequest<Key, T, Caller, CallerData> >::iterator + i = m_queue.getQueue().begin(); + i != m_queue.getQueue().end(); ++i) { GetRequest<Key, T, Caller, CallerData> &request = *i; |