tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

GMPTestMonitor.h (1142B)


      1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=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 "mozilla/SchedulerGroup.h"
     10 #include "mozilla/SpinEventLoopUntil.h"
     11 #include "nsThreadUtils.h"
     12 
     13 class GMPTestMonitor {
     14 public:
     15  GMPTestMonitor() : mFinished(false) {}
     16 
     17  void AwaitFinished() {
     18    MOZ_RELEASE_ASSERT(NS_IsMainThread());
     19    mozilla::SpinEventLoopUntil("GMPTestMonitor::AwaitFinished"_ns,
     20                                [&]() { return mFinished; });
     21    mFinished = false;
     22  }
     23 
     24 private:
     25  void MarkFinished() {
     26    MOZ_RELEASE_ASSERT(NS_IsMainThread());
     27    mFinished = true;
     28  }
     29 
     30 public:
     31  void SetFinished() {
     32    mozilla::SchedulerGroup::Dispatch(mozilla::NewNonOwningRunnableMethod(
     33        "GMPTestMonitor::MarkFinished", this, &GMPTestMonitor::MarkFinished));
     34  }
     35 
     36 private:
     37  bool mFinished;
     38 };
     39 
     40 #endif  // __GMPTestMonitor_h__