Skip to content

Commit

Permalink
use make_shared
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin85421 committed Dec 25, 2024
1 parent f186d61 commit cfc5986
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 7 deletions.
6 changes: 2 additions & 4 deletions src/mock/ray/core_worker/memory_store.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,14 @@ class DefaultCoreWorkerMemoryStoreWithThread : public CoreWorkerMemoryStore {
std::unique_ptr<InstrumentedIOContextWithThread> io_context =
std::make_unique<InstrumentedIOContextWithThread>(
"DefaultCoreWorkerMemoryStoreWithThread");
return std::unique_ptr<DefaultCoreWorkerMemoryStoreWithThread>(
new DefaultCoreWorkerMemoryStoreWithThread(std::move(io_context)));
return std::make_unique<DefaultCoreWorkerMemoryStoreWithThread>(std::move(io_context));
}

static std::shared_ptr<DefaultCoreWorkerMemoryStoreWithThread> CreateShared() {
std::unique_ptr<InstrumentedIOContextWithThread> io_context =
std::make_unique<InstrumentedIOContextWithThread>(
"DefaultCoreWorkerMemoryStoreWithThread");
return std::shared_ptr<DefaultCoreWorkerMemoryStoreWithThread>(
new DefaultCoreWorkerMemoryStoreWithThread(std::move(io_context)));
return std::make_shared<DefaultCoreWorkerMemoryStoreWithThread>(std::move(io_context));
}

~DefaultCoreWorkerMemoryStoreWithThread() { io_context_->Stop(); }
Expand Down
4 changes: 4 additions & 0 deletions src/ray/common/client_connection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ Status ConnectSocketRetry(local_stream_socket &socket,
}

std::shared_ptr<ServerConnection> ServerConnection::Create(local_stream_socket &&socket) {
// C++ limitation: std::make_shared cannot be used because std::shared_ptr cannot invoke
// protected constructors.
std::shared_ptr<ServerConnection> self(new ServerConnection(std::move(socket)));
return self;
}
Expand Down Expand Up @@ -417,6 +419,8 @@ std::shared_ptr<ClientConnection> ClientConnection::Create(
const std::string &debug_label,
const std::vector<std::string> &message_type_enum_names,
int64_t error_message_type) {
// C++ limitation: std::make_shared cannot be used because std::shared_ptr cannot invoke
// protected constructors.
std::shared_ptr<ClientConnection> self(new ClientConnection(message_handler,
std::move(socket),
debug_label,
Expand Down
2 changes: 1 addition & 1 deletion src/ray/common/test_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ std::shared_ptr<RayObject> GenerateRandomObject(
ref.set_object_id(inlined_id.Binary());
refs.push_back(ref);
}
return std::shared_ptr<RayObject>(new RayObject(GenerateRandomBuffer(), nullptr, refs));
return std::make_shared<RayObject>(GenerateRandomBuffer(), nullptr, refs);
}

/// Path to redis server executable binary.
Expand Down
3 changes: 1 addition & 2 deletions src/ray/raylet/node_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -413,8 +413,7 @@ std::shared_ptr<raylet::RayletClient> NodeManager::CreateRayletClient(
rpc::NodeManagerWorkerClient::make(node_info->node_manager_address(),
node_info->node_manager_port(),
client_call_manager);
return std::shared_ptr<raylet::RayletClient>(
new raylet::RayletClient(std::move(grpc_client)));
return std::make_shared<raylet::RayletClient>(std::move(grpc_client));
};

bool NodeManager::IsWorkerDead(const WorkerID &worker_id, const NodeID &node_id) const {
Expand Down
2 changes: 2 additions & 0 deletions src/ray/rpc/node_manager/node_manager_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ class NodeManagerWorkerClient
const std::string &address,
const int port,
ClientCallManager &client_call_manager) {
// C++ limitation: std::make_shared cannot be used because std::shared_ptr cannot invoke
// private constructors.
auto instance = new NodeManagerWorkerClient(address, port, client_call_manager);
return std::shared_ptr<NodeManagerWorkerClient>(instance);
}
Expand Down
4 changes: 4 additions & 0 deletions src/ray/rpc/retryable_grpc_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ class RetryableGrpcClient : public std::enable_shared_from_this<RetryableGrpcCli
uint64_t server_unavailable_timeout_seconds,
std::function<void()> server_unavailable_timeout_callback,
std::string server_name) {
// C++ limitation: std::make_shared cannot be used because std::shared_ptr cannot invoke
// private constructors.
return std::shared_ptr<RetryableGrpcClient>(
new RetryableGrpcClient(std::move(channel),
io_context,
Expand Down Expand Up @@ -267,6 +269,8 @@ RetryableGrpcClient::RetryableGrpcRequest::Create(
};

return std::shared_ptr<RetryableGrpcClient::RetryableGrpcRequest>(
// C++ limitation: std::make_shared cannot be used because std::shared_ptr cannot invoke
// private constructors.
new RetryableGrpcClient::RetryableGrpcRequest(
std::move(executor), std::move(failure_callback), request_bytes, timeout_ms));
}
Expand Down

0 comments on commit cfc5986

Please sign in to comment.