[llvm-commits] [llvm] r73662 - in /llvm/trunk: include/llvm/System/RWMutex.h lib/VMCore/Function.cpp
Owen Anderson
resistor at mac.com
Wed Jun 17 16:49:16 PDT 2009
Author: resistor
Date: Wed Jun 17 18:49:06 2009
New Revision: 73662
URL: http://llvm.org/viewvc/llvm-project?rev=73662&view=rev
Log:
Reapply r73647 in a non-broken form.
Modified:
llvm/trunk/include/llvm/System/RWMutex.h
llvm/trunk/lib/VMCore/Function.cpp
Modified: llvm/trunk/include/llvm/System/RWMutex.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/System/RWMutex.h?rev=73662&r1=73661&r2=73662&view=diff
==============================================================================
--- llvm/trunk/include/llvm/System/RWMutex.h (original)
+++ llvm/trunk/include/llvm/System/RWMutex.h Wed Jun 17 18:49:06 2009
@@ -79,7 +79,7 @@
/// @}
};
- /// ScopedReader - RAII acquisition of a writer lock
+ /// ScopedReader - RAII acquisition of a reader lock
struct ScopedReader {
RWMutex* mutex;
Modified: llvm/trunk/lib/VMCore/Function.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Function.cpp?rev=73662&r1=73661&r2=73662&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/Function.cpp (original)
+++ llvm/trunk/lib/VMCore/Function.cpp Wed Jun 17 18:49:06 2009
@@ -18,6 +18,7 @@
#include "llvm/Support/LeakDetector.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/StringPool.h"
+#include "llvm/Support/Threading.h"
#include "llvm/System/RWMutex.h"
#include "SymbolTableListTraitsImpl.h"
#include "llvm/ADT/DenseMap.h"
@@ -230,21 +231,20 @@
// allocating an additional word in Function for programs which do not use GC
// (i.e., most programs) at the cost of increased overhead for clients which do
// use GC.
-static ManagedStatic<DenseMap<const Function*,PooledStringPtr> > GCNames;
-static ManagedStatic<StringPool> GCNamePool;
+static DenseMap<const Function*,PooledStringPtr> *GCNames;
+static StringPool *GCNamePool;
static ManagedStatic<sys::RWMutex> GCLock;
bool Function::hasGC() const {
if (llvm_is_multithreaded()) {
sys::ScopedReader Reader(&*GCLock);
- return GCNames->count(this);
- } else
- return GCNames->count(this);
+ return GCNames && GCNames->count(this);
+ } else
+ return GCNames && GCNames->count(this);
}
const char *Function::getGC() const {
assert(hasGC() && "Function has no collector");
-
if (llvm_is_multithreaded()) {
sys::ScopedReader Reader(&*GCLock);
return *(*GCNames)[this];
@@ -253,19 +253,29 @@
}
void Function::setGC(const char *Str) {
- if (llvm_is_multithreaded()) {
- sys::ScopedWriter Writer(&*GCLock);
- (*GCNames)[this] = GCNamePool->intern(Str);
- } else
- (*GCNames)[this] = GCNamePool->intern(Str);
+ if (llvm_is_multithreaded()) GCLock->writer_acquire();
+ if (!GCNamePool)
+ GCNamePool = new StringPool();
+ if (!GCNames)
+ GCNames = new DenseMap<const Function*,PooledStringPtr>();
+ (*GCNames)[this] = GCNamePool->intern(Str);
+ if (llvm_is_multithreaded()) GCLock->writer_release();
}
void Function::clearGC() {
- if (llvm_is_multithreaded()) {
- sys::ScopedWriter Writer(&*GCLock);
- GCNames->erase(this);
- } else
+ if (llvm_is_multithreaded()) GCLock->writer_acquire();
+ if (GCNames) {
GCNames->erase(this);
+ if (GCNames->empty()) {
+ delete GCNames;
+ GCNames = 0;
+ if (GCNamePool->empty()) {
+ delete GCNamePool;
+ GCNamePool = 0;
+ }
+ }
+ }
+ if (llvm_is_multithreaded()) GCLock->writer_release();
}
/// copyAttributesFrom - copy all additional attributes (those not needed to
More information about the llvm-commits
mailing list