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


##########
be/src/runtime/thread_context.h:
##########
@@ -101,63 +113,26 @@ class RuntimeState;
 
 extern bthread_key_t btls_key;
 
-// Using gcc11 compiles thread_local variable on lower versions of GLIBC will 
report an error,
-// see https://github.com/apache/doris/pull/7911
-//
-// If we want to avoid this error,
-// 1. For non-trivial variables in thread_local, such as std::string, you need 
to store them as pointers to
-//    ensure that thread_local is trivial, these non-trivial pointers will 
uniformly call destructors elsewhere.
-// 2. The default destructor of the thread_local variable cannot be overridden.
-//
-// This is difficult to implement. Because the destructor is not overwritten, 
it means that the outside cannot
-// be notified when the thread terminates, and the non-trivial pointers in 
thread_local cannot be released in time.
-// The func provided by pthread and std::thread doesn't help either.
-//
-// So, kudu Class-scoped static thread local implementation was introduced. 
Solve the above problem by
-// Thread-scoped thread local + Class-scoped thread local.
-//
-// This may look very trick, but it's the best way I can find.
-//
-// refer to:
-//  https://gcc.gnu.org/onlinedocs/gcc-3.3.1/gcc/Thread-Local.html
-//  https://stackoverflow.com/questions/12049684/
-//  
https://sourceware.org/glibc/wiki/Destructor%20support%20for%20thread_local%20variables
-//  https://www.jianshu.com/p/756240e837dd
-//  https://man7.org/linux/man-pages/man3/pthread_tryjoin_np.3.html
-class ThreadContextPtr {
-public:
-    ThreadContextPtr();
-    // Cannot add destructor `~ThreadContextPtr`, otherwise it will no longer 
be of type POD, the reason is as above.
-
-    // TCMalloc hook is triggered during ThreadContext construction, which may 
lead to deadlock.
-    bool init = false;
-
-    DECLARE_STATIC_THREAD_LOCAL(ThreadContext, _ptr);
-};
-
-inline thread_local ThreadContextPtr thread_context_ptr;
-
-// To avoid performance problems caused by frequently calling 
`bthread_getspecific` to obtain bthread TLS
-// in tcmalloc hook, cache the key and value of bthread TLS in pthread TLS.
-inline thread_local ThreadContext* bthread_context;
-inline thread_local bthread_t bthread_id;
+// Is true after ThreadContext construction.
+inline thread_local bool pthread_context_ptr_init = false;
+inline thread_local constinit ThreadContext* thread_context_ptr;
+// use mem hook to consume thread mem tracker.
+inline thread_local bool use_mem_hook = false;
 
 // The thread context saves some info about a working thread.
 // 2 required info:
 //   1. thread_id:   Current thread id, Auto generated.
-//   2. type:        The type is a enum value indicating which type of task 
current thread is running.
+//   2. type(abolished):        The type is a enum value indicating which type 
of task current thread is running.
 //                   For example: QUERY, LOAD, COMPACTION, ...
 //   3. task id:     A unique id to identify this task. maybe query id, load 
job id, etc.
+//   4. ThreadMemTrackerMgr
 //
 // There may be other optional info to be added later.
 class ThreadContext {
 public:
-    ThreadContext() {
-        thread_mem_tracker_mgr.reset(new ThreadMemTrackerMgr());
-        if (ExecEnv::ready()) thread_mem_tracker_mgr->init();
-    }
+    ThreadContext() { thread_mem_tracker_mgr = 
std::make_unique<ThreadMemTrackerMgr>(); }

Review Comment:
   warning: use '= default' to define a trivial default constructor 
[modernize-use-equals-default]
   ```cpp
       ThreadContext() { thread_mem_tracker_mgr = 
std::make_unique<ThreadMemTrackerMgr>(); }
       ^
   ```
   



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