From 55e4b89f1482a885da2bec1d10e27dcaaf0b432e Mon Sep 17 00:00:00 2001 From: fengjiayi Date: Sat, 31 Mar 2018 01:36:25 +0800 Subject: [PATCH] remove local_buffer_ --- .../reader/create_double_buffer_reader_op.cc | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/paddle/fluid/operators/reader/create_double_buffer_reader_op.cc b/paddle/fluid/operators/reader/create_double_buffer_reader_op.cc index 1b7df87b3..788f7582a 100644 --- a/paddle/fluid/operators/reader/create_double_buffer_reader_op.cc +++ b/paddle/fluid/operators/reader/create_double_buffer_reader_op.cc @@ -73,7 +73,6 @@ class DoubleBufferReader : public framework::DecoratedReader { framework::Channel* buffer_; platform::Place place_; std::vector> ctxs_; - mutable Item local_buffer_; }; class CreateDoubleBufferReaderOp : public framework::OperatorBase { @@ -128,12 +127,9 @@ class CreateDoubleBufferReaderOpMaker : public DecoratedReaderMakerBase { }; bool DoubleBufferReader::HasNext() const { - if (local_buffer_.payloads_.empty()) { - bool ok = buffer_->Receive(&local_buffer_); - return ok; - } else { - return true; + while (!buffer_->IsClosed() && !buffer_->CanReceive()) { } + return buffer_->CanReceive() } void DoubleBufferReader::ReadNext(std::vector* out) { @@ -141,10 +137,11 @@ void DoubleBufferReader::ReadNext(std::vector* out) { PADDLE_THROW("There is no next data!"); } - *out = local_buffer_.payloads_; - local_buffer_.payloads_.clear(); - if (local_buffer_.ctx_) { - local_buffer_.ctx_->Wait(); + Item batch; + buffer_->Receive(&batch); + *out = batch.payload_; + if (batch.ctx_) { + batch.ctx_->Wait(); } } -- GitLab