]> granicus.if.org Git - gc/commitdiff
Support configure --disable-thread-local-alloc option (similar for CMake)
authorIvan Maidanski <ivmai@mail.ru>
Wed, 7 Jun 2017 21:42:30 +0000 (00:42 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Wed, 7 Jun 2017 21:42:30 +0000 (00:42 +0300)
* CMakeLists.txt (enable_thread_local_alloc): New option (on by
default).
* CMakeLists.txt [CMAKE_USE_PTHREADS_INIT
|| CMAKE_USE_WIN32_THREADS_INIT] (SRC): Add thread_local_alloc.c only
if enable_thread_local_alloc.
* CMakeLists.txt [CMAKE_USE_PTHREADS_INIT
|| CMAKE_USE_WIN32_THREADS_INIT]: Define THREAD_LOCAL_ALLOC macro only
if enable_thread_local_alloc.

* Makefile.am (libgc_la_SOURCES): Add thread_local_alloc.c only if
THREAD_LOCAL_ALLOC.
* configure.ac (thread-local-alloc): New option.
* configure.ac: AC_DEFINE(THREAD_LOCAL_ALLOC) only if
enable_thread_local_alloc is yes or unset.
* configure.ac (THREAD_LOCAL_ALLOC): New AM_CONDITIONAL.

CMakeLists.txt
Makefile.am
configure.ac

index 1d46de9afb0e7cb794e016eaa4570d86c8cb4c82..d4bcd7f8c40b93a35f9f333c032c1b03b5ea6873 100644 (file)
@@ -61,6 +61,8 @@ IF(enable_threads)
         SET(LIBS ${LIBS} ${Threads_LIBRARIES})
 ENDIF(enable_threads)
 
+OPTION(enable_thread_local_alloc "Turn on thread-local allocation optimization" ON)
+
 OPTION(enable_parallel_mark "Parallelize marking and free list construction" ON)
 
 #IF(Threads_FOUND)
@@ -79,14 +81,17 @@ MESSAGE("HOST = ${HOST}")
 #Thread Detection. Relying on cmake for lib an includes.
 #TODO check cmake detection
 IF(CMAKE_USE_PTHREADS_INIT)
-        SET(SRC ${SRC} pthread_start.c pthread_support.c pthread_stop_world.c thread_local_alloc.c)
+        SET(SRC ${SRC} pthread_start.c pthread_support.c pthread_stop_world.c)
         # Common defines for most POSIX platforms.
         IF( HOST MATCHES .*-.*-aix.*|.*-.*-cygwin.*|.*-.*-darwin.*|.*-.*-.*freebsd.*|.*-.*-gnu.*|.*-.*-hpux11.*|.*-.*-irix.*|.*-.*-.*linux.*|.*-.*-nacl.*|.*-.*-netbsd.*|.*-.*-openbsd.*|.*-.*-osf.*|.*-.*-solaris.*)
                 ADD_DEFINITIONS("-DGC_THREADS -D_REENTRANT")
                 IF(enable_parallel_mark)
                     ADD_DEFINITIONS("-DPARALLEL_MARK")
                 ENDIF(enable_parallel_mark)
-                ADD_DEFINITIONS("-DTHREAD_LOCAL_ALLOC")
+                IF(enable_thread_local_alloc)
+                    ADD_DEFINITIONS("-DTHREAD_LOCAL_ALLOC")
+                    SET(SRC ${SRC} thread_local_alloc.c)
+                ENDIF(enable_thread_local_alloc)
                 MESSAGE("Explicit GC_INIT() calls may be required.")
         ENDIF()
         IF ( HOST MATCHES .*-.*-hpux11.*)
@@ -114,8 +119,10 @@ IF(CMAKE_USE_WIN32_THREADS_INIT)
         ADD_DEFINITIONS("-DGC_THREADS")
         IF(enable_parallel_mark)
                 ADD_DEFINITIONS("-DPARALLEL_MARK")
-                ADD_DEFINITIONS("-DTHREAD_LOCAL_ALLOC")
-                SET(SRC ${SRC} thread_local_alloc.c)
+                IF(enable_thread_local_alloc)
+                    ADD_DEFINITIONS("-DTHREAD_LOCAL_ALLOC")
+                    SET(SRC ${SRC} thread_local_alloc.c)
+                ENDIF(enable_thread_local_alloc)
         ENDIF()
         ADD_DEFINITIONS("-DEMPTY_GETENV_RESULTS") #TODO test
         SET(SRC ${SRC} win32_threads.c)
index a28b0428acd44b556f640c0623b4a97f761daeb1..5b63258ef4ec4167c21445a97ece7884d9b51ff9 100644 (file)
@@ -70,10 +70,10 @@ libgc_la_SOURCES = \
 # ---------------------------------
 
 if WIN32_THREADS
-libgc_la_SOURCES += thread_local_alloc.c win32_threads.c
+libgc_la_SOURCES += win32_threads.c
 else
 if PTHREADS
-libgc_la_SOURCES += pthread_start.c pthread_support.c thread_local_alloc.c
+libgc_la_SOURCES += pthread_start.c pthread_support.c
 if DARWIN_THREADS
 libgc_la_SOURCES += darwin_stop_world.c
 else
@@ -82,6 +82,10 @@ endif
 endif
 endif
 
+if THREAD_LOCAL_ALLOC
+libgc_la_SOURCES += thread_local_alloc.c
+endif
+
 if MAKE_BACK_GRAPH
 libgc_la_SOURCES += backgraph.c
 endif
index 292d6853c47fbe9a4e34831fb881e36bbcd8072f..ed2ee6424ad29aa76b35f300ca391de41510a0cb 100644 (file)
@@ -123,6 +123,18 @@ AC_ARG_ENABLE(parallel-mark,
     esac ]
 )
 
