Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Modify the key of scheduling_map to std::string to avoid accessing SeparateScheduling as nullptr during startup #118

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions trpc/runtime/threadmodel/separate/separate_scheduling.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@

namespace trpc {

static std::unordered_map<std::string_view, SeparateSchedulingCreateFunction> scheduling_create_funtion_map;
static std::unordered_map<std::string, SeparateSchedulingCreateFunction> scheduling_create_funtion_map;

bool RegisterSeparateSchedulingImpl(const std::string_view& name, SeparateSchedulingCreateFunction&& func) {
bool RegisterSeparateSchedulingImpl(const std::string& name, SeparateSchedulingCreateFunction&& func) {
scheduling_create_funtion_map[name] = std::move(func);

return true;
}

std::unique_ptr<SeparateScheduling> CreateSeparateScheduling(const std::string_view& name) {
std::unique_ptr<SeparateScheduling> CreateSeparateScheduling(const std::string& name) {
auto it = scheduling_create_funtion_map.find(name);
if (it != scheduling_create_funtion_map.end()) {
return (it->second)();
Expand Down
4 changes: 2 additions & 2 deletions trpc/runtime/threadmodel/separate/separate_scheduling.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ constexpr std::string_view kNonStealScheduling = "non_steal";

constexpr std::string_view kStealScheduling = "steal";

bool RegisterSeparateSchedulingImpl(const std::string_view& name, SeparateSchedulingCreateFunction&& func);
bool RegisterSeparateSchedulingImpl(const std::string& name, SeparateSchedulingCreateFunction&& func);

std::unique_ptr<SeparateScheduling> CreateSeparateScheduling(const std::string_view& name);
std::unique_ptr<SeparateScheduling> CreateSeparateScheduling(const std::string& name);

} // namespace trpc
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class TestSeparateThreadModel : public ::testing::Test {
std::make_unique<separate::NonStealScheduling>(std::move(option));
return sep_sche;
};
RegisterSeparateSchedulingImpl(kNonStealScheduling, std::move(sche_create_func));
RegisterSeparateSchedulingImpl(std::string(kNonStealScheduling), std::move(sche_create_func));

// Register the taskflow scheduler creation function
sche_create_func = []() {
Expand All @@ -70,7 +70,7 @@ class TestSeparateThreadModel : public ::testing::Test {
std::unique_ptr<SeparateScheduling> sep_sche = std::make_unique<separate::StealScheduling>(std::move(option));
return sep_sche;
};
RegisterSeparateSchedulingImpl(kStealScheduling, std::move(sche_create_func));
RegisterSeparateSchedulingImpl(std::string(kStealScheduling), std::move(sche_create_func));
}

static SeparateThreadModel* CreateSeparateThreadModel(ScheduleType type) {
Expand Down
Loading