Skip to content

Commit

Permalink
Pass shared_ptr by const reference to avoid ref count increase (micro…
Browse files Browse the repository at this point in the history
  • Loading branch information
tmccrmck authored Apr 29, 2019
1 parent b9c378f commit 2757afb
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion onnxruntime/server/http/predict_request_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void Predict(const std::string& name,
const std::string& version,
const std::string& action,
/* in, out */ HttpContext& context,
std::shared_ptr<ServerEnvironment> env) {
const std::shared_ptr<ServerEnvironment>& env) {
auto logger = env->GetLogger(context.request_id);
LOGS(*logger, INFO) << "Model Name: " << name << ", Version: " << version << ", Action: " << action;

Expand Down
2 changes: 1 addition & 1 deletion onnxruntime/server/http/predict_request_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ void Predict(const std::string& name,
const std::string& version,
const std::string& action,
/* in, out */ HttpContext& context,
std::shared_ptr<ServerEnvironment> env);
const std::shared_ptr<ServerEnvironment>& env);

} // namespace server
} // namespace onnxruntime
8 changes: 4 additions & 4 deletions onnxruntime/server/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ int main(int argc, char* argv[]) {
exit(EXIT_FAILURE);
}

auto env = std::make_shared<server::ServerEnvironment>(config.logging_level);
const auto env = std::make_shared<server::ServerEnvironment>(config.logging_level);
auto logger = env->GetAppLogger();
LOGS(logger, VERBOSE) << "Logging manager initialized.";
LOGS(logger, INFO) << "Model path: " << config.model_path;
Expand All @@ -45,14 +45,14 @@ int main(int argc, char* argv[]) {
server::App app{};

app.RegisterStartup(
[env](const auto& details) -> void {
[&env](const auto& details) -> void {
auto logger = env->GetAppLogger();
LOGS(logger, INFO) << "Listening at: "
<< "http://" << details.address << ":" << details.port;
});

app.RegisterError(
[env](auto& context) -> void {
[&env](auto& context) -> void {
auto logger = env->GetLogger(context.request_id);
LOGS(*logger, VERBOSE) << "Error code: " << context.error_code;
LOGS(*logger, VERBOSE) << "Error message: " << context.error_message;
Expand All @@ -68,7 +68,7 @@ int main(int argc, char* argv[]) {

app.RegisterPost(
R"(/v1/models/([^/:]+)(?:/versions/(\d+))?:(classify|regress|predict))",
[env](const auto& name, const auto& version, const auto& action, auto& context) -> void {
[&env](const auto& name, const auto& version, const auto& action, auto& context) -> void {
server::Predict(name, version, action, context, env);
});

Expand Down

0 comments on commit 2757afb

Please sign in to comment.