tor-browser

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

MediaSystemResourceClient.cpp (1685B)


      1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim:set ts=2 sw=2 sts=2 et cindent: */
      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 file,
      5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #include "MediaSystemResourceClient.h"
      8 
      9 #include "mozilla/Monitor.h"
     10 #include "mozilla/ReentrantMonitor.h"
     11 
     12 namespace mozilla {
     13 
     14 Atomic<uint32_t> MediaSystemResourceClient::sSerialCounter(0);
     15 
     16 MediaSystemResourceClient::MediaSystemResourceClient(
     17    MediaSystemResourceType aReourceType)
     18    : mResourceType(aReourceType),
     19      mId(++sSerialCounter),
     20      mListener(nullptr),
     21      mResourceState(RESOURCE_STATE_START),
     22      mIsSync(false),
     23      mAcquireSyncWaitMonitor(nullptr),
     24      mAcquireSyncWaitDone(nullptr) {
     25  mManager = MediaSystemResourceManager::Get();
     26  if (mManager) {
     27    mManager->Register(this);
     28  }
     29 }
     30 
     31 MediaSystemResourceClient::~MediaSystemResourceClient() {
     32  ReleaseResource();
     33  if (mManager) {
     34    mManager->Unregister(this);
     35  }
     36 }
     37 
     38 bool MediaSystemResourceClient::SetListener(
     39    MediaSystemResourceReservationListener* aListener) {
     40  if (!mManager) {
     41    return false;
     42  }
     43  return mManager->SetListener(this, aListener);
     44 }
     45 
     46 void MediaSystemResourceClient::Acquire() {
     47  if (!mManager) {
     48    return;
     49  }
     50  mManager->Acquire(this);
     51 }
     52 
     53 bool MediaSystemResourceClient::AcquireSyncNoWait() {
     54  if (!mManager) {
     55    return false;
     56  }
     57  return mManager->AcquireSyncNoWait(this);
     58 }
     59 
     60 void MediaSystemResourceClient::ReleaseResource() {
     61  if (!mManager) {
     62    return;
     63  }
     64  mManager->ReleaseResource(this);
     65 }
     66 
     67 }  // namespace mozilla