Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2879)

Unified Diff: base/tracked_objects.cc

Issue 1845753006: Don't create redundant ThreadData for Worker Threads (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« base/threading/platform_thread.h ('K') | « base/tracked_objects.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/tracked_objects.cc
diff --git a/base/tracked_objects.cc b/base/tracked_objects.cc
index d24cedf159241d58a92909650de374f187dd85ae..81f17e9bdcb09a2bc44566dc066b64aae9fe536c 100644
--- a/base/tracked_objects.cc
+++ b/base/tracked_objects.cc
@@ -354,13 +354,32 @@ ThreadData* ThreadData::first() {
ThreadData* ThreadData::next() const { return next_; }
// static
-void ThreadData::InitializeThreadContext(const std::string& suggested_name) {
+void ThreadData::InitializeThreadContext(const std::string& suggested_name,
+ bool is_worker_thread) {
dcheng 2016/04/01 10:52:30 Interesting, the original assumption is that worke
Initialize();
ThreadData* current_thread_data =
reinterpret_cast<ThreadData*>(tls_index_.Get());
if (current_thread_data)
return; // Browser tests instigate this.
- current_thread_data = new ThreadData(suggested_name);
+
+ if (is_worker_thread) {
dcheng 2016/04/01 10:52:30 Can we just early return at the beginning for work
+ // Try to reuse retired worker thread data first
+ if (first_retired_worker_) {
+ current_thread_data = first_retired_worker_;
+ first_retired_worker_ = first_retired_worker_->next_retired_worker_;
+ current_thread_data->next_retired_worker_ = NULL;
+ } else {
+ int worker_thread_number = ++worker_thread_data_creation_count_;
+ DCHECK_GT(worker_thread_number, 0);
+ current_thread_data = new ThreadData(worker_thread_number);
+ }
+ DCHECK_GT(current_thread_data->worker_thread_number_, 0);
+ }
+ else {
+ current_thread_data = new ThreadData(suggested_name);
+ }
+
+ DCHECK(current_thread_data);
tls_index_.Set(current_thread_data);
}
« base/threading/platform_thread.h ('K') | « base/tracked_objects.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698