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 file,
5 : * You can obtain one at http://mozilla.org/MPL/2.0/. */
6 :
7 : #include "SystemGroup.h"
8 :
9 : #include "mozilla/Move.h"
10 : #include "mozilla/UniquePtr.h"
11 : #include "nsINamed.h"
12 :
13 : using namespace mozilla;
14 :
15 : class SystemGroupImpl final : public SchedulerGroup
16 : {
17 : public:
18 : SystemGroupImpl();
19 0 : ~SystemGroupImpl() {}
20 :
21 : static void InitStatic();
22 : static void ShutdownStatic();
23 : static SystemGroupImpl* Get();
24 :
25 299 : static bool Initialized() { return !!sSingleton; }
26 :
27 39 : NS_METHOD_(MozExternalRefCountType) AddRef(void)
28 : {
29 39 : return 2;
30 : }
31 12 : NS_METHOD_(MozExternalRefCountType) Release(void)
32 : {
33 12 : return 1;
34 : }
35 :
36 : private:
37 : static UniquePtr<SystemGroupImpl> sSingleton;
38 : };
39 :
40 3 : UniquePtr<SystemGroupImpl> SystemGroupImpl::sSingleton;
41 :
42 3 : SystemGroupImpl::SystemGroupImpl()
43 : {
44 3 : CreateEventTargets(/* aNeedValidation = */ true);
45 3 : }
46 :
47 : /* static */ void
48 3 : SystemGroupImpl::InitStatic()
49 : {
50 3 : MOZ_ASSERT(!sSingleton);
51 3 : MOZ_ASSERT(NS_IsMainThread());
52 3 : sSingleton = MakeUnique<SystemGroupImpl>();
53 3 : }
54 :
55 : /* static */ void
56 0 : SystemGroupImpl::ShutdownStatic()
57 : {
58 0 : sSingleton->Shutdown(true);
59 0 : sSingleton = nullptr;
60 0 : }
61 :
62 : /* static */ SystemGroupImpl*
63 82 : SystemGroupImpl::Get()
64 : {
65 82 : MOZ_ASSERT(sSingleton);
66 82 : return sSingleton.get();
67 : }
68 :
69 : void
70 3 : SystemGroup::InitStatic()
71 : {
72 3 : SystemGroupImpl::InitStatic();
73 3 : }
74 :
75 : void
76 0 : SystemGroup::Shutdown()
77 : {
78 0 : SystemGroupImpl::ShutdownStatic();
79 0 : }
80 :
81 : bool
82 299 : SystemGroup::Initialized()
83 : {
84 299 : return SystemGroupImpl::Initialized();
85 : }
86 :
87 : /* static */ nsresult
88 6 : SystemGroup::Dispatch(const char* aName,
89 : TaskCategory aCategory,
90 : already_AddRefed<nsIRunnable>&& aRunnable)
91 : {
92 6 : return SystemGroupImpl::Get()->Dispatch(aName, aCategory, Move(aRunnable));
93 : }
94 :
95 : /* static */ nsISerialEventTarget*
96 75 : SystemGroup::EventTargetFor(TaskCategory aCategory)
97 : {
98 75 : return SystemGroupImpl::Get()->EventTargetFor(aCategory);
99 : }
100 :
101 : /* static */ AbstractThread*
102 1 : SystemGroup::AbstractMainThreadFor(TaskCategory aCategory)
103 : {
104 1 : return SystemGroupImpl::Get()->AbstractMainThreadFor(aCategory);
105 : }
|