Commit 3896e617 authored by Andreas Haas's avatar Andreas Haas Committed by Commit Bot

[test] Add TaskRunners to the platform in the compiler dispatcher tests

I just pass a pointer of the platform to the task runner so that the
task runners can put tasks directly into the platform data structures.

R=rmcilroy@chromium.org

Change-Id: I7c1c56c3b9f550c0fe80012abcd31011e69f3d5d
Reviewed-on: https://chromium-review.googlesource.com/771751Reviewed-by: 's avatarRoss McIlroy <rmcilroy@chromium.org>
Commit-Queue: Andreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#49498}
parent 5cf75a1a
...@@ -99,6 +99,18 @@ class MockPlatform : public v8::Platform { ...@@ -99,6 +99,18 @@ class MockPlatform : public v8::Platform {
size_t NumberOfAvailableBackgroundThreads() override { return 1; } size_t NumberOfAvailableBackgroundThreads() override { return 1; }
std::shared_ptr<TaskRunner> GetForegroundTaskRunner(
v8::Isolate* isolate) override {
constexpr bool is_foreground_task_runner = true;
return std::make_shared<MockTaskRunner>(this, is_foreground_task_runner);
}
std::shared_ptr<TaskRunner> GetBackgroundTaskRunner(
v8::Isolate* isolate) override {
constexpr bool is_foreground_task_runner = false;
return std::make_shared<MockTaskRunner>(this, is_foreground_task_runner);
}
void CallOnBackgroundThread(Task* task, void CallOnBackgroundThread(Task* task,
ExpectedRuntime expected_runtime) override { ExpectedRuntime expected_runtime) override {
base::LockGuard<base::Mutex> lock(&mutex_); base::LockGuard<base::Mutex> lock(&mutex_);
...@@ -251,6 +263,43 @@ class MockPlatform : public v8::Platform { ...@@ -251,6 +263,43 @@ class MockPlatform : public v8::Platform {
DISALLOW_COPY_AND_ASSIGN(TaskWrapper); DISALLOW_COPY_AND_ASSIGN(TaskWrapper);
}; };
class MockTaskRunner final : public TaskRunner {
public:
MockTaskRunner(MockPlatform* platform, bool is_foreground_task_runner)
: platform_(platform),
is_foreground_task_runner_(is_foreground_task_runner) {}
void PostTask(std::unique_ptr<v8::Task> task) override {
base::LockGuard<base::Mutex> lock(&platform_->mutex_);
if (is_foreground_task_runner_) {
platform_->foreground_tasks_.push_back(task.release());
} else {
platform_->background_tasks_.push_back(task.release());
}
}
void PostDelayedTask(std::unique_ptr<Task> task,
double delay_in_seconds) override {
UNREACHABLE();
};
void PostIdleTask(std::unique_ptr<IdleTask> task) override {
DCHECK(IdleTasksEnabled());
base::LockGuard<base::Mutex> lock(&platform_->mutex_);
ASSERT_TRUE(platform_->idle_task_ == nullptr);
platform_->idle_task_ = task.release();
}
bool IdleTasksEnabled() override {
// Idle tasks are enabled only in the foreground task runner.
return is_foreground_task_runner_;
};
private:
MockPlatform* platform_;
bool is_foreground_task_runner_;
};
double time_; double time_;
double time_step_; double time_step_;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment