1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
9 #include "nsThreadUtils.h"
10 #include "mozilla/Attributes.h"
11 #include "mozilla/SpinEventLoopUntil.h"
13 //-----------------------------------------------------------------------------
15 class WaitForCondition final
: public nsIRunnable
{
17 NS_DECL_THREADSAFE_ISUPPORTS
19 void Wait(int pending
) {
20 MOZ_RELEASE_ASSERT(NS_IsMainThread());
21 MOZ_RELEASE_ASSERT(mPending
== 0);
24 mozilla::SpinEventLoopUntil("TestCommon.h:WaitForCondition::Wait"_ns
,
25 [&]() { return !mPending
; });
26 NS_ProcessPendingEvents(nullptr);
29 void Notify() { NS_DispatchToMainThread(this); }
32 virtual ~WaitForCondition() = default;
34 NS_IMETHOD
Run() override
{
35 MOZ_RELEASE_ASSERT(NS_IsMainThread());
36 MOZ_RELEASE_ASSERT(mPending
);
42 uint32_t mPending
= 0;