Bug 460933: Call pthread_atfork() to prevent potential deadlock after forking. [r=stuart]
authorJason Evans <jasone@canonware.com>
Thu, 30 Oct 2008 16:13:43 -0500
changeset 21117 fbadbd5149d5c4eeb1d00d8d72e7a29c5237008c
parent 21116 a618c70c87e55c0ce2b759319d1c563bff98f6d5
child 21118 a269caae011a7ef8a60c4d2b9e4d4f91cbb5b566
push id3327
push userreed@reedloden.com
push dateThu, 30 Oct 2008 21:13:37 +0000
treeherdermozilla-central@fbadbd5149d5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersstuart
bugs460933
milestone1.9.1b2pre
Bug 460933: Call pthread_atfork() to prevent potential deadlock after forking. [r=stuart]
memory/jemalloc/jemalloc.c
--- a/memory/jemalloc/jemalloc.c
+++ b/memory/jemalloc/jemalloc.c
@@ -1281,16 +1281,19 @@ static void	malloc_print_stats(void);
 static
 #endif
 bool		malloc_init_hard(void);
 static void	reserve_shrink(void);
 static uint64_t	reserve_notify(reserve_cnd_t cnd, size_t size, uint64_t seq);
 static uint64_t	reserve_crit(size_t size, const char *fname, uint64_t seq);
 static void	reserve_fail(size_t size, const char *fname);
 
+void		_malloc_prefork(void);
+void		_malloc_postfork(void);
+
 /*
  * End function prototypes.
  */
 /******************************************************************************/
 
 /*
  * umax2s() provides minimal integer printing functionality, which is
  * especially useful for situations where allocation in vsnprintf() calls would
@@ -5686,16 +5689,21 @@ MALLOC_OUT:
 	/* Take care to call atexit() only once. */
 	if (opt_print_stats) {
 #ifndef MOZ_MEMORY_WINDOWS
 		/* Print statistics at exit. */
 		atexit(malloc_print_stats);
 #endif
 	}
 
+#if (!defined(MOZ_MEMORY_WINDOWS) && !defined(MOZ_MEMORY_DARWIN))
+	/* Prevent potential deadlock on malloc locks after fork. */
+	pthread_atfork(_malloc_prefork, _malloc_postfork, _malloc_postfork);
+#endif
+
 	/* Set variables according to the value of opt_small_max_2pow. */
 	if (opt_small_max_2pow < opt_quantum_2pow)
 		opt_small_max_2pow = opt_quantum_2pow;
 	small_max = (1U << opt_small_max_2pow);
 
 	/* Set bin-related variables. */
 	bin_maxclass = (pagesize >> 1);
 	assert(opt_quantum_2pow >= TINY_MIN_2POW);