提交 af64f39b 编写于 作者: F fengjiayi

fix compile errors

上级 3fcd16ed
...@@ -120,11 +120,13 @@ void DoubleBufferReader::ReadNext(std::vector<LoDTensor>* out) { ...@@ -120,11 +120,13 @@ void DoubleBufferReader::ReadNext(std::vector<LoDTensor>* out) {
} }
out->clear(); out->clear();
out->resize(buffer_[read_pos_].size()); out->reserve(buffer_[read_pos_].size());
// TODO(fengjiayi): This copy shall be reduced. // TODO(fengjiayi): This copy shall be reduced.
for (size_t i = 0; i < buffer_[read_pos_].size(); ++i) { for (size_t i = 0; i < buffer_[read_pos_].size(); ++i) {
TensorCopy(buffer_[read_pos_][i], platform::CPUPlace(), &out[i]); LoDTensor dst;
out[i].set_lod(buffer_[read_pos_][i].lod()); TensorCopy(buffer_[read_pos_][i], platform::CPUPlace(), &dst);
dst.set_lod(buffer_[read_pos_][i].lod());
out->push_back(dst);
} }
++read_pos_; ++read_pos_;
...@@ -134,13 +136,13 @@ void DoubleBufferReader::ReadNext(std::vector<LoDTensor>* out) { ...@@ -134,13 +136,13 @@ void DoubleBufferReader::ReadNext(std::vector<LoDTensor>* out) {
buffer_not_full_.notify_all(); buffer_not_full_.notify_all();
} }
bool DoubleBufferReader::HasNext() { bool DoubleBufferReader::HasNext() const {
return reader_->HasNext() || !buffer_.empty(); return reader_->HasNext() || !buffer_.empty();
} }
void DoubleBufferReader::ProducerThreadFunc() { void DoubleBufferReader::ProducerThreadFunc() {
while (reader_->HasNext()) { while (reader_->HasNext()) {
std::unique_lock<std::mutex> lck(mtx); std::unique_lock<std::mutex> lck(mtx_);
while (((write_pos_ + 1) % kDoubleBufferSize) == read_pos_) { while (((write_pos_ + 1) % kDoubleBufferSize) == read_pos_) {
buffer_not_full_.wait(lck); buffer_not_full_.wait(lck);
} }
......
...@@ -140,7 +140,7 @@ class BatchReader : public DecoratedReader { ...@@ -140,7 +140,7 @@ class BatchReader : public DecoratedReader {
class DoubleBufferReader : public DecoratedReader { class DoubleBufferReader : public DecoratedReader {
public: public:
DoubleBufferReader(ReaderBase* reader) explicit DoubleBufferReader(ReaderBase* reader)
: DecoratedReader(reader), buffer_(kDoubleBufferSize) { : DecoratedReader(reader), buffer_(kDoubleBufferSize) {
framework::Async(std::bind(&DoubleBufferReader::ProducerThreadFunc, this)); framework::Async(std::bind(&DoubleBufferReader::ProducerThreadFunc, this));
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册