diff options
author | Aliaksey Kandratsenka <alk@tut.by> | 2015-05-09 12:48:11 -0700 |
---|---|---|
committer | Aliaksey Kandratsenka <alk@tut.by> | 2015-05-09 14:56:58 -0700 |
commit | 7013b219970a329d1db58fbd7fa7c907bec8dbba (patch) | |
tree | 1496a9991f9ade6c289e06b511263b5708c7dbc1 | |
parent | f25f8e0bf2d361f852929848d79d7ba54586c352 (diff) | |
download | gperftools-7013b219970a329d1db58fbd7fa7c907bec8dbba.tar.gz |
hook mi_force_{un,}lock on OSX instead of pthread_atfork
This is patch by Anton Samokhvalov.
Apparently it helps with locking around forking on OSX.
-rw-r--r-- | src/libc_override_osx.h | 9 | ||||
-rw-r--r-- | src/static_vars.cc | 4 |
2 files changed, 9 insertions, 4 deletions
diff --git a/src/libc_override_osx.h b/src/libc_override_osx.h index 26923e9..b801f22 100644 --- a/src/libc_override_osx.h +++ b/src/libc_override_osx.h @@ -85,6 +85,11 @@ #include <AvailabilityMacros.h> #include <malloc/malloc.h> +namespace tcmalloc { + void CentralCacheLockAll(); + void CentralCacheUnlockAll(); +} + // from AvailabilityMacros.h #if defined(MAC_OS_X_VERSION_10_6) && \ MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6 @@ -169,11 +174,11 @@ void mi_log(malloc_zone_t *zone, void *address) { } void mi_force_lock(malloc_zone_t *zone) { - // Hopefully unneeded by us! + tcmalloc::CentralCacheLockAll(); } void mi_force_unlock(malloc_zone_t *zone) { - // Hopefully unneeded by us! + tcmalloc::CentralCacheUnlockAll(); } void mi_statistics(malloc_zone_t *zone, malloc_statistics_t *stats) { diff --git a/src/static_vars.cc b/src/static_vars.cc index 197b3a1..09d2b59 100644 --- a/src/static_vars.cc +++ b/src/static_vars.cc @@ -51,7 +51,6 @@ namespace tcmalloc { // sure the central_cache locks remain in a consisten state in the forked // version of the thread. -static void CentralCacheLockAll() { Static::pageheap_lock()->Lock(); @@ -59,7 +58,6 @@ void CentralCacheLockAll() Static::central_cache()[i].Lock(); } -static void CentralCacheUnlockAll() { for (int i = 0; i < kNumClasses; ++i) @@ -114,9 +112,11 @@ void Static::InitStaticVars() { static inline void SetupAtForkLocksHandler() { +#if !defined(__APPLE__) pthread_atfork(CentralCacheLockAll, // parent calls before fork CentralCacheUnlockAll, // parent calls after fork CentralCacheUnlockAll); // child calls after fork +#endif } REGISTER_MODULE_INITIALIZER(tcmalloc_fork_handler, SetupAtForkLocksHandler()); |