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/06/23 02:54:08 UTC

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

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


##########
src/brpc/socket.cpp:
##########
@@ -770,12 +773,16 @@ 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,
-            butil::memory_order_relaxed,
-            butil::memory_order_relaxed)) {
+    // wait until status is not REF_REVIVING
+    while (_additional_ref_status.load(butil::memory_order_relaxed) == REF_REVIVING) {
+        bthread_yield();

Review Comment:
   bthread_yield代价太大,且有些上下文可能不适合切换bthread,建议使用sched_yield



##########
src/brpc/socket.cpp:
##########
@@ -770,12 +773,16 @@ 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,
-            butil::memory_order_relaxed,
-            butil::memory_order_relaxed)) {
+    // wait until status is not REF_REVIVING
+    while (_additional_ref_status.load(butil::memory_order_relaxed) == REF_REVIVING) {

Review Comment:
   这个比较最好是放在下面的compare_exchange 失败之后,再判断 expect是否等于REVIVING,如果等于,则yield后重新compare_exchange



-- 
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