| Index: third_party/tcmalloc/chromium/src/static_vars.cc
|
| diff --git a/third_party/tcmalloc/chromium/src/static_vars.cc b/third_party/tcmalloc/chromium/src/static_vars.cc
|
| index 6fc852a82d1f2edb6e48f8d6ce2f100f80b4feab..35e0fa9c6eaf80c6b6bd56ce501fa34551a60e2c 100644
|
| --- a/third_party/tcmalloc/chromium/src/static_vars.cc
|
| +++ b/third_party/tcmalloc/chromium/src/static_vars.cc
|
| @@ -33,6 +33,9 @@
|
| #include "static_vars.h"
|
| #include <stddef.h> // for NULL
|
| #include <new> // for operator new
|
| +#ifdef HAVE_PTHREAD
|
| +#include <pthread.h> // for pthread_atfork
|
| +#endif
|
| #include "internal_logging.h" // for CHECK_CONDITION
|
| #include "common.h"
|
| #include "sampler.h" // for Sampler
|
| @@ -49,6 +52,27 @@ PageHeapAllocator<StackTraceTable::Bucket> Static::bucket_allocator_;
|
| StackTrace* Static::growth_stacks_ = NULL;
|
| PageHeap* Static::pageheap_ = NULL;
|
|
|
| +#ifdef HAVE_PTHREAD
|
| +// These following two functions are registered via pthread_atfork to make
|
| +// sure the central_cache locks remain in a consistent state in the forked
|
| +// version of the thread.
|
| +
|
| +void CentralCacheLockAll()
|
| +{
|
| + Static::pageheap_lock()->Lock();
|
| + for (int i = 0; i < kNumClasses; ++i)
|
| + Static::central_cache()[i].Lock();
|
| +}
|
| +
|
| +void CentralCacheUnlockAll()
|
| +{
|
| + for (int i = 0; i < kNumClasses; ++i)
|
| + Static::central_cache()[i].Unlock();
|
| + Static::pageheap_lock()->Unlock();
|
| +}
|
| +
|
| +#endif
|
| +
|
| void Static::InitStaticVars() {
|
| sizemap_.Init();
|
| span_allocator_.Init();
|
| @@ -61,6 +85,13 @@ void Static::InitStaticVars() {
|
| for (int i = 0; i < kNumClasses; ++i) {
|
| central_cache_[i].Init(i);
|
| }
|
| +
|
| +#if defined(HAVE_PTHREAD) && !defined(__APPLE__)
|
| + pthread_atfork(CentralCacheLockAll, // parent calls before fork
|
| + CentralCacheUnlockAll, // parent calls after fork
|
| + CentralCacheUnlockAll); // child calls after fork
|
| +#endif
|
| +
|
| // It's important to have PageHeap allocated, not in static storage,
|
| // so that HeapLeakChecker does not consider all the byte patterns stored
|
| // in is caches as pointers that are sources of heap object liveness,
|
|
|