/src/mozilla-central/xpcom/threads/nsILabelableRunnable.cpp
Line | Count | Source (jump to first uncovered line) |
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 "nsILabelableRunnable.h" |
8 | | |
9 | | #include "mozilla/Scheduler.h" |
10 | | #include "mozilla/SchedulerGroup.h" |
11 | | |
12 | | bool |
13 | | nsILabelableRunnable::IsReadyToRun() |
14 | 0 | { |
15 | 0 | MOZ_ASSERT(mozilla::Scheduler::AnyEventRunning()); |
16 | 0 | MOZ_ASSERT(!mozilla::Scheduler::UnlabeledEventRunning()); |
17 | 0 | SchedulerGroupSet groups; |
18 | 0 | if (!GetAffectedSchedulerGroups(groups)) { |
19 | 0 | // it can not be labeled right now. |
20 | 0 | return false; |
21 | 0 | } |
22 | 0 | |
23 | 0 | if (groups.mSingle) { |
24 | 0 | MOZ_ASSERT(groups.mMulti.isNothing()); |
25 | 0 | return !groups.mSingle->IsRunning(); |
26 | 0 | } |
27 | 0 |
|
28 | 0 | if (groups.mMulti.isSome()) { |
29 | 0 | MOZ_ASSERT(!groups.mSingle); |
30 | 0 | for (auto iter = groups.mMulti.ref().ConstIter(); !iter.Done(); iter.Next()) { |
31 | 0 | if (iter.Get()->GetKey()->IsRunning()) { |
32 | 0 | return false; |
33 | 0 | } |
34 | 0 | } |
35 | 0 | return true; |
36 | 0 | } |
37 | 0 | |
38 | 0 | // No affected groups if we are here. Then, it's ready to run. |
39 | 0 | return true; |
40 | 0 | } |
41 | | |
42 | | void |
43 | | nsILabelableRunnable::SchedulerGroupSet::Put(mozilla::SchedulerGroup* aGroup) |
44 | 0 | { |
45 | 0 | if (mSingle) { |
46 | 0 | MOZ_ASSERT(mMulti.isNothing()); |
47 | 0 | mMulti.emplace(); |
48 | 0 | auto& multi = mMulti.ref(); |
49 | 0 | multi.PutEntry(mSingle); |
50 | 0 | multi.PutEntry(aGroup); |
51 | 0 | mSingle = nullptr; |
52 | 0 | return; |
53 | 0 | } |
54 | 0 |
|
55 | 0 | if (mMulti.isSome()) { |
56 | 0 | MOZ_ASSERT(!mSingle); |
57 | 0 | mMulti.ref().PutEntry(aGroup); |
58 | 0 | return; |
59 | 0 | } |
60 | 0 |
|
61 | 0 | mSingle = aGroup; |
62 | 0 | } |
63 | | |
64 | | void |
65 | | nsILabelableRunnable::SchedulerGroupSet::Clear() |
66 | 0 | { |
67 | 0 | mSingle = nullptr; |
68 | 0 | mMulti.reset(); |
69 | 0 | } |
70 | | |
71 | | void |
72 | | nsILabelableRunnable::SchedulerGroupSet::SetIsRunning(bool aIsRunning) |
73 | 0 | { |
74 | 0 | if (mSingle) { |
75 | 0 | MOZ_ASSERT(mMulti.isNothing()); |
76 | 0 | mSingle->SetIsRunning(aIsRunning); |
77 | 0 | return; |
78 | 0 | } |
79 | 0 |
|
80 | 0 | if (mMulti.isSome()) { |
81 | 0 | MOZ_ASSERT(!mSingle); |
82 | 0 | for (auto iter = mMulti.ref().ConstIter(); !iter.Done(); iter.Next()) { |
83 | 0 | MOZ_ASSERT(iter.Get()->GetKey()->IsRunning() != aIsRunning); |
84 | 0 | iter.Get()->GetKey()->SetIsRunning(aIsRunning); |
85 | 0 | } |
86 | 0 | return; |
87 | 0 | } |
88 | 0 | } |