+AC_ARG_ENABLE(thread-local-alloc,
+   [AC_HELP_STRING([--disable-thread-local-alloc],
+        [turn off thread-local allocation optimization])],
+   [case "$THREADS" in
+      no | none | single)
+        if test "${enable_thread_local_alloc}" = yes; then
+          AC_MSG_ERROR(
+                [Thread-local allocation requires --enable-threads=x spec])
+        fi
+        ;;
+    esac])
+
 AC_ARG_ENABLE(cplusplus,
     [AC_HELP_STRING([--enable-cplusplus], [install C++ support])])
 
@@ -179,7 +191,9 @@ case "$THREADS" in
         if test "${enable_parallel_mark}" != no; then
           AC_DEFINE(PARALLEL_MARK)
         fi
-        AC_DEFINE(THREAD_LOCAL_ALLOC)
+        if test "${enable_thread_local_alloc}" != no; then
+          AC_DEFINE(THREAD_LOCAL_ALLOC)
+        fi
         AC_MSG_WARN("Explicit GC_INIT() calls may be required.")
         ;;
     esac
@@ -233,7 +247,9 @@ case "$THREADS" in
         if test "${enable_parallel_mark}" != no; then
           AC_DEFINE(PARALLEL_MARK)
         fi
-        AC_DEFINE(THREAD_LOCAL_ALLOC)
+        if test "${enable_thread_local_alloc}" != no; then
+          AC_DEFINE(THREAD_LOCAL_ALLOC)
+        fi
         THREADDLLIBS="-lpthread"
         win32_threads=true
         ;;
@@ -260,9 +276,10 @@ case "$THREADS" in
     AC_DEFINE(GC_THREADS)
     if test "${enable_parallel_mark}" != no; then
       AC_DEFINE(PARALLEL_MARK)
-      AC_DEFINE(THREAD_LOCAL_ALLOC)
-    else
-      if test "${enable_shared}" != yes || test "${enable_static}" != no; then
+    fi
+    if test "${enable_thread_local_alloc}" != no; then
+      if test "${enable_parallel_mark}" != no \
+              -o "${enable_shared}" != yes -o "${enable_static}" != no; then
         # Imply THREAD_LOCAL_ALLOC unless GC_DLL.
         AC_DEFINE(THREAD_LOCAL_ALLOC)
       fi
@@ -284,7 +301,9 @@ case "$THREADS" in
     if test "${enable_parallel_mark}" != no; then
         AC_DEFINE(PARALLEL_MARK)
     fi
-    AC_DEFINE(THREAD_LOCAL_ALLOC)
+    if test "${enable_thread_local_alloc}" != no; then
+        AC_DEFINE(THREAD_LOCAL_ALLOC)
+    fi
     AC_MSG_WARN("Explicit GC_INIT() calls may be required.")
     AM_CFLAGS="-pthread $AM_CFLAGS"
     ;;
@@ -296,7 +315,9 @@ case "$THREADS" in
     if test "${enable_parallel_mark}" != no; then
       AC_DEFINE(PARALLEL_MARK)
     fi
-    AC_DEFINE(THREAD_LOCAL_ALLOC)
+    if test "${enable_thread_local_alloc}" != no; then
+      AC_DEFINE(THREAD_LOCAL_ALLOC)
+    fi
     ;;
  rtems)
     THREADS=posix
@@ -304,7 +325,9 @@ case "$THREADS" in
     if test "${enable_parallel_mark}" != no; then
       AC_DEFINE(PARALLEL_MARK)
     fi
-    AC_DEFINE(THREAD_LOCAL_ALLOC)
+    if test "${enable_thread_local_alloc}" != no; then
+      AC_DEFINE(THREAD_LOCAL_ALLOC)
+    fi
     ;;
  decosf1 | irix | mach | os2 | solaris | dce | vxworks)
     AC_MSG_ERROR(thread package $THREADS not yet supported)
@@ -318,6 +341,8 @@ AM_CONDITIONAL(THREADS, test x$THREADS != xnone)
 AM_CONDITIONAL(PTHREADS, test x$THREADS = xposix)
 AM_CONDITIONAL(DARWIN_THREADS, test x$darwin_threads = xtrue)
 AM_CONDITIONAL(WIN32_THREADS, test x$win32_threads = xtrue)
+AM_CONDITIONAL(THREAD_LOCAL_ALLOC,
+            test x$enable_thread_local_alloc != xno -a x$THREADS != xnone)
 
 compiler_suncc=no
 case "$host" in