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

Side by Side Diff: base/threading/platform_thread_win.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
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/threading/platform_thread.h" 5 #include "base/threading/platform_thread.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/debug/alias.h" 9 #include "base/debug/alias.h"
10 #include "base/debug/profiler.h" 10 #include "base/debug/profiler.h"
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 // static 155 // static
156 void PlatformThread::Sleep(TimeDelta duration) { 156 void PlatformThread::Sleep(TimeDelta duration) {
157 // When measured with a high resolution clock, Sleep() sometimes returns much 157 // When measured with a high resolution clock, Sleep() sometimes returns much
158 // too early. We may need to call it repeatedly to get the desired duration. 158 // too early. We may need to call it repeatedly to get the desired duration.
159 TimeTicks end = TimeTicks::Now() + duration; 159 TimeTicks end = TimeTicks::Now() + duration;
160 for (TimeTicks now = TimeTicks::Now(); now < end; now = TimeTicks::Now()) 160 for (TimeTicks now = TimeTicks::Now(); now < end; now = TimeTicks::Now())
161 ::Sleep(static_cast<DWORD>((end - now).InMillisecondsRoundedUp())); 161 ::Sleep(static_cast<DWORD>((end - now).InMillisecondsRoundedUp()));
162 } 162 }
163 163
164 // static 164 // static
165 void PlatformThread::SetName(const std::string& name) { 165 void PlatformThread::SetName(const std::string& name, bool is_worker_thread) {
166 ThreadIdNameManager::GetInstance()->SetName(CurrentId(), name); 166 ThreadIdNameManager::GetInstance()->SetName(CurrentId(), name);
167 167
168 // On Windows only, we don't need to tell the profiler about the "BrokerEvent" 168 // On Windows only, we don't need to tell the profiler about the "BrokerEvent"
169 // thread, as it exists only in the chrome.exe image, and never spawns or runs 169 // thread, as it exists only in the chrome.exe image, and never spawns or runs
170 // tasks (items which could be profiled). This test avoids the notification, 170 // tasks (items which could be profiled). This test avoids the notification,
171 // which would also (as a side effect) initialize the profiler in this unused 171 // which would also (as a side effect) initialize the profiler in this unused
172 // context, including setting up thread local storage, etc. The performance 172 // context, including setting up thread local storage, etc. The performance
173 // impact is not terrible, but there is no reason to do initialize it. 173 // impact is not terrible, but there is no reason to do initialize it.
174 if (name != "BrokerEvent") 174 if (name != "BrokerEvent")
175 tracked_objects::ThreadData::InitializeThreadContext(name); 175 tracked_objects::ThreadData::InitializeThreadContext(name,
176 is_worker_thread);
176 177
177 // The debugger needs to be around to catch the name in the exception. If 178 // The debugger needs to be around to catch the name in the exception. If
178 // there isn't a debugger, we are just needlessly throwing an exception. 179 // there isn't a debugger, we are just needlessly throwing an exception.
179 // If this image file is instrumented, we raise the exception anyway 180 // If this image file is instrumented, we raise the exception anyway
180 // to provide the profiler with human-readable thread names. 181 // to provide the profiler with human-readable thread names.
181 if (!::IsDebuggerPresent() && !base::debug::IsBinaryInstrumented()) 182 if (!::IsDebuggerPresent() && !base::debug::IsBinaryInstrumented())
182 return; 183 return;
183 184
184 SetNameInternal(CurrentId(), name.c_str()); 185 SetNameInternal(CurrentId(), name.c_str());
185 } 186 }
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 return ThreadPriority::REALTIME_AUDIO; 276 return ThreadPriority::REALTIME_AUDIO;
276 case THREAD_PRIORITY_ERROR_RETURN: 277 case THREAD_PRIORITY_ERROR_RETURN:
277 DPCHECK(false) << "GetThreadPriority error"; // Falls through. 278 DPCHECK(false) << "GetThreadPriority error"; // Falls through.
278 default: 279 default:
279 NOTREACHED() << "Unexpected priority: " << priority; 280 NOTREACHED() << "Unexpected priority: " << priority;
280 return ThreadPriority::NORMAL; 281 return ThreadPriority::NORMAL;
281 } 282 }
282 } 283 }
283 284
284 } // namespace base 285 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698