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

Side by Side 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, 8 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 unified diff | Download patch
« base/threading/platform_thread.h ('K') | « base/tracked_objects.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/tracked_objects.h" 5 #include "base/tracked_objects.h"
6 6
7 #include <limits.h> 7 #include <limits.h>
8 #include <stdlib.h> 8 #include <stdlib.h>
9 9
10 #include "base/atomicops.h" 10 #include "base/atomicops.h"
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 347
348 // static 348 // static
349 ThreadData* ThreadData::first() { 349 ThreadData* ThreadData::first() {
350 base::AutoLock lock(*list_lock_.Pointer()); 350 base::AutoLock lock(*list_lock_.Pointer());
351 return all_thread_data_list_head_; 351 return all_thread_data_list_head_;
352 } 352 }
353 353
354 ThreadData* ThreadData::next() const { return next_; } 354 ThreadData* ThreadData::next() const { return next_; }
355 355
356 // static 356 // static
357 void ThreadData::InitializeThreadContext(const std::string& suggested_name) { 357 void ThreadData::InitializeThreadContext(const std::string& suggested_name,
358 bool is_worker_thread) {
dcheng 2016/04/01 10:52:30 Interesting, the original assumption is that worke
358 Initialize(); 359 Initialize();
359 ThreadData* current_thread_data = 360 ThreadData* current_thread_data =
360 reinterpret_cast<ThreadData*>(tls_index_.Get()); 361 reinterpret_cast<ThreadData*>(tls_index_.Get());
361 if (current_thread_data) 362 if (current_thread_data)
362 return; // Browser tests instigate this. 363 return; // Browser tests instigate this.
363 current_thread_data = new ThreadData(suggested_name); 364
365 if (is_worker_thread) {
dcheng 2016/04/01 10:52:30 Can we just early return at the beginning for work
366 // Try to reuse retired worker thread data first
367 if (first_retired_worker_) {
368 current_thread_data = first_retired_worker_;
369 first_retired_worker_ = first_retired_worker_->next_retired_worker_;
370 current_thread_data->next_retired_worker_ = NULL;
371 } else {
372 int worker_thread_number = ++worker_thread_data_creation_count_;
373 DCHECK_GT(worker_thread_number, 0);
374 current_thread_data = new ThreadData(worker_thread_number);
375 }
376 DCHECK_GT(current_thread_data->worker_thread_number_, 0);
377 }
378 else {
379 current_thread_data = new ThreadData(suggested_name);
380 }
381
382 DCHECK(current_thread_data);
364 tls_index_.Set(current_thread_data); 383 tls_index_.Set(current_thread_data);
365 } 384 }
366 385
367 // static 386 // static
368 ThreadData* ThreadData::Get() { 387 ThreadData* ThreadData::Get() {
369 if (!tls_index_.initialized()) 388 if (!tls_index_.initialized())
370 return NULL; // For unittests only. 389 return NULL; // For unittests only.
371 ThreadData* registered = reinterpret_cast<ThreadData*>(tls_index_.Get()); 390 ThreadData* registered = reinterpret_cast<ThreadData*>(tls_index_.Get());
372 if (registered) 391 if (registered)
373 return registered; 392 return registered;
(...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after
968 #endif 987 #endif
969 } 988 }
970 989
971 ProcessDataSnapshot::ProcessDataSnapshot(const ProcessDataSnapshot& other) = 990 ProcessDataSnapshot::ProcessDataSnapshot(const ProcessDataSnapshot& other) =
972 default; 991 default;
973 992
974 ProcessDataSnapshot::~ProcessDataSnapshot() { 993 ProcessDataSnapshot::~ProcessDataSnapshot() {
975 } 994 }
976 995
977 } // namespace tracked_objects 996 } // namespace tracked_objects
OLDNEW
« 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