diff options
author | Tycho Bickerstaff <work.tycho@gmail.com> | 2014-01-02 13:32:55 +0100 |
---|---|---|
committer | Tycho Bickerstaff <work.tycho@gmail.com> | 2014-01-02 13:32:55 +0100 |
commit | 042b72bc172e7eb4e9ef7668ae28be6e7a3b4036 (patch) | |
tree | 7e3d265d3d1fde9f80f3f4623c2f59a5b0521b65 /src/OSSupport/Queue.h | |
parent | Merge branch 'master' into threadsafequeue (diff) | |
download | cuberite-042b72bc172e7eb4e9ef7668ae28be6e7a3b4036.tar cuberite-042b72bc172e7eb4e9ef7668ae28be6e7a3b4036.tar.gz cuberite-042b72bc172e7eb4e9ef7668ae28be6e7a3b4036.tar.bz2 cuberite-042b72bc172e7eb4e9ef7668ae28be6e7a3b4036.tar.lz cuberite-042b72bc172e7eb4e9ef7668ae28be6e7a3b4036.tar.xz cuberite-042b72bc172e7eb4e9ef7668ae28be6e7a3b4036.tar.zst cuberite-042b72bc172e7eb4e9ef7668ae28be6e7a3b4036.zip |
Diffstat (limited to 'src/OSSupport/Queue.h')
-rw-r--r-- | src/OSSupport/Queue.h | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/src/OSSupport/Queue.h b/src/OSSupport/Queue.h index eb323b067..153e201c1 100644 --- a/src/OSSupport/Queue.h +++ b/src/OSSupport/Queue.h @@ -3,8 +3,6 @@ #include <list> -#include "../OSSupport/Promise.h" - //this empty struct allows function inlining template<class T> struct cQueueFuncs @@ -52,6 +50,7 @@ public: if (m_contents.size() == 0) return false; item = m_contents.front(); m_contents.pop_front(); + m_evtRemoved.Set(); return true; } ItemType DequeueItem() @@ -62,10 +61,15 @@ public: cCSUnlock Unlock(m_CS); m_evtAdded.Wait(); } - return m_contents.pop_front(); + ItemType item = m_contents.front(); + m_contents.pop_front(); + m_evtRemoved.Set(); + return item; } - cPromise* BlockTillEmpty() { - return new cEmptyQueuePromise(this); + void BlockTillEmpty() { + //There is a very slight race condition here if the load completes between the check + //and the wait. + while(!(Size() == 0)){m_evtRemoved.Wait();} } //can all be inlined when delete is a noop void Clear() @@ -87,18 +91,12 @@ public: { cCSLock Lock(m_CS); m_contents.remove(item); + m_evtRemoved.Set(); } private: ListType m_contents; cCriticalSection m_CS; cEvent m_evtAdded; - - class cEmptyQueuePromise : public cPromise { - public: - cEmptyQueuePromise(cQueue* a_Queue) : cPromise(), m_Queue(a_Queue) {} - virtual bool IsCompleted() {return m_Queue->Size() != 0;} - private: - cQueue* m_Queue; - }; + cEvent m_evtRemoved; }; |