From 201f79d03985114de6e49adbaad7887fed8939b6 Mon Sep 17 00:00:00 2001 From: Yu Yang Date: Tue, 27 Mar 2018 18:53:54 +0800 Subject: [PATCH] Use Extend method --- .../framework/details/threaded_ssa_graph_executor.cc | 5 +---- .../framework/details/threaded_ssa_graph_executor.h | 11 +++++++++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/paddle/fluid/framework/details/threaded_ssa_graph_executor.cc b/paddle/fluid/framework/details/threaded_ssa_graph_executor.cc index 0bf05c3c112..fc840315562 100644 --- a/paddle/fluid/framework/details/threaded_ssa_graph_executor.cc +++ b/paddle/fluid/framework/details/threaded_ssa_graph_executor.cc @@ -178,10 +178,7 @@ void ThreadedSSAGraphExecutor::RunOp( try { VLOG(10) << op->Name() << " : " << op->DebugString(); op->Run(use_event_); - - for (auto &each : op->outputs_) { - ready_var_q.Push(each); - } + ready_var_q.Extend(op->outputs_); } catch (platform::EnforceNotMet ex) { exception_.reset(new platform::EnforceNotMet(ex)); } catch (...) { diff --git a/paddle/fluid/framework/details/threaded_ssa_graph_executor.h b/paddle/fluid/framework/details/threaded_ssa_graph_executor.h index 26ff1478639..83921703114 100644 --- a/paddle/fluid/framework/details/threaded_ssa_graph_executor.h +++ b/paddle/fluid/framework/details/threaded_ssa_graph_executor.h @@ -35,6 +35,17 @@ class BlockingQueue { cv_.notify_one(); } + template + void Extend(const U &items) { + { + std::lock_guard g(mutex_); + for (auto &item : items) { + q_.emplace_back(item); + } + } + cv_.notify_all(); + } + T Pop() { std::unique_lock lock(mutex_); while (q_.empty()) { -- GitLab