This is an automated email from the ASF dual-hosted git repository. guangmingchen 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 d0fa1763 Optimize shared_ptr assignment in DoublyBufferedData (#2981) d0fa1763 is described below commit d0fa17634e7c614f8481b21d5525611d618151e4 Author: Chen Chuanle <60637740+git...@users.noreply.github.com> AuthorDate: Sat Jun 7 23:20:20 2025 +0800 Optimize shared_ptr assignment in DoublyBufferedData (#2981) --- src/butil/containers/doubly_buffered_data.h | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/butil/containers/doubly_buffered_data.h b/src/butil/containers/doubly_buffered_data.h index ff96a903..8ba54ac0 100644 --- a/src/butil/containers/doubly_buffered_data.h +++ b/src/butil/containers/doubly_buffered_data.h @@ -484,17 +484,15 @@ int DoublyBufferedData<T, TLS, AllowBthreadSuspended>::Read( // foreground instance, so during the read process, there is // no need to lock mutex and bthread is allowed to be suspended. w->BeginRead(); - int index = -1; - ptr->_data = UnsafeRead(index); - ptr->_index = index; - w->AddRef(index); - ptr->_w = w; + // UnsafeRead will update ptr->_index + ptr->_data = UnsafeRead(ptr->_index); + w->AddRef(ptr->_index); w->BeginReadRelease(); } else { w->BeginRead(); ptr->_data = UnsafeRead(); - ptr->_w = w; } + ptr->_w.swap(w); return 0; } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@brpc.apache.org For additional commands, e-mail: dev-h...@brpc.apache.org