From 1e40b9b0494d1dd2d289f71799e1d5d6dec4774f Mon Sep 17 00:00:00 2001 From: Ivan Maidanski Date: Fri, 28 Apr 2017 11:42:43 +0300 Subject: [PATCH] Use thread-local allocations for all multi-threaded builds This change affects only builds by configure and CMake. * CMakeLists.txt [CMAKE_USE_PTHREADS_INIT]: Handle *-*-*linux* and *-*-nacl* targets in the same way as x86-*-linux*. * CMakeLists.txt [CMAKE_USE_PTHREADS_INIT] (THREAD_LOCAL_ALLOC): Define macro (and add thread_local_alloc.c to SRC) for *-*-aix*, *-*-hpux11*, *-*-openbsd*, *-*-freebsd*, *-*-netbsd*, *-*-irix* targets. * configure.ac [THREADS=posix] (THREAD_LOCAL_ALLOC): AC_DEFINE for *-*-*linux*, *-*-nacl*, *-*-aix*, *-*-openbsd*, *-*-netbsd*, *-*-irix* targets. * configure.ac [THREADS=posix && *-*-freebsd*]: Remove AC_MSG_WARN that threads are not fully supported by GC. * CMakeLists.txt [CMAKE_USE_PTHREADS_INIT && *-*-freebsd*]: Likewise. * configure.ac [THREADS=posix && *-*-osf*] (THREAD_LOCAL_ALLOC): Define even if enable_parallel_mark is false. * CMakeLists.txt [CMAKE_USE_PTHREADS_INIT && *-*-osf*] (THREAD_LOCAL_ALLOC): Likewise. * configure.ac [THREADS=aix] (THREAD_LOCAL_ALLOC): AC_DEFINE. --- CMakeLists.txt | 37 ++++++++++++++++--------------------- configure.ac | 20 ++++++++------------ 2 files changed, 24 insertions(+), 33 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2d924b8d..e33aee88 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -80,7 +80,7 @@ MESSAGE("HOST = ${HOST}") #TODO check cmake detection IF(CMAKE_USE_PTHREADS_INIT) SET(SRC ${SRC} pthread_start.c pthread_support.c pthread_stop_world.c) - IF( HOST MATCHES x86-.*-linux.*|ia64-.*-linux.*|i586-.*-linux.*|i686-.*-linux.*|x86_64-.*-linux.*|alpha-.*-linux.*|sparc.*-.*-linux.*) + IF( HOST MATCHES .*-.*-.*linux.*|.*-.*-nacl.*) ADD_DEFINITIONS("-DGC_LINUX_THREADS") ADD_DEFINITIONS("-D_REENTRANT") IF(enable_parallel_mark) @@ -90,19 +90,14 @@ IF(CMAKE_USE_PTHREADS_INIT) SET(SRC ${SRC} thread_local_alloc.c) MESSAGE("Explicit GC_INIT() calls may be required.") ENDIF() - IF ( HOST MATCHES .*-.*-linux.*) - ADD_DEFINITIONS("-DGC_LINUX_THREADS") - ADD_DEFINITIONS("-D_REENTRANT") - IF(enable_parallel_mark) - ADD_DEFINITIONS("-DPARALLEL_MARK") - ENDIF(enable_parallel_mark) - ENDIF() IF ( HOST MATCHES .*-.*-aix.*) ADD_DEFINITIONS("-DGC_AIX_THREADS") ADD_DEFINITIONS("-D_REENTRANT") IF(enable_parallel_mark) ADD_DEFINITIONS("-DPARALLEL_MARK") ENDIF(enable_parallel_mark) + ADD_DEFINITIONS("-DTHREAD_LOCAL_ALLOC") + SET(SRC ${SRC} thread_local_alloc.c) ENDIF() IF ( HOST MATCHES .*-.*-hpux11.*) MESSAGE("Only HP/UX 11 POSIX threads are supported.") @@ -113,6 +108,8 @@ IF(CMAKE_USE_PTHREADS_INIT) IF(enable_parallel_mark) ADD_DEFINITIONS("-DPARALLEL_MARK") ENDIF(enable_parallel_mark) + ADD_DEFINITIONS("-DTHREAD_LOCAL_ALLOC") + SET(SRC ${SRC} thread_local_alloc.c) ENDIF() IF ( HOST MATCHES .*-.*-hpux10.*) MESSAGE("Only HP/UX 11 POSIX threads are supported.") @@ -122,13 +119,16 @@ IF(CMAKE_USE_PTHREADS_INIT) IF(enable_parallel_mark) ADD_DEFINITIONS("-DPARALLEL_MARK") ENDIF(enable_parallel_mark) + ADD_DEFINITIONS("-DTHREAD_LOCAL_ALLOC") + SET(SRC ${SRC} thread_local_alloc.c) ENDIF() IF ( HOST MATCHES .*-.*-freebsd.*) - MESSAGE("FreeBSD does not yet fully support threads with Boehm GC.") ADD_DEFINITIONS("-DGC_FREEBSD_THREADS") IF(enable_parallel_mark) ADD_DEFINITIONS("-DPARALLEL_MARK") ENDIF(enable_parallel_mark) + ADD_DEFINITIONS("-DTHREAD_LOCAL_ALLOC") + SET(SRC ${SRC} thread_local_alloc.c) ENDIF() IF ( HOST MATCHES .*-.*-kfreebsd.*-gnu) ADD_DEFINITIONS("-DGC_FREEBSD_THREADS") @@ -157,6 +157,8 @@ IF(CMAKE_USE_PTHREADS_INIT) IF(enable_parallel_mark) ADD_DEFINITIONS("-DPARALLEL_MARK") ENDIF(enable_parallel_mark) + ADD_DEFINITIONS("-DTHREAD_LOCAL_ALLOC") + SET(SRC ${SRC} thread_local_alloc.c) ENDIF() IF ( HOST MATCHES .*-.*-solaris.*) ADD_DEFINITIONS("-DGC_SOLARIS_THREADS") @@ -177,6 +179,8 @@ IF(CMAKE_USE_PTHREADS_INIT) IF(enable_parallel_mark) ADD_DEFINITIONS("-DPARALLEL_MARK") ENDIF(enable_parallel_mark) + ADD_DEFINITIONS("-DTHREAD_LOCAL_ALLOC") + SET(SRC ${SRC} thread_local_alloc.c) ENDIF() IF ( HOST MATCHES .*-.*-cygwin.*) ADD_DEFINITIONS("-DGC_THREADS") @@ -203,19 +207,10 @@ IF(CMAKE_USE_PTHREADS_INIT) ADD_DEFINITIONS("-DGC_OSF1_THREADS") IF(enable_parallel_mark) ADD_DEFINITIONS("-DPARALLEL_MARK") - ADD_DEFINITIONS("-DTHREAD_LOCAL_ALLOC") - SET(SRC ${SRC} thread_local_alloc.c) - MESSAGE("Explicit GC_INIT() calls may be required.") - # May want to enable it in other cases, too. - # Measurements haven't yet been done. ENDIF() - ENDIF() - IF ( HOST MATCHES .*-.*-linux.*) - ADD_DEFINITIONS("-DGC_LINUX_THREADS") - ADD_DEFINITIONS("-D_REENTRANT") - IF(enable_parallel_mark) - ADD_DEFINITIONS("-DPARALLEL_MARK") - ENDIF(enable_parallel_mark) + ADD_DEFINITIONS("-DTHREAD_LOCAL_ALLOC") + SET(SRC ${SRC} thread_local_alloc.c) + MESSAGE("Explicit GC_INIT() calls may be required.") ENDIF() ENDIF(CMAKE_USE_PTHREADS_INIT) diff --git a/configure.ac b/configure.ac index 12a96132..5617c3c5 100644 --- a/configure.ac +++ b/configure.ac @@ -183,8 +183,7 @@ case "$THREADS" in THREADS=posix AC_CHECK_LIB(pthread, pthread_self, THREADDLLIBS="-lpthread",,) case "$host" in - x86-*-linux* | ia64-*-linux* | i586-*-linux* | i686-*-linux* \ - | x86_64-*-linux* | alpha-*-linux* | powerpc*-*-linux* | sparc*-*-linux*) + *-*-*linux* | *-*-nacl*) AC_DEFINE(GC_LINUX_THREADS) AC_DEFINE(_REENTRANT) if test "${enable_parallel_mark}" != no; then @@ -193,19 +192,13 @@ case "$THREADS" in AC_DEFINE(THREAD_LOCAL_ALLOC) AC_MSG_WARN("Explicit GC_INIT() calls may be required."); ;; - *-*-*linux* | *-*-nacl*) - AC_DEFINE(GC_LINUX_THREADS) - AC_DEFINE(_REENTRANT) - if test "${enable_parallel_mark}" != no; then - AC_DEFINE(PARALLEL_MARK) - fi - ;; *-*-aix*) AC_DEFINE(GC_AIX_THREADS) AC_DEFINE(_REENTRANT) if test "${enable_parallel_mark}" != no; then AC_DEFINE(PARALLEL_MARK) fi + AC_DEFINE(THREAD_LOCAL_ALLOC) ;; *-*-hpux11*) AC_MSG_WARN("Only HP/UX 11 POSIX threads are supported.") @@ -228,11 +221,11 @@ case "$THREADS" in if test "${enable_parallel_mark}" != no; then AC_DEFINE(PARALLEL_MARK) fi + AC_DEFINE(THREAD_LOCAL_ALLOC) THREADDLLIBS=-pthread AM_CFLAGS="$AM_CFLAGS -pthread" ;; *-*-freebsd*) - AC_MSG_WARN("FreeBSD does not yet fully support threads with Boehm GC.") AC_DEFINE(GC_FREEBSD_THREADS) AM_CFLAGS="$AM_CFLAGS -pthread" if test "${enable_parallel_mark}" != no; then @@ -267,6 +260,7 @@ case "$THREADS" in if test "${enable_parallel_mark}" != no; then AC_DEFINE(PARALLEL_MARK) fi + AC_DEFINE(THREAD_LOCAL_ALLOC) THREADDLLIBS="-lpthread -lrt" ;; *-*-solaris*) @@ -286,6 +280,7 @@ case "$THREADS" in if test "${enable_parallel_mark}" != no; then AC_DEFINE(PARALLEL_MARK) fi + AC_DEFINE(THREAD_LOCAL_ALLOC) ;; *-*-cygwin*) AC_DEFINE(GC_WIN32_THREADS) @@ -322,9 +317,9 @@ case "$THREADS" in AC_DEFINE(GC_OSF1_THREADS) if test "${enable_parallel_mark}" != no; then AC_DEFINE(PARALLEL_MARK) - AC_DEFINE(THREAD_LOCAL_ALLOC) - AC_MSG_WARN("Explicit GC_INIT() calls may be required."); fi + AC_DEFINE(THREAD_LOCAL_ALLOC) + AC_MSG_WARN("Explicit GC_INIT() calls may be required."); AM_CFLAGS="$AM_CFLAGS -pthread" THREADDLLIBS="-lpthread -lrt" ;; @@ -384,6 +379,7 @@ case "$THREADS" in if test "${enable_parallel_mark}" != no; then AC_DEFINE(PARALLEL_MARK) fi + AC_DEFINE(THREAD_LOCAL_ALLOC) ;; rtems) THREADS=posix -- 2.40.0