This is an automated email from the ASF dual-hosted git repository.
serverglen pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/brpc.git
The following commit(s) were added to refs/heads/master by this push:
new d6f6f7cf Optimize ParallelChannel AddChannel Interface (#2467)
d6f6f7cf is described below
commit d6f6f7cf6f38ecf9cba5dca9481444325478a56b
Author: miko song <[email protected]>
AuthorDate: Mon Dec 25 10:12:43 2023 +0800
Optimize ParallelChannel AddChannel Interface (#2467)
---
src/brpc/parallel_channel.cpp | 20 ++++++++++++++++++++
src/brpc/parallel_channel.h | 7 +++++++
2 files changed, 27 insertions(+)
diff --git a/src/brpc/parallel_channel.cpp b/src/brpc/parallel_channel.cpp
index ca71bedc..c6972211 100644
--- a/src/brpc/parallel_channel.cpp
+++ b/src/brpc/parallel_channel.cpp
@@ -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 {
diff --git a/src/brpc/parallel_channel.h b/src/brpc/parallel_channel.h
index aa2739a2..df85c9ac 100644
--- a/src/brpc/parallel_channel.h
+++ b/src/brpc/parallel_channel.h
@@ -218,6 +218,13 @@ public:
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
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]