Commit 37f15b89 authored by Peter Marshall's avatar Peter Marshall Committed by Commit Bot

[cleanup] Remove unused RunsTasksOnCurrentThread on task runner

This was needed for Perfetto at one point but now this is all handled
internally by the Perfetto Client API. The implementation was
potentially wrong as on some platforms we truncate the the thread ID
https://chromium-review.googlesource.com/c/v8/v8/+/1720821/1/src/base/platform/platform-posix.cc#528

Change-Id: I5124f4fb0df4d29ff78ab6c7a2c2b0c9a66a2af3
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1981508Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Commit-Queue: Peter Marshall <petermarshall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#65576}
parent 234da719
......@@ -11,9 +11,7 @@ namespace platform {
DefaultWorkerThreadsTaskRunner::DefaultWorkerThreadsTaskRunner(
uint32_t thread_pool_size, TimeFunction time_function)
: queue_(time_function),
time_function_(time_function),
thread_pool_size_(thread_pool_size) {
: queue_(time_function), time_function_(time_function) {
for (uint32_t i = 0; i < thread_pool_size; ++i) {
thread_pool_.push_back(std::make_unique<WorkerThread>(this));
}
......@@ -25,20 +23,12 @@ double DefaultWorkerThreadsTaskRunner::MonotonicallyIncreasingTime() {
return time_function_();
}
bool DefaultWorkerThreadsTaskRunner::RunsTasksOnCurrentThread() const {
USE(thread_pool_size_);
DCHECK_EQ(thread_pool_size_, 1);
return single_worker_thread_id_.load(std::memory_order_relaxed) ==
base::OS::GetCurrentThreadId();
}
void DefaultWorkerThreadsTaskRunner::Terminate() {
base::MutexGuard guard(&lock_);
terminated_ = true;
queue_.Terminate();
// Clearing the thread pool lets all worker threads join.
thread_pool_.clear();
single_worker_thread_id_.store(0, std::memory_order_relaxed);
}
void DefaultWorkerThreadsTaskRunner::PostTask(std::unique_ptr<Task> task) {
......@@ -79,8 +69,6 @@ DefaultWorkerThreadsTaskRunner::WorkerThread::WorkerThread(
DefaultWorkerThreadsTaskRunner::WorkerThread::~WorkerThread() { Join(); }
void DefaultWorkerThreadsTaskRunner::WorkerThread::Run() {
runner_->single_worker_thread_id_.store(base::OS::GetCurrentThreadId(),
std::memory_order_relaxed);
while (std::unique_ptr<Task> task = runner_->GetNext()) {
task->Run();
}
......
......@@ -31,10 +31,6 @@ class V8_PLATFORM_EXPORT DefaultWorkerThreadsTaskRunner
double MonotonicallyIncreasingTime();
// It is only valid to call this method on a task runner with a single worker
// thread. True if the current thread is the worker thread.
bool RunsTasksOnCurrentThread() const;
// v8::TaskRunner implementation.
void PostTask(std::unique_ptr<Task> task) override;
......@@ -69,8 +65,6 @@ class V8_PLATFORM_EXPORT DefaultWorkerThreadsTaskRunner
DelayedTaskQueue queue_;
std::vector<std::unique_ptr<WorkerThread>> thread_pool_;
TimeFunction time_function_;
std::atomic_int single_worker_thread_id_{0};
uint32_t thread_pool_size_;
};
} // namespace platform
......
......@@ -274,25 +274,5 @@ TEST(DefaultWorkerThreadsTaskRunnerUnittest, NoIdleTasks) {
runner.Terminate();
}
TEST(DefaultWorkerThreadsTaskRunnerUnittest, RunsTasksOnCurrentThread) {
DefaultWorkerThreadsTaskRunner runner(1, RealTime);
base::Semaphore semaphore(0);
EXPECT_FALSE(runner.RunsTasksOnCurrentThread());
std::unique_ptr<TestTask> task1 = std::make_unique<TestTask>([&] {
EXPECT_TRUE(runner.RunsTasksOnCurrentThread());
semaphore.Signal();
});
runner.PostTask(std::move(task1));
semaphore.Wait();
EXPECT_FALSE(runner.RunsTasksOnCurrentThread());
runner.Terminate();
EXPECT_FALSE(runner.RunsTasksOnCurrentThread());
}
} // namespace platform
} // namespace v8
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