Some minor refactoring of TU store
This commit is contained in:
parent
a215f933a9
commit
0f7d9ec131
@ -54,12 +54,10 @@ shared_ptr< TranslationUnit > TranslationUnitStore::GetOrCreate(
|
||||
translation_unit_created = false;
|
||||
{
|
||||
lock_guard< mutex > lock( filename_to_translation_unit_mutex_ );
|
||||
TranslationUnitForFilename::iterator it =
|
||||
filename_to_translation_unit_.find( filename );
|
||||
shared_ptr< TranslationUnit > current_unit = GetNoLock( filename );
|
||||
|
||||
if ( it != filename_to_translation_unit_.end() ) {
|
||||
return it->second;
|
||||
}
|
||||
if ( current_unit )
|
||||
return current_unit;
|
||||
|
||||
// We create and store an invalid, sentinel TU so that other threads don't
|
||||
// try to create a TU for the same file while we are trying to create this
|
||||
@ -93,9 +91,7 @@ shared_ptr< TranslationUnit > TranslationUnitStore::GetOrCreate(
|
||||
shared_ptr< TranslationUnit > TranslationUnitStore::Get(
|
||||
const std::string &filename ) {
|
||||
lock_guard< mutex > lock( filename_to_translation_unit_mutex_ );
|
||||
return FindWithDefault( filename_to_translation_unit_,
|
||||
filename,
|
||||
shared_ptr< TranslationUnit >() );
|
||||
return GetNoLock( filename );
|
||||
}
|
||||
|
||||
bool TranslationUnitStore::Remove( const std::string &filename ) {
|
||||
@ -108,4 +104,11 @@ void TranslationUnitStore::RemoveAll() {
|
||||
filename_to_translation_unit_.clear();
|
||||
}
|
||||
|
||||
shared_ptr< TranslationUnit > TranslationUnitStore::GetNoLock(
|
||||
const std::string &filename ) {
|
||||
return FindWithDefault( filename_to_translation_unit_,
|
||||
filename,
|
||||
shared_ptr< TranslationUnit >() );
|
||||
}
|
||||
|
||||
} // namespace YouCompleteMe
|
||||
|
@ -56,6 +56,11 @@ public:
|
||||
void RemoveAll();
|
||||
|
||||
private:
|
||||
|
||||
// WARNING: This does accesses filename_to_translation_unit_ without a lock!
|
||||
boost::shared_ptr< TranslationUnit > GetNoLock( const std::string &filename );
|
||||
|
||||
|
||||
typedef boost::unordered_map< std::string,
|
||||
boost::shared_ptr< TranslationUnit > > TranslationUnitForFilename;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user