| 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..ece565d586b9dbb418b79086066a909f11c5c689 100644
|
| --- a/third_party/tcmalloc/chromium/src/static_vars.cc
|
| +++ b/third_party/tcmalloc/chromium/src/static_vars.cc
|
| @@ -36,9 +36,32 @@
|
| #include "internal_logging.h" // for CHECK_CONDITION
|
| #include "common.h"
|
| #include "sampler.h" // for Sampler
|
| +#include "base/googleinit.h"
|
| +#include "maybe_threads.h"
|
|
|
| namespace tcmalloc {
|
|
|
| +#if defined(HAVE_FORK) && defined(HAVE_PTHREAD) && !defined(__APPLE__)
|
| +
|
| +// 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
|
| +
|
| SpinLock Static::pageheap_lock_(SpinLock::LINKER_INITIALIZED);
|
| SizeMap Static::sizemap_;
|
| CentralFreeListPadded Static::central_cache_[kNumClasses];
|
| @@ -70,4 +93,19 @@ void Static::InitStaticVars() {
|
| Sampler::InitStatics();
|
| }
|
|
|
| +
|
| +#if defined(HAVE_FORK) && defined(HAVE_PTHREAD) && !defined(__APPLE__)
|
| +
|
| +static inline
|
| +void SetupAtForkLocksHandler()
|
| +{
|
| + perftools_pthread_atfork(
|
| + CentralCacheLockAll, // parent calls before fork
|
| + CentralCacheUnlockAll, // parent calls after fork
|
| + CentralCacheUnlockAll); // child calls after fork
|
| +}
|
| +REGISTER_MODULE_INITIALIZER(tcmalloc_fork_handler, SetupAtForkLocksHandler());
|
| +
|
| +#endif
|
| +
|
| } // namespace tcmalloc
|
|
|