lh2debug commented on code in PR #3140:
URL: https://github.com/apache/brpc/pull/3140#discussion_r2522397911


##########
src/brpc/span.cpp:
##########
@@ -37,9 +37,97 @@
 
 #define BRPC_SPAN_INFO_SEP "\1"
 
-
 namespace brpc {
 
+// Callback for creating a new bthread span when creating a new bthread.
+// This is called by bthread layer when BTHREAD_INHERIT_SPAN flag is set.
+// Returns a heap-allocated weak_ptr<Span>* as void*, or NULL if span creation 
fails.
+void* CreateBthreadSpanAsVoid() {
+    const int64_t received_us = butil::cpuwide_time_us();
+    const int64_t base_realtime = butil::gettimeofday_us() - received_us;
+    std::shared_ptr<Span> span = Span::CreateBthreadSpan("Bthread", 
base_realtime);
+
+    if (!span) {
+        return NULL;
+    }
+    return new std::weak_ptr<Span>(span);

Review Comment:
   My earliest version used the `weak_ptr` type for `rpcz_parent_span` within 
`LocalStorage` because your team offered a very reasonable optimization reason: 
bthreads shouldn't depend on brpc. Therefore, `rpcz_parent_span` needed to 
retain its original `void*` type. The brpc layer provides manual `new/delete` 
management of `weak_ptr` for the bthread layer to register and use.
   
   Therefore, during the bthread's lifecycle, the `weak_ptr` lifecycle of 
`rpcz_parent_span` needs to be manually managed using `new/delete` (i.e., `new` 
when the bthread is created, and `delete` when the bthread ends).



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to