1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4  * License, v. 2.0. If a copy of the MPL was not distributed with this
5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef __GMPTestMonitor_h__
7 #define __GMPTestMonitor_h__
8 
9 #include "nsThreadUtils.h"
10 #include "mozilla/SchedulerGroup.h"
11 
12 class GMPTestMonitor {
13  public:
GMPTestMonitor()14   GMPTestMonitor() : mFinished(false) {}
15 
AwaitFinished()16   void AwaitFinished() {
17     MOZ_ASSERT(NS_IsMainThread());
18     mozilla::SpinEventLoopUntil([&]() { return mFinished; });
19     mFinished = false;
20   }
21 
22  private:
MarkFinished()23   void MarkFinished() {
24     MOZ_ASSERT(NS_IsMainThread());
25     mFinished = true;
26   }
27 
28  public:
SetFinished()29   void SetFinished() {
30     mozilla::SchedulerGroup::Dispatch(mozilla::TaskCategory::Other,
31                                       mozilla::NewNonOwningRunnableMethod(
32                                           "GMPTestMonitor::MarkFinished", this,
33                                           &GMPTestMonitor::MarkFinished));
34   }
35 
36  private:
37   bool mFinished;
38 };
39 
40 #endif  // __GMPTestMonitor_h__
41