Skip to content

Commit ff83471

Browse files
authored
feat: prepare for scheduling application (#23)
* use unique_ptr as opposed to shared_ptr for better performance * cmake cleanup * transition to a invoke-handler local queue * replace destructor busy wait with cv notify * test cases and bug fixes * clean up script * multithreaded example
1 parent 15ff448 commit ff83471

23 files changed

Lines changed: 929 additions & 459 deletions

File tree

.gitmodules

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
[submodule "extern/Catch2"]
22
path = extern/Catch2
33
url = https://github.com/catchorg/Catch2.git
4+
[submodule "extern/concurrentqueue"]
5+
path = extern/concurrentqueue
6+
url = https://github.com/cameron314/concurrentqueue.git
7+
[submodule "extern/benchmark"]
8+
path = extern/benchmark
9+
url = https://github.com/google/benchmark.git

CMakeLists.txt

Lines changed: 51 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,97 +1,84 @@
11
cmake_minimum_required(VERSION 3.27)
22
cmake_policy(SET CMP0148 NEW)
3+
34
project(pyscheduler VERSION 0.1.0 LANGUAGES CXX)
45

5-
set(CMAKE_CXX_STANDARD 17)
6+
7+
set(CMAKE_CXX_STANDARD 20)
8+
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
69
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
710

8-
# fetch concurrent queue
9-
include(FetchContent)
10-
FetchContent_Declare(
11-
concurrentqueue
12-
GIT_REPOSITORY https://github.com/cameron314/concurrentqueue.git
13-
GIT_TAG master
14-
)
15-
FetchContent_MakeAvailable(concurrentqueue)
11+
include(GNUInstallDirs)
12+
include(CMakePackageConfigHelpers)
13+
14+
set(_pyscheduler_install_cmakedir "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
15+
16+
option(BUILD_EXAMPLES "Build example programs" OFF)
17+
option(BUILD_TESTS "Build test cases" OFF)
18+
option(ENABLE_FP "Enable frame pointer for flamegraph generation" OFF)
19+
option(ENABLE_ASAN "Enable AddressSanitizer" OFF)
20+
option(ENABLE_TSAN "Enable ThreadSanitizer" OFF)
21+
22+
if(ENABLE_ASAN AND ENABLE_TSAN)
23+
message(FATAL_ERROR "ASan and TSan cannot be enabled simultaneously.")
24+
endif()
25+
26+
add_subdirectory(extern/concurrentqueue)
1627

1728
find_package(pybind11 CONFIG REQUIRED)
1829
find_package(Threads REQUIRED)
1930

20-
# create library target
2131
add_library(${PROJECT_NAME} INTERFACE)
32+
add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME})
33+
34+
target_compile_features(${PROJECT_NAME} INTERFACE cxx_std_17)
35+
target_include_directories(${PROJECT_NAME} INTERFACE
36+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
37+
$<INSTALL_INTERFACE:include>
38+
)
2239
target_link_libraries(${PROJECT_NAME} INTERFACE
2340
pybind11::embed
2441
concurrentqueue
2542
Threads::Threads
2643
)
27-
target_include_directories(${PROJECT_NAME} INTERFACE
28-
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
29-
$<INSTALL_INTERFACE:include>
30-
)
31-
32-
# Diagnostic flags
33-
option(ENABLE_GPROF "Enable gprof profiling flags (-pg)" OFF)
34-
option(ENABLE_FP "Enable frame pointer for flamegraph generation" OFF)
35-
option(ENABLE_ASAN "Enable AddressSanitizer" OFF)
36-
option(ENABLE_TSAN "Enable ThreadSanitizer" OFF)
37-
if (ENABLE_ASAN AND ENABLE_TSAN)
38-
message(FATAL_ERROR "ASan and TSan cannot be enabled simultaneously.")
39-
endif()
40-
41-
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
42-
if (ENABLE_GPROF)
43-
message(STATUS "Enabling gprof (-pg)")
44-
add_compile_options(-pg)
45-
add_link_options(-pg)
46-
endif()
47-
48-
if (ENABLE_FP)
49-
message(STATUS "Enabling frame pointer (-fno-omit-frame-pointer)")
50-
add_compile_options(-fno-omit-frame-pointer -g)
51-
if (CMAKE_BUILD_TYPE MATCHES "Debug|RelWithDebInfo")
52-
add_compile_options(-g)
53-
endif()
54-
endif()
5544

