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
|
|
|
|
|
|
|
|
WorkerHolder::WorkerHolder()
|
|
|
|
: mWorkerPrivate(nullptr)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
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 07:16:43 +03:00
|
|
|
WorkerHolder::HoldWorker(WorkerPrivate* aWorkerPrivate)
|
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 07:16:43 +03:00
|
|
|
if (!aWorkerPrivate->AddHolder(this)) {
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|