Remove old ThreadPool::Schedule (#1139)
parent
21c428b1bf
commit
3ca6506bc7
|
@ -53,12 +53,6 @@ void ThreadPoolForTesting::NotifyDependenciesCompleted(Task* task) {
|
||||||
tasks_not_ready_.erase(it);
|
tasks_not_ready_.erase(it);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ThreadPoolForTesting::Schedule(const std::function<void()>& work_item) {
|
|
||||||
auto task = common::make_unique<Task>();
|
|
||||||
task->SetWorkItem(work_item);
|
|
||||||
Schedule(std::move(task));
|
|
||||||
}
|
|
||||||
|
|
||||||
std::weak_ptr<Task> ThreadPoolForTesting::Schedule(std::unique_ptr<Task> task) {
|
std::weak_ptr<Task> ThreadPoolForTesting::Schedule(std::unique_ptr<Task> task) {
|
||||||
std::shared_ptr<Task> shared_task;
|
std::shared_ptr<Task> shared_task;
|
||||||
{
|
{
|
||||||
|
|
|
@ -34,18 +34,18 @@ class ThreadPoolForTesting : public ThreadPoolInterface {
|
||||||
ThreadPoolForTesting();
|
ThreadPoolForTesting();
|
||||||
~ThreadPoolForTesting();
|
~ThreadPoolForTesting();
|
||||||
|
|
||||||
void NotifyDependenciesCompleted(Task* task) EXCLUDES(mutex_) override;
|
|
||||||
|
|
||||||
void Schedule(const std::function<void()>& work_item) override;
|
|
||||||
|
|
||||||
std::weak_ptr<Task> Schedule(std::unique_ptr<Task> task)
|
std::weak_ptr<Task> Schedule(std::unique_ptr<Task> task)
|
||||||
EXCLUDES(mutex_) override;
|
EXCLUDES(mutex_) override;
|
||||||
|
|
||||||
void WaitUntilIdle();
|
void WaitUntilIdle();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
friend class Task;
|
||||||
|
|
||||||
void DoWork();
|
void DoWork();
|
||||||
|
|
||||||
|
void NotifyDependenciesCompleted(Task* task) EXCLUDES(mutex_) override;
|
||||||
|
|
||||||
Mutex mutex_;
|
Mutex mutex_;
|
||||||
bool running_ GUARDED_BY(mutex_) = true;
|
bool running_ GUARDED_BY(mutex_) = true;
|
||||||
bool idle_ GUARDED_BY(mutex_) = true;
|
bool idle_ GUARDED_BY(mutex_) = true;
|
||||||
|
|
|
@ -41,10 +41,6 @@ class FakeThreadPool : public ThreadPoolInterface {
|
||||||
tasks_not_ready_.erase(it);
|
tasks_not_ready_.erase(it);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Schedule(const std::function<void()>& work_item) override {
|
|
||||||
LOG(FATAL) << "not implemented";
|
|
||||||
}
|
|
||||||
|
|
||||||
std::weak_ptr<Task> Schedule(std::unique_ptr<Task> task) override {
|
std::weak_ptr<Task> Schedule(std::unique_ptr<Task> task) override {
|
||||||
std::shared_ptr<Task> shared_task;
|
std::shared_ptr<Task> shared_task;
|
||||||
auto it =
|
auto it =
|
||||||
|
|
|
@ -63,12 +63,6 @@ void ThreadPool::NotifyDependenciesCompleted(Task* task) {
|
||||||
tasks_not_ready_.erase(it);
|
tasks_not_ready_.erase(it);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ThreadPool::Schedule(const std::function<void()>& work_item) {
|
|
||||||
auto task = make_unique<Task>();
|
|
||||||
task->SetWorkItem(work_item);
|
|
||||||
Schedule(std::move(task));
|
|
||||||
}
|
|
||||||
|
|
||||||
std::weak_ptr<Task> ThreadPool::Schedule(std::unique_ptr<Task> task) {
|
std::weak_ptr<Task> ThreadPool::Schedule(std::unique_ptr<Task> task) {
|
||||||
std::shared_ptr<Task> shared_task;
|
std::shared_ptr<Task> shared_task;
|
||||||
{
|
{
|
||||||
|
|
|
@ -36,8 +36,6 @@ class ThreadPoolInterface {
|
||||||
public:
|
public:
|
||||||
ThreadPoolInterface() {}
|
ThreadPoolInterface() {}
|
||||||
virtual ~ThreadPoolInterface() {}
|
virtual ~ThreadPoolInterface() {}
|
||||||
// TODO(gaschler): Use Schedule(unique_ptr<Task>), then remove Schedule.
|
|
||||||
virtual void Schedule(const std::function<void()>& work_item) = 0;
|
|
||||||
virtual std::weak_ptr<Task> Schedule(std::unique_ptr<Task> task) = 0;
|
virtual std::weak_ptr<Task> Schedule(std::unique_ptr<Task> task) = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -64,9 +62,6 @@ class ThreadPool : public ThreadPoolInterface {
|
||||||
ThreadPool(const ThreadPool&) = delete;
|
ThreadPool(const ThreadPool&) = delete;
|
||||||
ThreadPool& operator=(const ThreadPool&) = delete;
|
ThreadPool& operator=(const ThreadPool&) = delete;
|
||||||
|
|
||||||
// TODO(gaschler): Remove all uses.
|
|
||||||
void Schedule(const std::function<void()>& work_item) override;
|
|
||||||
|
|
||||||
// When the returned weak pointer is expired, 'task' has certainly completed,
|
// When the returned weak pointer is expired, 'task' has certainly completed,
|
||||||
// so dependants no longer need to add it as a dependency.
|
// so dependants no longer need to add it as a dependency.
|
||||||
std::weak_ptr<Task> Schedule(std::unique_ptr<Task> task)
|
std::weak_ptr<Task> Schedule(std::unique_ptr<Task> task)
|
||||||
|
|
Loading…
Reference in New Issue