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
{
40 class Runnable final
: public mozilla::Runnable
, public nsIRunnablePriority
{
42 Runnable(already_AddRefed
<nsIRunnable
>&& aRunnable
,
43 mozilla::PerformanceCounter
* aPerformanceCounter
);
45 mozilla::PerformanceCounter
* GetPerformanceCounter() const;
47 #ifdef MOZ_COLLECTING_RUNNABLE_TELEMETRY
48 NS_IMETHOD
GetName(nsACString
& aName
) override
;
51 NS_DECL_ISUPPORTS_INHERITED
53 NS_DECL_NSIRUNNABLEPRIORITY
55 NS_DECLARE_STATIC_IID_ACCESSOR(NS_SCHEDULERGROUPRUNNABLE_IID
);
58 friend class SchedulerGroup
;
60 ~Runnable() = default;
62 nsCOMPtr
<nsIRunnable
> mRunnable
;
63 RefPtr
<mozilla::PerformanceCounter
> mPerformanceCounter
;
65 friend class Runnable
;
67 static nsresult
Dispatch(TaskCategory aCategory
,
68 already_AddRefed
<nsIRunnable
>&& aRunnable
);
70 static nsresult
UnlabeledDispatch(TaskCategory aCategory
,
71 already_AddRefed
<nsIRunnable
>&& aRunnable
);
73 static nsresult
LabeledDispatch(
74 TaskCategory aCategory
, already_AddRefed
<nsIRunnable
>&& aRunnable
,
75 mozilla::PerformanceCounter
* aPerformanceCounter
);
78 static nsresult
InternalUnlabeledDispatch(
79 TaskCategory aCategory
, already_AddRefed
<Runnable
>&& aRunnable
);
82 NS_DEFINE_STATIC_IID_ACCESSOR(SchedulerGroup::Runnable
,
83 NS_SCHEDULERGROUPRUNNABLE_IID
);
85 } // namespace mozilla
87 #endif // mozilla_SchedulerGroup_h