You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@brpc.apache.org by GitBox <gi...@apache.org> on 2022/07/23 09:17:06 UTC

[GitHub] [incubator-brpc] chenBright commented on a diff in pull request #1817: fix additional refrerence can not release when socket is reviving

chenBright commented on code in PR #1817:
URL: https://github.com/apache/incubator-brpc/pull/1817#discussion_r928100985


##########
src/brpc/socket.cpp:
##########
@@ -770,15 +773,22 @@ void Socket::Revive() {
 }
 
 int Socket::ReleaseAdditionalReference() {
-    bool expect = false;
-    // Use `relaxed' fence here since `Dereference' has `released' fence
-    if (_recycle_flag.compare_exchange_strong(
-            expect, true,
+    do {
+        AdditionalRefStatus expect = REF_USING;
+        if (_additional_ref_status.compare_exchange_strong(
+            expect,
+            REF_RECYLED,
             butil::memory_order_relaxed,
             butil::memory_order_relaxed)) {
-        return Dereference();
-    }
-    return -1;
+            return Dereference();
+        }
+
+        if (expect == REF_REVIVING) { // sched_yield to wait until status is not REF_REVIVING
+            sched_yield();

Review Comment:
   当时考虑这个情况很低频,并且_additional_ref_status很快就能从REF_REVIVING变成REF_USING,即使sched_yield do nothing[1]了,应该也不会忙等太久,所以就没考虑wait/wake的实现方案。



-- 
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: dev-unsubscribe@brpc.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org