From af64f39bfd2ba99c2bba36926c5b45c4f2015609 Mon Sep 17 00:00:00 2001 From: fengjiayi Date: Wed, 7 Mar 2018 11:11:30 +0800 Subject: [PATCH] fix compile errors --- paddle/fluid/framework/reader.cc | 12 +++++++----- paddle/fluid/framework/reader.h | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/paddle/fluid/framework/reader.cc b/paddle/fluid/framework/reader.cc index 9cdce11d375..bd915ab8bbe 100644 --- a/paddle/fluid/framework/reader.cc +++ b/paddle/fluid/framework/reader.cc @@ -120,11 +120,13 @@ void DoubleBufferReader::ReadNext(std::vector* out) { } out->clear(); - out->resize(buffer_[read_pos_].size()); + out->reserve(buffer_[read_pos_].size()); // TODO(fengjiayi): This copy shall be reduced. for (size_t i = 0; i < buffer_[read_pos_].size(); ++i) { - TensorCopy(buffer_[read_pos_][i], platform::CPUPlace(), &out[i]); - out[i].set_lod(buffer_[read_pos_][i].lod()); + LoDTensor dst; + TensorCopy(buffer_[read_pos_][i], platform::CPUPlace(), &dst); + dst.set_lod(buffer_[read_pos_][i].lod()); + out->push_back(dst); } ++read_pos_; @@ -134,13 +136,13 @@ void DoubleBufferReader::ReadNext(std::vector* out) { buffer_not_full_.notify_all(); } -bool DoubleBufferReader::HasNext() { +bool DoubleBufferReader::HasNext() const { return reader_->HasNext() || !buffer_.empty(); } void DoubleBufferReader::ProducerThreadFunc() { while (reader_->HasNext()) { - std::unique_lock lck(mtx); + std::unique_lock lck(mtx_); while (((write_pos_ + 1) % kDoubleBufferSize) == read_pos_) { buffer_not_full_.wait(lck); } diff --git a/paddle/fluid/framework/reader.h b/paddle/fluid/framework/reader.h index 917412ce9b2..f237dd4f3cd 100644 --- a/paddle/fluid/framework/reader.h +++ b/paddle/fluid/framework/reader.h @@ -140,7 +140,7 @@ class BatchReader : public DecoratedReader { class DoubleBufferReader : public DecoratedReader { public: - DoubleBufferReader(ReaderBase* reader) + explicit DoubleBufferReader(ReaderBase* reader) : DecoratedReader(reader), buffer_(kDoubleBufferSize) { framework::Async(std::bind(&DoubleBufferReader::ProducerThreadFunc, this)); } -- GitLab