Add multi-thread support

This commit is contained in:
2025-09-06 04:29:50 -07:00
parent 814234603d
commit 97d1b4a701
8 changed files with 277 additions and 151 deletions

View File

@ -1,12 +1,23 @@
cmake_minimum_required(VERSION 3.11)
set(CMAKE_C_STANDARD 99)
set(REFCOUNT_USE_THREADS
ON
CACHE BOOL "Weather or not RefCount should be thread aware.")
if(REFCOUNT_USE_THREADS)
set(CMAKE_C_STANDARD 11)
else()
set(CMAKE_C_STANDARD 99)
endif()
project(
refcount
VERSION 1.0
LANGUAGES C)
# For configuring config.h (I like this name better)
set(REFCOUNT_HAS_THREADS "${REFCOUNT_USE_THREADS}")
include(FetchContent)
FetchContent_Declare(
ht
@ -19,13 +30,17 @@ if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
include(CTest)
endif()
add_compile_options(-fsanitize=address,leak,undefined)
add_link_options(-fsanitize=address,leak,undefined)
# add_compile_options(-fsanitize=address,leak,undefined)
# add_link_options(-fsanitize=address,leak,undefined)
configure_file(include/refcount/config.h.in include/refcount/config.h @ONLY)
add_library(refcount src/allocator.c src/list.c src/refcount.c)
target_link_libraries(refcount PUBLIC ht)
target_include_directories(refcount PUBLIC include/)
target_compile_options(refcount PRIVATE -Wall -Wpedantic)
target_include_directories(refcount
PUBLIC "${CMAKE_CURRENT_BINARY_DIR}/include")
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING)
add_subdirectory(test/)