dom/workers/WorkerHolder.cpp
author David Anderson <danderson@mozilla.com>
Fri, 01 Jul 2016 01:15:16 -0700
changeset 343414 887adb3d9482c267c5928f5d900252361f35ac25
parent 342450 1c5d78c7ba432f923296cf6d664e345782cb67b1
child 343579 cc14db2645218df5f292f1eb00fdd1e9d7d83486
permissions -rw-r--r--
Move InProcessCompositorWidget to its own file. (bug 1281998 part 3, r=jimm)

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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/. */

#include "WorkerHolder.h"
#include "WorkerPrivate.h"

BEGIN_WORKERS_NAMESPACE

WorkerHolder::WorkerHolder()
  : mWorkerPrivate(nullptr)
{
}

WorkerHolder::~WorkerHolder()
{
  ReleaseWorkerInternal();
  MOZ_ASSERT(mWorkerPrivate == nullptr);
}

bool
WorkerHolder::HoldWorker(WorkerPrivate* aWorkerPrivate)
{
  MOZ_ASSERT(aWorkerPrivate);
  aWorkerPrivate->AssertIsOnWorkerThread();

  if (!aWorkerPrivate->AddHolder(this)) {
    return false;
  }

  mWorkerPrivate = aWorkerPrivate;
  return true;
}

void
WorkerHolder::ReleaseWorker()
{
  MOZ_ASSERT(mWorkerPrivate);
  ReleaseWorkerInternal();
}

void
WorkerHolder::ReleaseWorkerInternal()
{
  if (mWorkerPrivate) {
    mWorkerPrivate->RemoveHolder(this);
    mWorkerPrivate = nullptr;
  }
}

END_WORKERS_NAMESPACE