Chromium Code Reviews| 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..3759d46403e9ff5d20138d0d3ff71120a39c370a 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 consisten 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 |
|
rickyz (no longer on Chrome)
2015/12/16 12:13:39
Unlike the upstream commit, we keep the pthread_at
|
| + 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, |