Skip to content

Commit 02512bc

Browse files
gbottesiGuillaume BOTTESIsean-parent
authored
No longer a header-only library. Added support for src files to make it simpler to integrate with dynamic libraries with hidden symbols.
Added .cpp files to hold thread pool and pre-exit support code to avoid duplicates when built as/in a DLL. Declared pre_exit and at_pre_exit as extern "C" to make them simpler to export from a DLL in an export list. Adding an issue to make it simpler to export the default executor as well. --------- Co-authored-by: Guillaume BOTTESI <[email protected]> Co-authored-by: Sean Parent <[email protected]>
1 parent a97f0a3 commit 02512bc

File tree

15 files changed

+212
-120
lines changed

15 files changed

+212
-120
lines changed

CMakeLists.txt

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,7 @@ if((STLAB_MAIN_EXECUTOR STREQUAL "qt6") AND NOT Qt6Core_FOUND)
6969
message(SEND_ERROR "STLAB_MAIN_EXECUTOR is set to \"qt6\", but a Qt6 installation was not found.")
7070
endif()
7171

72-
#
73-
# stlab has no compiled components. As such, we declare it as an `INTERFACE`
74-
# library, which denotes a collection of target propeties to be applied
75-
# transitively to linking targets. In our case, this ammounts to an include
76-
# directory, compile flags, linking flags, and links to system libraries.
77-
#
78-
add_library(stlab INTERFACE)
72+
add_library(stlab)
7973
add_library(stlab::stlab ALIAS stlab)
8074

8175
#
@@ -84,8 +78,8 @@ add_library(stlab::stlab ALIAS stlab)
8478
# on how the configuration under which this library is being consumed.
8579
#
8680
target_include_directories(stlab INTERFACE
87-
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>/include
88-
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}>/include
81+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
82+
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include>
8983
$<INSTALL_INTERFACE:include>)
9084

9185
#
@@ -98,6 +92,7 @@ target_include_directories(stlab INTERFACE
9892
target_compile_definitions(stlab INTERFACE $<$<CXX_COMPILER_ID:MSVC>:NOMINMAX>)
9993

10094
add_subdirectory(include/stlab)
95+
add_subdirectory(src)
10196

10297
if(NOT STLAB_THREAD_SYSTEM STREQUAL "none")
10398
target_link_libraries(stlab INTERFACE Threads::Threads)
@@ -130,16 +125,6 @@ write_basic_package_version_file(
130125
VERSION ${stlab_VERSION}
131126
COMPATIBILITY SameMajorVersion)
132127

133-
#
134-
# As a header-only library, there are no target components to be installed
135-
# directly (the PUBLIC_HEADER property is not white listed for INTERFACE
136-
# targets for some reason).
137-
#
138-
# However, it is worthwhile export our target description in order to later
139-
# generate a CMake configuration file for consumption by CMake's `find_package`
140-
# intrinsic
141-
#
142-
143128
install(
144129
TARGETS stlab
145130
EXPORT stlabTargets

CMakePresets.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,8 @@
144144
"cacheVariables": {
145145
"CMAKE_CXX_STANDARD": "17",
146146
"CMAKE_BUILD_TYPE": "DEBUG",
147-
"CMAKE_CXX_INCLUDE_WHAT_YOU_USE": "include-what-you-use;-Xiwyu;--mapping_file=/usr/local/Cellar/include-what-you-use/0.23/libexec/share/include-what-you-use/boost-all.imp"
147+
"CMAKE_CXX_INCLUDE_WHAT_YOU_USE":
148+
"include-what-you-use;-Xiwyu;--mapping_file=/usr/local/Cellar/include-what-you-use/0.23/libexec/share/include-what-you-use/boost-all.imp"
148149
}
149150
}
150151
],
@@ -170,7 +171,7 @@
170171
"description": "",
171172
"displayName": "",
172173
"configurePreset": "ninja-cpp20-debug-thread-undefined",
173-
"output":{
174+
"output": {
174175
"verbosity": "verbose"
175176
}
176177
}