56-
if (ENABLE_ASAN)
45+
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
46+
if(ENABLE_ASAN)
5747
message(STATUS "Using AddressSanitizer")
58-
add_compile_options(-fsanitize=address -fno-omit-frame-pointer)
59-
add_link_options(-fsanitize=address)
6048
endif()
61-
62-
if (ENABLE_TSAN)
49+
if(ENABLE_TSAN)
6350
message(STATUS "Using ThreadSanitizer")
64-
add_compile_options(-fsanitize=thread -fno-omit-frame-pointer)
65-
add_link_options(-fsanitize=thread)
6651
endif()
52+
53+
target_compile_options(${PROJECT_NAME} INTERFACE
54+
$<$<BOOL:${ENABLE_FP}>:-fno-omit-frame-pointer>
55+
$<$<AND:$<BOOL:${ENABLE_FP}>,$<CONFIG:Debug,RelWithDebInfo>>:-g>
56+
$<$<BOOL:${ENABLE_ASAN}>:-fsanitize=address;-fno-omit-frame-pointer>
57+
$<$<BOOL:${ENABLE_TSAN}>:-fsanitize=thread;-fno-omit-frame-pointer>
58+
)
59+
target_link_options(${PROJECT_NAME} INTERFACE
60+
$<$<BOOL:${ENABLE_ASAN}>:-fsanitize=address>
61+
$<$<BOOL:${ENABLE_TSAN}>:-fsanitize=thread>
62+
)
6763
endif()
6864

69-
# Build example programs
70-
option(BUILD_EXAMPLES "Build example programs" OFF)
7165
if(BUILD_EXAMPLES)
7266
add_subdirectory(examples)
7367
endif()
7468

75-
# Build test cases
76-
option(BUILD_TESTS "Build test cases" OFF)
7769
if(BUILD_TESTS)
7870
add_subdirectory(extern/Catch2)
71+
set(BENCHMARK_ENABLE_TESTING OFF CACHE BOOL "Disable benchmark internal tests" FORCE)
72+
set(BENCHMARK_ENABLE_GTEST_TESTS OFF CACHE BOOL "Disable benchmark gtest-based tests" FORCE)
73+
add_subdirectory(extern/benchmark)
7974
enable_testing()
8075
add_subdirectory(tests)
8176
endif()
8277

83-
# Install
84-
include(GNUInstallDirs)
85-
include(CMakePackageConfigHelpers)
86-
8778
install(
8879
TARGETS ${PROJECT_NAME}
8980
EXPORT ${PROJECT_NAME}Targets
90-
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} # .so / .dylib
91-
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} # .a
92-
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} # .exe on Windows
93-
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} # for modern CMake
94-
81+
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
9582
)
9683

9784
install(
@@ -104,24 +91,25 @@ install(
10491
EXPORT ${PROJECT_NAME}Targets
10592
FILE ${PROJECT_NAME}Targets.cmake
10693
NAMESPACE ${PROJECT_NAME}::
107-
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
94+
DESTINATION ${_pyscheduler_install_cmakedir}
10895
)
10996

11097
write_basic_package_version_file(
11198
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
11299
VERSION ${PROJECT_VERSION}
113100
COMPATIBILITY AnyNewerVersion
101+
ARCH_INDEPENDENT
114102
)
115103

116104
configure_package_config_file(
117105
"${CMAKE_CURRENT_LIST_DIR}/cmake/Config.cmake.in"
118106
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
119-
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
107+
INSTALL_DESTINATION ${_pyscheduler_install_cmakedir}
120108
)
121109

122110
install(
123111
FILES
124-
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
125-
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
126-
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
112+
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
113+
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
114+
DESTINATION ${_pyscheduler_install_cmakedir}
127115
)

CMakePresets.json

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
{
2+
"version": 6,
3+
"cmakeMinimumRequired": {
4+
"major": 3,
5+
"minor": 27,
6+
"patch": 0
7+
},
8+
"configurePresets": [
9+
{
10+
"name": "base",
11+
"hidden": true,
12+
"binaryDir": "${sourceDir}/build/${presetName}",
13+
"cacheVariables": {
14+
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON",
15+
"BUILD_EXAMPLES": "OFF",
16+
"BUILD_TESTS": "OFF",
17+
"ENABLE_FP": "OFF",
18+
"ENABLE_ASAN": "OFF",
19+
"ENABLE_TSAN": "OFF"
20+
}
21+
},
22+
{
23+
"name": "debug",
24+
"inherits": "base",
25+
"cacheVariables": {
26+
"CMAKE_BUILD_TYPE": "Debug"
27+
}
28+
},
29+
{
30+
"name": "release",
31+
"inherits": "base",
32+
"cacheVariables": {
33+
"CMAKE_BUILD_TYPE": "Release"
34+
}
35+
},
36+
{
37+
"name": "relwithdebinfo",
38+
"inherits": "base",
39+
"cacheVariables": {
40+
"CMAKE_BUILD_TYPE": "RelWithDebInfo"
41+
}
42+
}
43+
],
44+
"buildPresets": [
45+
{
46+
"name": "debug",
47+
"configurePreset": "debug"
48+
},
49+
{
50+
"name": "release",
51+
"configurePreset": "release"
52+
},
53+
{
54+
"name": "relwithdebinfo",
55+
"configurePreset": "relwithdebinfo"
56+
}
57+
]
58+
}

0 commit comments

Comments
 (0)