NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: port-arm/50087: all threaded programs crash on arm



The following reply was made to PR port-arm/50087; it has been noted by GNATS.

From: christos%zoulas.com@localhost (Christos Zoulas)
To: gnats-bugs%NetBSD.org@localhost, port-arm-maintainer%netbsd.org@localhost, 
	gnats-admin%netbsd.org@localhost, netbsd-bugs%netbsd.org@localhost, martin%NetBSD.org@localhost
Cc: 
Subject: Re: port-arm/50087: all threaded programs crash on arm
Date: Sun, 26 Jul 2015 11:54:27 -0400

 On Jul 26, 12:20pm, martin%duskware.de@localhost (Martin Husemann) wrote:
 -- Subject: Re: port-arm/50087: all threaded programs crash on arm
 
 Here's a fix.
 
 christos
 
 Index: jemalloc.c
 ===================================================================
 RCS file: /cvsroot/src/lib/libc/stdlib/jemalloc.c,v
 retrieving revision 1.37
 diff -u -u -r1.37 jemalloc.c
 --- jemalloc.c	20 Jan 2015 18:31:25 -0000	1.37
 +++ jemalloc.c	26 Jul 2015 15:52:41 -0000
 @@ -783,20 +783,58 @@
  static malloc_mutex_t	arenas_mtx; /* Protects arenas initialization. */
  #endif
  
 -#ifndef NO_TLS
  /*
   * Map of pthread_self() --> arenas[???], used for selecting an arena to use
   * for allocations.
   */
 -static __thread arena_t	*arenas_map;
 -#define	get_arenas_map()	(arenas_map)
 -#define	set_arenas_map(x)	(arenas_map = x)
 +#ifndef NO_TLS
 +static __thread arena_t	**arenas_map;
  #else
 -#ifdef _REENTRANT
 -static thread_key_t arenas_map_key;
 +static arena_t	**arenas_map;
  #endif
 -#define	get_arenas_map()	thr_getspecific(arenas_map_key)
 -#define	set_arenas_map(x)	thr_setspecific(arenas_map_key, x)
 +
 +#if !defined(NO_TLS) || !defined(_REENTRANT)
 +# define	get_arenas_map()	(arenas_map)
 +# define	set_arenas_map(x)	(arenas_map = x)
 +#else
 +
 +static thread_key_t arenas_map_key = -1;
 +
 +static inline arena_t **
 +get_arenas_map(void)
 +{
 +	if (!__isthreaded)
 +		return arenas_map;
 +
 +	if (arenas_map_key == -1) {
 +		(void)thr_keycreate(&arenas_map_key, NULL);
 +		if (arenas_map != NULL) {
 +			thr_setspecific(arenas_map_key, arenas_map);
 +			arenas_map = NULL;
 +		}
 +	}
 +
 +	return thr_getspecific(arenas_map_key);
 +}
 +
 +static __inline void
 +set_arenas_map(arena_t **a)
 +{
 +	if (!__isthreaded) {
 +		arenas_map = a;
 +		return;
 +	}
 +
 +	if (arenas_map_key == -1) {
 +		(void)thr_keycreate(&arenas_map_key, NULL);
 +		if (arenas_map != NULL) {
 +			_DIAGASSERT(arenas_map == a);
 +			arenas_map = NULL;
 +		}
 +	}
 +
 +	thr_setspecific(arenas_map_key, a);
 +}
  #endif
  
  #ifdef MALLOC_STATS
 @@ -3654,11 +3692,6 @@
  		opt_narenas_lshift += 2;
  	}
  
 -#ifdef NO_TLS
 -	/* Initialize arena key. */
 -	(void)thr_keycreate(&arenas_map_key, NULL);
 -#endif
 -
  	/* Determine how many arenas to use. */
  	narenas = ncpus;
  	if (opt_narenas_lshift > 0) {
 


Home | Main Index | Thread Index | Old Index