Skip to content

Commit

Permalink
scheduling: auto-detect scheduling group key rename() method
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
avikivity committed Jan 22, 2025
1 parent 19dbc3e commit ca93c31
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
8 changes: 8 additions & 0 deletions include/seastar/core/scheduling.hh
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,9 @@ SEASTAR_MODULE_EXPORT_BEGIN
* This configuration is used by the infrastructure to allocate memory for the values
* and initialize or deinitialize them when they are created or destroyed.
*
* If the type T has a member function T::rename()
* then it will be called after the scheduling group is renamed.
*
* @tparam T - the type for the newly created value.
* @tparam ...ConstructorArgs - the types for the constructor parameters (should be deduced)
* @param args - The parameters for the constructor.
Expand All @@ -255,6 +258,11 @@ make_scheduling_group_key_config(ConstructorArgs... args) {
sgkc.destructor = [] (void* p) {
static_cast<T*>(p)->~T();
};
if constexpr (requires(T key) { key.rename(); }) {
sgkc.rename = [] (void* p) {
static_cast<T*>(p)->rename();
};
}
return sgkc;
}

Expand Down
3 changes: 0 additions & 3 deletions tests/unit/scheduling_group_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,6 @@ SEASTAR_THREAD_TEST_CASE(sg_rename_callback) {
};

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

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

0 comments on commit ca93c31

Please sign in to comment.