Created
July 18, 2009 01:58
-
-
Save benjamn/149380 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class EventQueue { | |
Queue<nsIRunnable> mQueue; | |
PRBool mWaiting; | |
mozilla::Monitor mRarelyUsedMonitor; | |
public: | |
EventQueue() | |
: mQueue() | |
, mWaiting(0) | |
, mRarelyUsedMonitor("EventQueue::mRarelyUsedMonitor") | |
{} | |
PRBool GetEvent(PRBool mayWait, nsIRunnable** result) { | |
if (!mQueue.dequeue(*result)) { | |
if (!mayWait) | |
return PR_FALSE; | |
mozilla::MonitorAutoEnter mon(mRarelyUsedMonitor); | |
while (!mQueue.dequeue(*result)) { | |
mWaiting = PR_TRUE; | |
mon.Wait(); | |
} | |
} | |
return PR_TRUE; | |
} | |
void PutEvent(nsIRunnable* event) { | |
NS_IF_ADDREF(event); | |
mQueue.enqueue(event); | |
if (mWaiting) { | |
mozilla::MonitorAutoEnter mon(mRarelyUsedMonitor); | |
mWaiting = PR_FALSE; | |
mon.NotifyAll(); | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment