summaryrefslogtreecommitdiff
path: root/src/thread_cache.cc
diff options
context:
space:
mode:
authorcsilvers <csilvers@6b5cf1ce-ec42-a296-1ba9-69fdba395a50>2011-03-04 23:52:33 +0000
committercsilvers <csilvers@6b5cf1ce-ec42-a296-1ba9-69fdba395a50>2011-03-04 23:52:33 +0000
commit6fe07cd2c0527e18276cc79a57e2212a4b048746 (patch)
treebddf3a270eaa039d36146c6f77e76a058c09ecfb /src/thread_cache.cc
parent75584139e40c9d6c952d9c5339c52e5b58302fc8 (diff)
downloadgperftools-6fe07cd2c0527e18276cc79a57e2212a4b048746.tar.gz
* add a flag to use MAP_PRIVATE in memfs_malloc (gangren)
* pthread_self() is now safe to use early (ppluzhnikov) * windows support for pprof: nul and /usr/bin/file (csilvers) * fix tc_malloc_size for debugallocation (csilvers) * add test on strdup to tcmalloc_test (csilvers) * augment heap-checker to deal with no-inode maps (csilvers) * Get rid of -Wno-unused-result: not all gcc's support it (csilvers) * /bin/true -> ':', which is faster and more portable (csilvers) git-svn-id: http://gperftools.googlecode.com/svn/trunk@107 6b5cf1ce-ec42-a296-1ba9-69fdba395a50
Diffstat (limited to 'src/thread_cache.cc')
-rw-r--r--src/thread_cache.cc29
1 files changed, 11 insertions, 18 deletions
diff --git a/src/thread_cache.cc b/src/thread_cache.cc
index 8d31117..64e3b07 100644
--- a/src/thread_cache.cc
+++ b/src/thread_cache.cc
@@ -312,16 +312,6 @@ void ThreadCache::InitTSD() {
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() {
@@ -329,14 +319,17 @@ ThreadCache* ThreadCache::CreateCacheIfNecessary() {
ThreadCache* heap = NULL;
{
SpinLockHolder h(Static::pageheap_lock());
-
- // 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();
- }
+ // 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();
// This may be a recursive malloc call from pthread_setspecific()
// In that case, the heap for this thread has already been created