Skip to content

Commit

Permalink
Feature: Modify the key of scheduling_map to std::string to avoid acc…
Browse files Browse the repository at this point in the history
…essing SeparateScheduling as nullptr during startup (#118)
  • Loading branch information
yujun411522 authored Mar 8, 2024
1 parent ce53eec commit f0a78df
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
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

0 comments on commit f0a78df

Please sign in to comment.