Skip to content

Commit ca93c31

Browse files
committed
scheduling: auto-detect scheduling group key rename() method
make_scheduling_group_key_config() is able to create a fully functional scheduling_group_key_config, apart from the rename() method. Provide for that by detecting if the type has a rename() method and if so, create a thunk for it. This is kept optional for backward compatibility.
1 parent 19dbc3e commit ca93c31

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

include/seastar/core/scheduling.hh

+8
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,9 @@ SEASTAR_MODULE_EXPORT_BEGIN
238238
* This configuration is used by the infrastructure to allocate memory for the values
239239
* and initialize or deinitialize them when they are created or destroyed.
240240
*
241+
* If the type T has a member function T::rename()
242+
* then it will be called after the scheduling group is renamed.
243+
*
241244
* @tparam T - the type for the newly created value.
242245
* @tparam ...ConstructorArgs - the types for the constructor parameters (should be deduced)
243246
* @param args - The parameters for the constructor.
@@ -255,6 +258,11 @@ make_scheduling_group_key_config(ConstructorArgs... args) {
255258
sgkc.destructor = [] (void* p) {
256259
static_cast<T*>(p)->~T();
257260
};
261+
if constexpr (requires(T key) { key.rename(); }) {
262+
sgkc.rename = [] (void* p) {
263+
static_cast<T*>(p)->rename();
264+
};
265+
}
258266
return sgkc;
259267
}
260268

tests/unit/scheduling_group_test.cc

-3
Original file line numberDiff line numberDiff line change
@@ -305,9 +305,6 @@ SEASTAR_THREAD_TEST_CASE(sg_rename_callback) {
305305
};
306306

307307
scheduling_group_key_config key_conf = make_scheduling_group_key_config<value>();
308-
key_conf.rename = [] (void* ptr) {
309-
reinterpret_cast<value*>(ptr)->rename();
310-
};
311308

312309
std::vector<scheduling_group_key> keys;
313310
for (size_t i = 0; i < 3; ++i) {

0 commit comments

Comments
 (0)