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/. */
7 #ifndef mozilla_SchedulerGroup_h
8 #define mozilla_SchedulerGroup_h
10 #include "mozilla/RefPtr.h"
11 #include "mozilla/TaskCategory.h"
12 #include "mozilla/PerformanceCounter.h"
15 #include "nsIRunnable.h"
16 #include "nsISupports.h"
17 #include "nsStringFwd.h"
18 #include "nsThreadUtils.h"
23 class nsISerialEventTarget
;
31 #define NS_SCHEDULERGROUPRUNNABLE_IID \
33 0xd31b7420, 0x872b, 0x4cfb, { \
34 0xa9, 0xc6, 0xae, 0x4c, 0x0f, 0x06, 0x36, 0x74 \
38 class SchedulerGroup
{
42 NS_INLINE_DECL_PURE_VIRTUAL_REFCOUNTING
44 class Runnable final
: public mozilla::Runnable
, public nsIRunnablePriority
{
46 Runnable(already_AddRefed
<nsIRunnable
>&& aRunnable
,
47 mozilla::PerformanceCounter
* aPerformanceCounter
);
49 mozilla::PerformanceCounter
* GetPerformanceCounter() const;
51 #ifdef MOZ_COLLECTING_RUNNABLE_TELEMETRY
52 NS_IMETHOD
GetName(nsACString
& aName
) override
;
55 NS_DECL_ISUPPORTS_INHERITED
57 NS_DECL_NSIRUNNABLEPRIORITY
59 NS_DECLARE_STATIC_IID_ACCESSOR(NS_SCHEDULERGROUPRUNNABLE_IID
);
62 friend class SchedulerGroup
;
64 ~Runnable() = default;
66 nsCOMPtr
<nsIRunnable
> mRunnable
;
67 RefPtr
<mozilla::PerformanceCounter
> mPerformanceCounter
;
69 friend class Runnable
;
71 static nsresult
Dispatch(TaskCategory aCategory
,
72 already_AddRefed
<nsIRunnable
>&& aRunnable
);
74 static nsresult
UnlabeledDispatch(TaskCategory aCategory
,
75 already_AddRefed
<nsIRunnable
>&& aRunnable
);
77 static void MarkVsyncReceived();
79 static void MarkVsyncRan();
81 static nsresult
LabeledDispatch(
82 TaskCategory aCategory
, already_AddRefed
<nsIRunnable
>&& aRunnable
,
83 mozilla::PerformanceCounter
* aPerformanceCounter
);
86 static nsresult
InternalUnlabeledDispatch(
87 TaskCategory aCategory
, already_AddRefed
<Runnable
>&& aRunnable
);
89 // Shuts down this dispatcher. If aXPCOMShutdown is true, invalidates this
91 void Shutdown(bool aXPCOMShutdown
);
95 // Number of events that are currently enqueued for this SchedulerGroup
96 // (across all queues).
97 size_t mEventCount
= 0;
100 NS_DEFINE_STATIC_IID_ACCESSOR(SchedulerGroup::Runnable
,
101 NS_SCHEDULERGROUPRUNNABLE_IID
);
103 } // namespace mozilla
105 #endif // mozilla_SchedulerGroup_h