Use atomic operations for accessing this global counter.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@74294 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Owen Anderson 2009-06-26 18:09:03 +00:00
parent 93d95bd2c3
commit cb73734247

View File

@ -68,9 +68,12 @@ AnnotationID AnnotationManager::getID(const char *Name) { // Name -> ID
if (I == E) {
sys::SmartScopedWriter<true> Writer(&*AnnotationsLock);
I = IDMap->find(Name);
if (I == IDMap->end())
(*IDMap)[Name] = IDCounter++; // Add a new element
return AnnotationID(IDCounter-1);
if (I == IDMap->end()) {
unsigned newCount = sys::AtomicIncrement(&IDCounter);
(*IDMap)[Name] = newCount-1; // Add a new element
return AnnotationID(newCount-1);
} else
return AnnotationID(I->second);
}
return AnnotationID(I->second);
}