Remove unused WorkStealing thread pool
Bug: 10141986
Change-Id: Id2042320afc91b34b6203e82fb56424281c8d64b
diff --git a/runtime/thread_pool.cc b/runtime/thread_pool.cc
index 1e84c9d..d8f80fa 100644
--- a/runtime/thread_pool.cc
+++ b/runtime/thread_pool.cc
@@ -201,112 +201,4 @@
return tasks_.size();
}
-WorkStealingWorker::WorkStealingWorker(ThreadPool* thread_pool, const std::string& name,
- size_t stack_size)
- : ThreadPoolWorker(thread_pool, name, stack_size), task_(nullptr) {}
-
-void WorkStealingWorker::Run() {
- Thread* self = Thread::Current();
- Task* task = nullptr;
- WorkStealingThreadPool* thread_pool = down_cast<WorkStealingThreadPool*>(thread_pool_);
- while ((task = thread_pool_->GetTask(self)) != nullptr) {
- WorkStealingTask* stealing_task = down_cast<WorkStealingTask*>(task);
-
- {
- CHECK(task_ == nullptr);
- MutexLock mu(self, thread_pool->work_steal_lock_);
- // Register that we are running the task
- ++stealing_task->ref_count_;
- task_ = stealing_task;
- }
- stealing_task->Run(self);
- // Mark ourselves as not running a task so that nobody tries to steal from us.
- // There is a race condition that someone starts stealing from us at this point. This is okay
- // due to the reference counting.
- task_ = nullptr;
-
- bool finalize;
-
- // Steal work from tasks until there is none left to steal. Note: There is a race, but
- // all that happens when the race occurs is that we steal some work instead of processing a
- // task from the queue.
- while (thread_pool->GetTaskCount(self) == 0) {
- WorkStealingTask* steal_from_task = nullptr;
-
- {
- MutexLock mu(self, thread_pool->work_steal_lock_);
- // Try finding a task to steal from.
- steal_from_task = thread_pool->FindTaskToStealFrom();
- if (steal_from_task != nullptr) {
- CHECK_NE(stealing_task, steal_from_task)
- << "Attempting to steal from completed self task";
- steal_from_task->ref_count_++;
- } else {
- break;
- }
- }
-
- if (steal_from_task != nullptr) {
- // Task which completed earlier is going to steal some work.
- stealing_task->StealFrom(self, steal_from_task);
-
- {
- // We are done stealing from the task, lets decrement its reference count.
- MutexLock mu(self, thread_pool->work_steal_lock_);
- finalize = !--steal_from_task->ref_count_;
- }
-
- if (finalize) {
- steal_from_task->Finalize();
- }
- }
- }
-
- {
- MutexLock mu(self, thread_pool->work_steal_lock_);
- // If nobody is still referencing task_ we can finalize it.
- finalize = !--stealing_task->ref_count_;
- }
-
- if (finalize) {
- stealing_task->Finalize();
- }
- }
-}
-
-WorkStealingWorker::~WorkStealingWorker() {}
-
-WorkStealingThreadPool::WorkStealingThreadPool(const char* name, size_t num_threads)
- : ThreadPool(name, 0),
- work_steal_lock_("work stealing lock"),
- steal_index_(0) {
- while (GetThreadCount() < num_threads) {
- const std::string worker_name = StringPrintf("Work stealing worker %zu", GetThreadCount());
- threads_.push_back(new WorkStealingWorker(this, worker_name,
- ThreadPoolWorker::kDefaultStackSize));
- }
-}
-
-WorkStealingTask* WorkStealingThreadPool::FindTaskToStealFrom() {
- const size_t thread_count = GetThreadCount();
- for (size_t i = 0; i < thread_count; ++i) {
- // TODO: Use CAS instead of lock.
- ++steal_index_;
- if (steal_index_ >= thread_count) {
- steal_index_-= thread_count;
- }
-
- WorkStealingWorker* worker = down_cast<WorkStealingWorker*>(threads_[steal_index_]);
- WorkStealingTask* task = worker->task_;
- if (task) {
- // Not null, we can probably steal from this worker.
- return task;
- }
- }
- // Couldn't find something to steal.
- return nullptr;
-}
-
-WorkStealingThreadPool::~WorkStealingThreadPool() {}
-
} // namespace art
diff --git a/runtime/thread_pool.h b/runtime/thread_pool.h
index 0557708..88700e6 100644
--- a/runtime/thread_pool.h
+++ b/runtime/thread_pool.h
@@ -144,58 +144,6 @@
DISALLOW_COPY_AND_ASSIGN(ThreadPool);
};
-class WorkStealingTask : public Task {
- public:
- WorkStealingTask() : ref_count_(0) {}
-
- size_t GetRefCount() const {
- return ref_count_;
- }
-
- virtual void StealFrom(Thread* self, WorkStealingTask* source) = 0;
-
- private:
- // How many people are referencing this task.
- size_t ref_count_;
-
- friend class WorkStealingWorker;
-};
-
-class WorkStealingWorker : public ThreadPoolWorker {
- public:
- virtual ~WorkStealingWorker();
-
- bool IsRunningTask() const {
- return task_ != nullptr;
- }
-
- protected:
- WorkStealingTask* task_;
-
- WorkStealingWorker(ThreadPool* thread_pool, const std::string& name, size_t stack_size);
- virtual void Run();
-
- private:
- friend class WorkStealingThreadPool;
- DISALLOW_COPY_AND_ASSIGN(WorkStealingWorker);
-};
-
-class WorkStealingThreadPool : public ThreadPool {
- public:
- explicit WorkStealingThreadPool(const char* name, size_t num_threads);
- virtual ~WorkStealingThreadPool();
-
- private:
- Mutex work_steal_lock_;
- // Which thread we are stealing from (round robin).
- size_t steal_index_;
-
- // Find a task to steal from
- WorkStealingTask* FindTaskToStealFrom() EXCLUSIVE_LOCKS_REQUIRED(work_steal_lock_);
-
- friend class WorkStealingWorker;
-};
-
} // namespace art
#endif // ART_RUNTIME_THREAD_POOL_H_