DataReader::DataReader(const LayerParameter& param, bool is_cpm_data) : queue_pair_(new QueuePair(is_cpm_data ? // param.cpmdata_param().prefetch() * param.cpmdata_param().batch_size() : param.data_param().prefetch() * param.data_param().batch_size())) { // Get or create a body boost::mutex::scoped_lock lock(bodies_mutex_); string key = source_key(param, is_cpm_data); weak_ptr<Body>& weak = bodies_[key]; body_ = weak.lock(); if (!body_) { body_.reset(new Body(param, is_cpm_data)); bodies_[key] = weak_ptr<Body>(body_); } body_->new_queue_pairs_.push(queue_pair_); }
// A source is uniquely identified by its layer name + path, in case // the same database is read from two different locations in the net. static inline string source_key(const LayerParameter& param, bool is_cpm_data_) { return param.name() + ":" + (is_cpm_data_ ? param.cpmdata_param().source() : param.data_param().source()); }