int IdPair::Primary::getUniqueId(const std::string &id) { int found = -1; { while (++readers < 0) { --readers; while (readers < 0) { } } IDMapType::iterator iter = idMap.find(id); if (iter != idMap.end()) { found = (*iter).second; } --readers; } if (found == -1) { readers -= WRITER; while (readers > -WRITER) { } // Can now safely add this to the map. found = max_id; assert(found == (int)idNames.size()); idMap.insert(IDMapType::value_type(id, found)); idNames.push_back(id); max_id++; readers += WRITER; // done. } return found; }
int IdPair::Primary::getUniqueId(const std::string &id) { IDMapType::iterator iter = idMap.find(id); if (iter == idMap.end()) { iter = idMap.insert(IDMapType::value_type(id, max_id)).first; max_id++; } return (*iter).second; }