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

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

Issue 1715903002: Adapt upstream patches fixing potential deadlock in tcmalloc after fork. Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: Updated README Created 4 years, 10 months 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/maybe_threads.cc ('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..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
« no previous file with comments | « third_party/tcmalloc/chromium/src/maybe_threads.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698