зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1332494 - Add SystemGroup class similar to TabGroup/DocGroup (r=froydnj)
MozReview-Commit-ID: ApxMkd5zEQ5
This commit is contained in:
Родитель
4df03bc275
Коммит
9c91994cbc
|
@ -0,0 +1,38 @@
|
|||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "SystemGroup.h"
|
||||
|
||||
#include "mozilla/Move.h"
|
||||
#include "nsINamed.h"
|
||||
|
||||
using namespace mozilla;
|
||||
|
||||
/* static */ nsresult
|
||||
SystemGroup::Dispatch(const char* aName,
|
||||
TaskCategory aCategory,
|
||||
already_AddRefed<nsIRunnable>&& aRunnable)
|
||||
{
|
||||
nsCOMPtr<nsIRunnable> runnable(aRunnable);
|
||||
if (aName) {
|
||||
if (nsCOMPtr<nsINamed> named = do_QueryInterface(runnable)) {
|
||||
named->SetName(aName);
|
||||
}
|
||||
}
|
||||
if (NS_IsMainThread()) {
|
||||
return NS_DispatchToCurrentThread(runnable.forget());
|
||||
} else {
|
||||
return NS_DispatchToMainThread(runnable.forget());
|
||||
}
|
||||
}
|
||||
|
||||
/* static */ nsIEventTarget*
|
||||
SystemGroup::EventTargetFor(TaskCategory aCategory)
|
||||
{
|
||||
nsCOMPtr<nsIEventTarget> main = do_GetMainThread();
|
||||
return main;
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#ifndef mozilla_SystemGroup_h
|
||||
#define mozilla_SystemGroup_h
|
||||
|
||||
#include "mozilla/TaskCategory.h"
|
||||
|
||||
// The SystemGroup should be used for dispatching runnables that don't need to
|
||||
// touch web content. Runnables dispatched to the SystemGroup are run in order
|
||||
// relative to each other, but their order relative to other runnables is
|
||||
// undefined.
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
class SystemGroup {
|
||||
public:
|
||||
// This method is safe to use from any thread.
|
||||
static nsresult Dispatch(const char* aName,
|
||||
TaskCategory aCategory,
|
||||
already_AddRefed<nsIRunnable>&& aRunnable);
|
||||
|
||||
// This method is safe to use from any thread.
|
||||
static nsIEventTarget* EventTargetFor(TaskCategory aCategory);
|
||||
};
|
||||
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // mozilla_SystemGroup_h
|
||||
|
|
@ -51,6 +51,7 @@ EXPORTS.mozilla += [
|
|||
'StateMirroring.h',
|
||||
'StateWatching.h',
|
||||
'SyncRunnable.h',
|
||||
'SystemGroup.h',
|
||||
'TaskCategory.h',
|
||||
'TaskDispatcher.h',
|
||||
'TaskQueue.h',
|
||||
|
@ -76,6 +77,7 @@ UNIFIED_SOURCES += [
|
|||
'nsThreadUtils.cpp',
|
||||
'nsTimerImpl.cpp',
|
||||
'SharedThreadPool.cpp',
|
||||
'SystemGroup.cpp',
|
||||
'TaskQueue.cpp',
|
||||
'ThreadStackHelper.cpp',
|
||||
'ThrottledEventQueue.cpp',
|
||||
|
|
Загрузка…
Ссылка в новой задаче