Expose pthread feature flag

The code was able to use pthread destructors rather than C++ thread
local destructors.  This removes the dependence on a C++ .so on linux.
However, this is not stable on other platforms such as Apple. Where the
C++ thread local state can be cleared before the pthread destructor
runs.
This commit is contained in:
Matthew Parkinson
2021-08-25 11:26:44 +01:00
committed by Matthew Parkinson
parent ea90f7b9c2
commit b52e2a6e27
4 changed files with 20 additions and 3 deletions

View File

@@ -38,16 +38,23 @@ jobs:
build-type: Debug
build-only: yes
# Add the self-host build
- os: ubuntu-latest
- os: "ubuntu-latest"
build-type: Debug
self-host: true
# Extra build to check using pthread library for destructing local state.
- os: "ubuntu-latest"
variant: "Ubuntu (with pthread destructors)."
dependencies: "sudo apt install ninja-build"
build-type: Debug
self-host: true
extra-cmake-flags: "-DSNMALLOC_USE_PTHREAD_DESTRUCTORS=On -DCMAKE_CXX_COMPILER=clang++-10 -DCMAKE_C_COMPILER=clang-10"
# Add an extra element to the matrix that does a build with clang 12
# but doesn't run tests.
- os: "freebsd-13.0"
variant: Clang 12 (Build only)
extra-cmake-flags: "-DCMAKE_CXX_COMPILER=clang++12"
build-only: yes
- os: ubuntu-latest
- os: "ubuntu-latest"
variant: Clang 10 libstdc++ (Build only)
dependencies: "sudo apt install ninja-build"
extra-cmake-flags: "-DCMAKE_CXX_COMPILER=clang++-10 -DCMAKE_C_COMPILER=clang-10 -DCMAKE_CXX_FLAGS=-stdlib=libstdc++"

View File

@@ -19,6 +19,7 @@ option(SNMALLOC_QEMU_WORKAROUND "Disable using madvise(DONT_NEED) to zero memory
option(SNMALLOC_OPTIMISE_FOR_CURRENT_MACHINE "Compile for current machine architecture" Off)
set(SNMALLOC_STATIC_LIBRARY_PREFIX "sn_" CACHE STRING "Static library function prefix")
option(SNMALLOC_USE_CXX17 "Build as C++17 for legacy support." OFF)
option(SNMALLOC_USE_PTHREAD_DESTRUCTORS "Build using pthread destructors. Reduces the system dependencies, but may interact badly with C++ on some platforms." OFF)
# malloc.h will error if you include it on FreeBSD, so this test must not
# unconditionally include it.
@@ -150,6 +151,10 @@ if(SNMALLOC_PLATFORM_HAS_GETENTROPY)
target_compile_definitions(snmalloc_lib INTERFACE -DSNMALLOC_PLATFORM_HAS_GETENTROPY)
endif()
if(SNMALLOC_USE_PTHREAD_DESTRUCTORS)
target_compile_definitions(snmalloc_lib INTERFACE -DSNMALLOC_USE_PTHREAD_DESTRUCTORS)
endif()
if(CONST_QUALIFIED_MALLOC_USABLE_SIZE)
target_compile_definitions(snmalloc_lib INTERFACE -DMALLOC_USABLE_SIZE_QUALIFIER=const)
endif()

View File

@@ -19,6 +19,7 @@
# if defined(SNMALLOC_THREAD_TEARDOWN_DEFINED)
# error At most one out of method of thread teardown can be specified.
# else
# include <pthread.h>
# define SNMALLOC_THREAD_TEARDOWN_DEFINED
# endif
#endif
@@ -95,7 +96,7 @@ namespace snmalloc
}
};
# ifdef SNMALLOC_USE_PTHREAD_DESTRUCTOR
# ifdef SNMALLOC_USE_PTHREAD_DESTRUCTORS
/**
* Used to give correct signature to teardown required by pthread_key.
*/

View File

@@ -1,3 +1,7 @@
#ifdef SNMALLOC_USE_PTHREAD_DESTRUCTORS
# undef SNMALLOC_USE_PTHREAD_DESTRUCTORS
#endif
#include <snmalloc_core.h>
#include <test/setup.h>