2016-06-23 11:53:14 +03:00
|
|
|
/* -*- 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
|
|
|
|
|
2017-05-10 19:27:10 +03:00
|
|
|
WorkerHolder::WorkerHolder(Behavior aBehavior)
|
2016-06-23 11:53:14 +03:00
|
|
|
: mWorkerPrivate(nullptr)
|
2017-05-10 19:27:10 +03:00
|
|
|
, mBehavior(aBehavior)
|
2016-06-23 11:53:14 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
WorkerHolder::~WorkerHolder()
|
|
|
|
{
|
2016-07-18 10:13:05 +03:00
|
|
|
NS_ASSERT_OWNINGTHREAD(WorkerHolder);
|
2016-06-23 11:53:14 +03:00
|
|
|
ReleaseWorkerInternal();
|
|
|
|
MOZ_ASSERT(mWorkerPrivate == nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2016-08-18 17:11:04 +03:00
|
|
|
WorkerHolder::HoldWorker(WorkerPrivate* aWorkerPrivate, Status aFailStatus)
|
2016-06-23 11:53:14 +03:00
|
|
|
{
|
2016-07-18 10:13:05 +03:00
|
|
|
NS_ASSERT_OWNINGTHREAD(WorkerHolder);
|
2016-06-23 11:53:14 +03:00
|
|
|
MOZ_ASSERT(aWorkerPrivate);
|
|
|
|
aWorkerPrivate->AssertIsOnWorkerThread();
|
|
|
|
|
2016-08-18 17:11:04 +03:00
|
|
|
if (!aWorkerPrivate->AddHolder(this, aFailStatus)) {
|
2016-06-23 11:53:14 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
mWorkerPrivate = aWorkerPrivate;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WorkerHolder::ReleaseWorker()
|
|
|
|
{
|
2016-07-18 10:13:05 +03:00
|
|
|
NS_ASSERT_OWNINGTHREAD(WorkerHolder);
|
2016-06-23 11:53:14 +03:00
|
|
|
MOZ_ASSERT(mWorkerPrivate);
|
2016-07-18 10:13:05 +03:00
|
|
|
|
2016-06-23 11:53:14 +03:00
|
|
|
ReleaseWorkerInternal();
|
|
|
|
}
|
|
|
|
|
2017-05-10 19:27:10 +03:00
|
|
|
WorkerHolder::Behavior
|
|
|
|
WorkerHolder::GetBehavior() const
|
|
|
|
{
|
|
|
|
return mBehavior;
|
|
|
|
}
|
|
|
|
|
2016-06-23 11:53:14 +03:00
|
|
|
void
|
|
|
|
WorkerHolder::ReleaseWorkerInternal()
|
|
|
|
{
|
2016-07-18 10:13:05 +03:00
|
|
|
NS_ASSERT_OWNINGTHREAD(WorkerHolder);
|
|
|
|
|
2016-06-23 11:53:14 +03:00
|
|
|
if (mWorkerPrivate) {
|
2016-07-04 09:19:10 +03:00
|
|
|
mWorkerPrivate->AssertIsOnWorkerThread();
|
2016-06-23 11:53:14 +03:00
|
|
|
mWorkerPrivate->RemoveHolder(this);
|
|
|
|
mWorkerPrivate = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
END_WORKERS_NAMESPACE
|