Index: third_party/tcmalloc/chromium/src/thread_cache.cc |
=================================================================== |
--- third_party/tcmalloc/chromium/src/thread_cache.cc (revision 87277) |
+++ third_party/tcmalloc/chromium/src/thread_cache.cc (working copy) |
@@ -31,18 +31,20 @@ |
// Author: Ken Ashcraft <opensource@google.com> |
#include <config.h> |
-#ifdef HAVE_INTTYPES_H |
-#include <inttypes.h> |
-#endif |
-#include <algorithm> // for min and max |
#include "thread_cache.h" |
+#include <string.h> // for memcpy |
+#include <algorithm> // for max, min |
+#include "base/commandlineflags.h" // for SpinLockHolder |
+#include "base/spinlock.h" // for SpinLockHolder |
+#include "central_freelist.h" // for CentralFreeListPadded |
#include "maybe_threads.h" |
using std::min; |
using std::max; |
DEFINE_int64(tcmalloc_max_total_thread_cache_bytes, |
- EnvToInt64("TCMALLOC_MAX_TOTAL_THREAD_CACHE_BYTES", 16<<20), |
+ EnvToInt64("TCMALLOC_MAX_TOTAL_THREAD_CACHE_BYTES", |
+ kDefaultOverallThreadCacheSize), |
"Bound on the total amount of bytes allocated to " |
"thread caches. This bound is not strict, so it is possible " |
"for the cache to go over this bound in certain circumstances. "); |
@@ -311,16 +313,6 @@ |
ASSERT(!tsd_inited_); |
perftools_pthread_key_create(&heap_key_, DestroyThreadCache); |
tsd_inited_ = true; |
- |
- // We may have used a fake pthread_t for the main thread. Fix it. |
- pthread_t zero; |
- memset(&zero, 0, sizeof(zero)); |
- SpinLockHolder h(Static::pageheap_lock()); |
- for (ThreadCache* h = thread_heaps_; h != NULL; h = h->next_) { |
- if (h->tid_ == zero) { |
- h->tid_ = pthread_self(); |
- } |
- } |
} |
ThreadCache* ThreadCache::CreateCacheIfNecessary() { |
@@ -328,15 +320,18 @@ |
ThreadCache* heap = NULL; |
{ |
SpinLockHolder h(Static::pageheap_lock()); |
+ // On very old libc's, this call may crash if it happens too |
+ // early. No libc using NPTL should be affected. If there |
+ // is a crash here, we could use code (on linux, at least) |
+ // to detect NPTL vs LinuxThreads: |
+ // http://www.redhat.com/archives/phil-list/2003-April/msg00038.html |
+ // If we detect not-NPTL, we could execute the old code from |
+ // http://google-perftools.googlecode.com/svn/tags/google-perftools-1.7/src/thread_cache.cc |
+ // that avoids calling pthread_self too early. The problem with |
+ // that code is it caused a race condition when tcmalloc is linked |
+ // in statically and other libraries spawn threads before main. |
+ const pthread_t me = pthread_self(); |
- // Early on in glibc's life, we cannot even call pthread_self() |
- pthread_t me; |
- if (!tsd_inited_) { |
- memset(&me, 0, sizeof(me)); |
- } else { |
- me = pthread_self(); |
- } |
- |
// This may be a recursive malloc call from pthread_setspecific() |
// In that case, the heap for this thread has already been created |
// and added to the linked list. So we search for that first. |