Bug 955888. Part 2: In chaos mode, sometimes yield just before dispatching an XPCOM event. r=bsmedberg

This gives other threads a chance to beat us in a race to dispatch an event to
this event queue.

--HG--
extra : rebase_source : ca19bb52281837762bce43481b3393cd2ecf6679
This commit is contained in:
Robert O'Callahan 2014-03-03 18:12:23 +13:00
parent e6993f791e
commit a22a728d85

View File

@ -8,6 +8,8 @@
#include "nsAutoPtr.h"
#include "prlog.h"
#include "nsThreadUtils.h"
#include "prthread.h"
#include "mozilla/ChaosMode.h"
using namespace mozilla;
@ -85,6 +87,14 @@ nsEventQueue::PutEvent(nsIRunnable *runnable)
nsRefPtr<nsIRunnable> event(runnable);
bool rv = true;
{
if (ChaosMode::isActive()) {
// With probability 0.5, yield so other threads have a chance to
// dispatch events to this queue first.
if (ChaosMode::randomUint32LessThan(2)) {
PR_Sleep(PR_INTERVAL_NO_WAIT);
}
}
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
if (!mHead) {