Line data Source code
1 : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* vim: set ts=8 sts=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 :
7 : #include "WorkerHolder.h"
8 : #include "WorkerPrivate.h"
9 :
10 : BEGIN_WORKERS_NAMESPACE
11 :
12 8 : WorkerHolder::WorkerHolder(Behavior aBehavior)
13 : : mWorkerPrivate(nullptr)
14 8 : , mBehavior(aBehavior)
15 : {
16 8 : }
17 :
18 4 : WorkerHolder::~WorkerHolder()
19 : {
20 2 : NS_ASSERT_OWNINGTHREAD(WorkerHolder);
21 2 : ReleaseWorkerInternal();
22 2 : MOZ_ASSERT(mWorkerPrivate == nullptr);
23 2 : }
24 :
25 : bool
26 7 : WorkerHolder::HoldWorker(WorkerPrivate* aWorkerPrivate, Status aFailStatus)
27 : {
28 7 : NS_ASSERT_OWNINGTHREAD(WorkerHolder);
29 7 : MOZ_ASSERT(aWorkerPrivate);
30 7 : aWorkerPrivate->AssertIsOnWorkerThread();
31 :
32 7 : if (!aWorkerPrivate->AddHolder(this, aFailStatus)) {
33 0 : return false;
34 : }
35 :
36 7 : mWorkerPrivate = aWorkerPrivate;
37 7 : return true;
38 : }
39 :
40 : void
41 2 : WorkerHolder::ReleaseWorker()
42 : {
43 2 : NS_ASSERT_OWNINGTHREAD(WorkerHolder);
44 2 : MOZ_ASSERT(mWorkerPrivate);
45 :
46 2 : ReleaseWorkerInternal();
47 2 : }
48 :
49 : WorkerHolder::Behavior
50 11 : WorkerHolder::GetBehavior() const
51 : {
52 11 : return mBehavior;
53 : }
54 :
55 : void
56 4 : WorkerHolder::ReleaseWorkerInternal()
57 : {
58 4 : NS_ASSERT_OWNINGTHREAD(WorkerHolder);
59 :
60 4 : if (mWorkerPrivate) {
61 4 : mWorkerPrivate->AssertIsOnWorkerThread();
62 4 : mWorkerPrivate->RemoveHolder(this);
63 4 : mWorkerPrivate = nullptr;
64 : }
65 4 : }
66 :
67 9 : END_WORKERS_NAMESPACE
|