docs/_data/contributors.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"type": "User",
4242
"user_view_type": "public",
4343
"site_admin": false,
44-
"contributions": 167
44+
"contributions": 170
4545
},
4646
{
4747
"login": "fosterbrereton",

docs/include/stlab/pre_exit.hpp/f_at_pre_exit.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ hyde:
88
- function
99
inline:
1010
brief:
11-
- Register a pre-exit handler. The pre-exit-handler may not throw. With C++17 or later it is required to be `noexcept`.
11+
- Register a pre-exit handler. The `pre-exit-handler` may not throw. With C++17 or later it is required to be `noexcept`.
1212
defined_in_file: stlab/pre_exit.hpp
1313
overloads:
1414
void at_pre_exit(stlab::pre_exit_handler):
@@ -19,10 +19,10 @@ hyde:
1919
description: Register the `pre_exit_handler` to be called on [`pre_exit()`](./f_pre_exit.html). The functions are called in the reverse order that they are registered.
2020
inline:
2121
description:
22-
- Register a pre-exit handler. The pre-exit-handler may not throw. With C++17 or later it is required to be `noexcept`.
22+
- Register a pre-exit handler. The `pre-exit-handler` may not throw. With C++17 or later it is required to be `noexcept`.
2323
return: __OPTIONAL__
2424
signature_with_names: void at_pre_exit(stlab::pre_exit_handler f)
2525
namespace:
2626
- stlab
27-
- v1
27+
- v2
2828
---

docs/include/stlab/pre_exit.hpp/f_pre_exit.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ hyde:
2020
signature_with_names: void pre_exit()
2121
namespace:
2222
- stlab
23-
- v1
23+
- v2
2424
---
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
layout: function
3+
title: stlab_at_pre_exit
4+
hyde:
5+
owner: __MISSING__
6+
brief: __INLINED__
7+
tags:
8+
- function
9+
inline:
10+
brief:
11+
- An `extern "C"` vector for `at_pre-exit()` to make it simpler to export the function from a shared library.
12+
defined_in_file: stlab/pre_exit.hpp
13+
overloads:
14+
void stlab_at_pre_exit(stlab::pre_exit_handler):
15+
arguments:
16+
- description: __OPTIONAL__
17+
name: f
18+
type: stlab::pre_exit_handler
19+
description: __INLINED__
20+
inline:
21+
description:
22+
- An `extern "C"` vector for `at_pre-exit()` to make it simpler to export the function from a shared library.
23+
return: __OPTIONAL__
24+
signature_with_names: void stlab_at_pre_exit(stlab::pre_exit_handler f)
25+
namespace:
26+
- stlab
27+
- v2
28+
---
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
layout: function
3+
title: stlab_pre_exit
4+
hyde:
5+
owner: __MISSING__
6+
brief: __INLINED__
7+
tags:
8+
- function
9+
inline:
10+
brief:
11+
- An `extern "C"` vector for `pre-exit()` to make it simpler to export the function from a shared library.
12+
defined_in_file: stlab/pre_exit.hpp
13+
overloads:
14+
void stlab_pre_exit():
15+
description: __INLINED__
16+
inline:
17+
description:
18+
- An `extern "C"` vector for `pre-exit()` to make it simpler to export the function from a shared library.
19+
return: __OPTIONAL__
20+
signature_with_names: void stlab_pre_exit()
21+
namespace:
22+
- stlab
23+
- v2
24+
---

docs/tools/docker-tools/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ This should leave you at a bash prompt that looks like this:
7575
app@fc7590a63ba3:~$
7676
```
7777

78-
The hex number is the docker image container ID and may be different. Going foreward I refer to this as the _docker_ prompt to distinguish it from the _local_ prompt.
78+
The hex number is the docker image container ID and may be different. Going foreword I refer to this as the _docker_ prompt to distinguish it from the _local_ prompt.
7979

8080
```
8181
cd /mnt/host

include/stlab/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ stlab_generate_config_file()
4444
target_sources( stlab INTERFACE
4545
FILE_SET stlab
4646
TYPE HEADERS
47-
BASE_DIRS ${PROJECT_BINARY_DIR}
47+
BASE_DIRS ${PROJECT_BINARY_DIR}/include
4848
FILES
49-
${PROJECT_BINARY_DIR}/stlab/config.hpp
49+
${PROJECT_BINARY_DIR}/include/stlab/config.hpp
5050
)

include/stlab/concurrency/default_executor.hpp

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,22 @@
1111

1212
#include <stlab/config.hpp>
1313

14-
#include <stlab/pre_exit.hpp>
15-
16-
#include <stlab/concurrency/set_current_thread_name.hpp>
17-
#include <stlab/concurrency/task.hpp>
18-
1914
#include <cassert>
20-
#include <chrono>
2115
#include <cstdint>
22-
#include <functional>
23-
#include <memory>
2416
#include <type_traits>
2517
#include <utility>
2618

2719
#if STLAB_TASK_SYSTEM(LIBDISPATCH)
2820
#include <dispatch/dispatch.h>
2921
#elif STLAB_TASK_SYSTEM(WINDOWS)
22+
#include <stlab/pre_exit.hpp>
23+
3024
#include <Windows.h>
3125
#include <memory>
3226
#elif STLAB_TASK_SYSTEM(PORTABLE)
27+
#include <stlab/concurrency/set_current_thread_name.hpp>
28+
#include <stlab/concurrency/task.hpp>
29+
3330
#include <algorithm>
3431
#include <atomic>
3532
#include <climits>
@@ -79,17 +76,7 @@ struct group_t {
7976
}
8077
};
8178

82-
inline auto group() -> group_t& {
83-
// Use an immediately executed lambda to atomically register pre-exit handler
84-
// and create the dispatch group.
85-
static group_t g{[] {
86-
at_pre_exit([]() noexcept { // <br>
87-
dispatch_group_wait(g._group, DISPATCH_TIME_FOREVER);
88-
});
89-
return group_t{};
90-
}()};
91-
return g;
92-
}
79+
group_t& group();
9380

9481
template <executor_priority P = executor_priority::medium>
9582
struct executor_type {
@@ -452,15 +439,7 @@ class priority_task_system {
452439
/// Returns an instance of the task system singleton. An immediately executed lambda is used
453440
/// to register the the task system for tear down pre-exit in a thread safe manner.
454441

455-
inline priority_task_system& pts() {
456-
// Uses the `nullptr` constructor with an immediate executed lambda to register the task
457-
// system in a thread safe manner.
458-
static priority_task_system only_task_system{[] {
459-
at_pre_exit([]() noexcept { only_task_system.join(); });
460-
return nullptr;
461-
}()};
462-
return only_task_system;
463-
}
442+
priority_task_system& pts();
464443

465444
#endif
466445

0 commit comments

Comments
 (0)