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

Optimize ParallelChannel AddChannel Interface #2467

Merged
merged 1 commit into from
Dec 25, 2023
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
20 changes: 20 additions & 0 deletions src/brpc/parallel_channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,26 @@ int ParallelChannel::AddChannel(ChannelBase* sub_channel,
return 0;
}

int ParallelChannel::AddChannel(ChannelBase* sub_channel,
ChannelOwnership ownership,
const butil::intrusive_ptr<CallMapper>& call_mapper,
const butil::intrusive_ptr<ResponseMerger>& merger) {
if (NULL == sub_channel) {
LOG(ERROR) << "Param[sub_channel] is NULL";
return -1;
}
if (_chans.capacity() == 0) {
_chans.reserve(32);
}
SubChan sc;
sc.chan = sub_channel;
sc.ownership = ownership;
sc.call_mapper = call_mapper;
sc.merger = merger;
_chans.push_back(sc);
return 0;
}

struct SortByChannelPtr {
bool operator()(const ParallelChannel::SubChan& c1,
const ParallelChannel::SubChan& c2) const {
Expand Down
7 changes: 7 additions & 0 deletions src/brpc/parallel_channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,13 @@ friend class Controller;
CallMapper* call_mapper,
ResponseMerger* response_merger);

// same as AddChannel(... CallMapper* call_mapper, ResponseMerger* response_merger)
// use intrusive_ptr to avoid potential memory leak
int AddChannel(ChannelBase* sub_channel,
ChannelOwnership ownership,
const butil::intrusive_ptr<CallMapper>& call_mapper,
const butil::intrusive_ptr<ResponseMerger>& response_merger);

// Call `method' of the remote service with `request' as input, and
// `response' as output. `controller' contains options and extra data.
// If `done' is not NULL, this method returns after request was sent
Expand Down
Loading