Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(228)

Unified Diff: third_party/tcmalloc/chromium/src/static_vars.cc

Issue 1523403003: Lock tcmalloc structures in a pthread_atfork hook. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix typo. Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/tcmalloc/chromium/src/libc_override_osx.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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,
« no previous file with comments | « third_party/tcmalloc/chromium/src/libc_override_osx.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698