2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2004-10-22 01:22:23 +04:00
|
|
|
|
|
|
|
#ifndef TestCommon_h__
|
|
|
|
#define TestCommon_h__
|
|
|
|
|
2006-05-10 21:30:15 +04:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include "nsThreadUtils.h"
|
2012-06-06 07:18:25 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2006-05-10 21:30:15 +04:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2018-03-09 17:37:18 +03:00
|
|
|
class WaitForCondition final : public nsIRunnable {
|
2006-05-10 21:30:15 +04:00
|
|
|
public:
|
2013-07-19 06:24:13 +04:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
2016-11-29 21:53:48 +03:00
|
|
|
|
|
|
|
void Wait(int pending) {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
MOZ_ASSERT(mPending == 0);
|
|
|
|
|
|
|
|
mPending = pending;
|
2017-05-15 16:34:19 +03:00
|
|
|
mozilla::SpinEventLoopUntil([&]() { return !mPending; });
|
2016-11-29 21:53:48 +03:00
|
|
|
NS_ProcessPendingEvents(nullptr);
|
2006-05-10 21:30:15 +04:00
|
|
|
}
|
|
|
|
|
2016-11-29 21:53:48 +03:00
|
|
|
void Notify() { NS_DispatchToMainThread(this); }
|
2006-05-10 21:30:15 +04:00
|
|
|
|
2016-11-29 21:53:48 +03:00
|
|
|
private:
|
|
|
|
virtual ~WaitForCondition() {}
|
2006-05-10 21:30:15 +04:00
|
|
|
|
2016-11-29 21:53:48 +03:00
|
|
|
NS_IMETHOD Run() override {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
MOZ_ASSERT(mPending);
|
2006-05-10 21:30:15 +04:00
|
|
|
|
2016-11-29 21:53:48 +03:00
|
|
|
--mPending;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t mPending = 0;
|
|
|
|
};
|
|
|
|
NS_IMPL_ISUPPORTS(WaitForCondition, nsIRunnable)
|
2006-05-10 21:30:15 +04:00
|
|
|
|
2004-10-22 01:22:23 +04:00
|
|
|
#endif
|