aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorOwen Anderson <resistor@mac.com>2009-06-26 18:09:03 +0000
committerOwen Anderson <resistor@mac.com>2009-06-26 18:09:03 +0000
commit3de3e9bd1bce1728849e39097f2ef570d98cf53a (patch)
treecbc7b2baedca704fede8b84eb2f2649c109027aa /lib
parente883fc4de8b1a7f06208cec052c8dee5e647a299 (diff)
downloadexternal_llvm-3de3e9bd1bce1728849e39097f2ef570d98cf53a.zip
external_llvm-3de3e9bd1bce1728849e39097f2ef570d98cf53a.tar.gz
external_llvm-3de3e9bd1bce1728849e39097f2ef570d98cf53a.tar.bz2
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
Diffstat (limited to 'lib')
-rw-r--r--lib/Support/Annotation.cpp9
1 files changed, 6 insertions, 3 deletions
diff --git a/lib/Support/Annotation.cpp b/lib/Support/Annotation.cpp
index 9c3efa3..b778043 100644
--- a/lib/Support/Annotation.cpp
+++ b/lib/Support/Annotation.cpp
@@ -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);
}