Skip to content

Commit

Permalink
Optimize ParallelChannel AddChannel Interface
Browse files Browse the repository at this point in the history
  • Loading branch information
sinomiko committed Dec 6, 2023
1 parent dc9e786 commit 6ccea9d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
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

0 comments on commit 6ccea9d

Please sign in to comment.