v8/test/unittests/heap/cppgc/test-platform.cc

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

48 lines
1.5 KiB
C++
Raw Normal View History

// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "test/unittests/heap/cppgc/test-platform.h"
#include "include/libplatform/libplatform.h"
#include "src/base/platform/platform.h"
#include "src/base/platform/time.h"
namespace cppgc {
namespace internal {
namespace testing {
TestPlatform::TestPlatform(
std::unique_ptr<v8::TracingController> tracing_controller)
: DefaultPlatform(0 /* thread_pool_size */, IdleTaskSupport::kEnabled,
std::move(tracing_controller)) {}
Reland "cppgc: Provide jobs support through DefaultPlatform and TestPlatform" This reverts commit 2221f0909b4aff18a6dc51f694d877122001aed0. Reason for revert: fix in patchset 2 Original change's description: > Revert "cppgc: Provide jobs support through DefaultPlatform and TestPlatform" > > This reverts commit 22c0fc8f2ed93e911351b652674c488c02454f3d. > > Reason for revert: https://ci.chromium.org/p/v8/builders/ci/V8%20Linux%20gcc/8712? > > Original change's description: > > cppgc: Provide jobs support through DefaultPlatform and TestPlatform > > > > This CL extends cppgc::DefaultPlatform and TestPlatform to emulate > > jobs using std::thread and v8::base::Thread respectively. > > Jobs using these platform do not yield unless the job as been > > cancelled. Additionally, the job priority is ignored. > > > > Bug: chromium:1056170 > > Change-Id: I72db1eef410d2be3d3e5ea7d4ece9e5584a451f2 > > Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2416378 > > Commit-Queue: Omer Katz <omerkatz@chromium.org> > > Reviewed-by: Anton Bikineev <bikineev@chromium.org> > > Reviewed-by: Michael Lippautz <mlippautz@chromium.org> > > Cr-Commit-Position: refs/heads/master@{#70139} > > TBR=mlippautz@chromium.org,bikineev@chromium.org,omerkatz@chromium.org > > Change-Id: Ic29235e3ab78a1b515a5b14b808e116a1ccffc0f > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: chromium:1056170 > Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2432087 > Reviewed-by: Francis McCabe <fgm@chromium.org> > Commit-Queue: Francis McCabe <fgm@chromium.org> > Cr-Commit-Position: refs/heads/master@{#70142} # Not skipping CQ checks because this is a reland. Bug: chromium:1056170 Change-Id: Iaa8312da759ab97f646a9fb6144462a115393b5f Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2431666 Reviewed-by: Anton Bikineev <bikineev@chromium.org> Reviewed-by: Michael Lippautz <mlippautz@chromium.org> Commit-Queue: Omer Katz <omerkatz@chromium.org> Cr-Commit-Position: refs/heads/master@{#70150}
2020-09-25 18:04:34 +00:00
std::unique_ptr<cppgc::JobHandle> TestPlatform::PostJob(
cppgc::TaskPriority priority, std::unique_ptr<cppgc::JobTask> job_task) {
if (AreBackgroundTasksDisabled()) return nullptr;
return v8_platform_->PostJob(priority, std::move(job_task));
}
void TestPlatform::RunAllForegroundTasks() {
v8::platform::PumpMessageLoop(v8_platform_.get(), kNoIsolate);
if (GetForegroundTaskRunner()->IdleTasksEnabled()) {
v8::platform::RunIdleTasks(v8_platform_.get(), kNoIsolate,
std::numeric_limits<double>::max());
}
}
TestPlatform::DisableBackgroundTasksScope::DisableBackgroundTasksScope(
TestPlatform* platform)
: platform_(platform) {
++platform_->disabled_background_tasks_;
}
TestPlatform::DisableBackgroundTasksScope::~DisableBackgroundTasksScope()
V8_NOEXCEPT {
--platform_->disabled_background_tasks_;
}
} // namespace testing
} // namespace internal
} // namespace cppgc