github-actions[bot] commented on code in PR #26567:
URL: https://github.com/apache/doris/pull/26567#discussion_r1385931445


##########
be/src/util/ref_count_closure.h:
##########
@@ -54,4 +54,77 @@ class RefCountClosure : public google::protobuf::Closure {
     std::atomic<int> _refs;
 };
 
+template <typename Response>
+class DummyBrpcCallback {
+    ENABLE_FACTORY_CREATOR(DummyBrpcCallback);
+
+public:
+    void call(std::shared_ptr<Response> rep, std::shared_ptr<brpc::Controller> 
cntl) {}
+};
+
+// The closure will be deleted after callback.
+// It could only be created by using shared ptr or unique ptr.
+// It will hold a weak ptr of T and call run of T
+// Callback() {
+//  xxxx;
+//  public
+//  void run() {
+//      logxxx
+//  }
+//  }
+//
+//  std::shared_ptr<Callback> b;
+//
+//  std::unique_ptr<AutoReleaseClosure> a(b);
+//  brpc_call(a.release());
+
+template <typename Request, typename Response,
+          typename Callback = std::shared_ptr<DummyBrpcCallback<Response>>>
+class AutoReleaseClosure : public google::protobuf::Closure {
+    using Weak = typename Callback::weak_type;
+    ENABLE_FACTORY_CREATOR(AutoReleaseClosure);
+
+public:
+    AutoReleaseClosure(std::shared_ptr<Request> req, std::shared_ptr<Response> 
rep,
+                       Callback callback, bool auto_release)
+            : callback_(callback), auto_release_(auto_release) {}
+    AutoReleaseClosure(std::shared_ptr<Request> req, std::shared_ptr<Response> 
rep,
+                       bool auto_release)
+            : auto_release_(auto_release) {}
+    ~AutoReleaseClosure() override = default;
+
+    //  Will delete itself
+    void Run() override {
+        SCOPED_TRACK_MEMORY_TO_UNKNOWN();
+        Defer defer {[&]() {
+            if (this->auto_release_) {
+                delete this;
+            }
+        }};
+        // If lock failed, it means the callback object is deconstructed, then 
no need
+        // to deal with the callback any more.
+        if (Callback tmp = callback_.lock()) {
+            tmp->call(response_, cntl_);
+        }
+    }
+
+    void join() { brpc::Join(cntl_->call_id()); }
+
+public:

Review Comment:
   warning: redundant access specifier has the same accessibility as the 
previous access specifier [readability-redundant-access-specifiers]
   
   ```suggestion
   
   ```
   <details>
   <summary>Additional context</summary>
   
   **be/src/util/ref_count_closure.h:86:** previously declared here
   ```cpp
   public:
   ^
   ```
   
   </details>
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to