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 1b7df87b355ae2c1168125f3ff7955316204eb5b..788f7582aebdce65f56d5270943e6e62f720b744 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(); } }