| commit 7013b219970a329d1db58fbd7fa7c907bec8dbba |
| Author: Aliaksey Kandratsenka <alk@tut.by> |
| Date: Sat May 9 12:48:11 2015 -0700 |
| |
| 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. |
| |
| 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()); |
| |