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

Side by Side Diff: base/threading/platform_thread_posix.cc

Issue 14634009: Move Thread Name Mapping into ThreadFunc. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 7 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 | Annotate | Revision Log
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 <errno.h> 7 #include <errno.h>
8 #include <sched.h> 8 #include <sched.h>
9 9
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
(...skipping 28 matching lines...) Expand all
39 #if defined(OS_MACOSX) 39 #if defined(OS_MACOSX)
40 void InitThreading(); 40 void InitThreading();
41 #endif 41 #endif
42 42
43 namespace { 43 namespace {
44 44
45 struct ThreadParams { 45 struct ThreadParams {
46 PlatformThread::Delegate* delegate; 46 PlatformThread::Delegate* delegate;
47 bool joinable; 47 bool joinable;
48 ThreadPriority priority; 48 ThreadPriority priority;
49 PlatformThreadHandle* thread_handle;
49 }; 50 };
50 51
51 void SetCurrentThreadPriority(ThreadPriority priority) { 52 void SetCurrentThreadPriority(ThreadPriority priority) {
52 #if defined(OS_LINUX) || defined(OS_ANDROID) 53 #if defined(OS_LINUX) || defined(OS_ANDROID)
53 switch (priority) { 54 switch (priority) {
54 case kThreadPriority_Normal: 55 case kThreadPriority_Normal:
55 NOTREACHED() << "Don't reset priority as not all processes can."; 56 NOTREACHED() << "Don't reset priority as not all processes can.";
56 break; 57 break;
57 case kThreadPriority_RealtimeAudio: 58 case kThreadPriority_RealtimeAudio:
58 #if defined(OS_LINUX) 59 #if defined(OS_LINUX)
(...skipping 25 matching lines...) Expand all
84 #endif 85 #endif
85 ThreadParams* thread_params = static_cast<ThreadParams*>(params); 86 ThreadParams* thread_params = static_cast<ThreadParams*>(params);
86 PlatformThread::Delegate* delegate = thread_params->delegate; 87 PlatformThread::Delegate* delegate = thread_params->delegate;
87 if (!thread_params->joinable) 88 if (!thread_params->joinable)
88 base::ThreadRestrictions::SetSingletonAllowed(false); 89 base::ThreadRestrictions::SetSingletonAllowed(false);
89 90
90 // If there is a non-default priority for this thread, set it now. 91 // If there is a non-default priority for this thread, set it now.
91 if (thread_params->priority != kThreadPriority_Normal) 92 if (thread_params->priority != kThreadPriority_Normal)
92 SetCurrentThreadPriority(thread_params->priority); 93 SetCurrentThreadPriority(thread_params->priority);
93 94
95 ThreadIdNameManager::GetInstance()->RegisterThread(
96 thread_params->thread_handle,
97 PlatformThread::CurrentId());
98
94 delete thread_params; 99 delete thread_params;
95 delegate->ThreadMain(); 100 delegate->ThreadMain();
96 #if defined(OS_ANDROID) 101 #if defined(OS_ANDROID)
97 base::android::DetachFromVM(); 102 base::android::DetachFromVM();
98 #endif 103 #endif
99 return NULL; 104 return NULL;
100 } 105 }
101 106
102 bool CreateThread(size_t stack_size, bool joinable, 107 bool CreateThread(size_t stack_size, bool joinable,
103 PlatformThread::Delegate* delegate, 108 PlatformThread::Delegate* delegate,
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 } 153 }
149 #endif // OS_MACOSX && !OS_IOS 154 #endif // OS_MACOSX && !OS_IOS
150 155
151 if (stack_size > 0) 156 if (stack_size > 0)
152 pthread_attr_setstacksize(&attributes, stack_size); 157 pthread_attr_setstacksize(&attributes, stack_size);
153 158
154 ThreadParams* params = new ThreadParams; 159 ThreadParams* params = new ThreadParams;
155 params->delegate = delegate; 160 params->delegate = delegate;
156 params->joinable = joinable; 161 params->joinable = joinable;
157 params->priority = priority; 162 params->priority = priority;
163 params->thread_handle = thread_handle;
158 164
159 int err = pthread_create(thread_handle, &attributes, ThreadFunc, params); 165 int err = pthread_create(thread_handle, &attributes, ThreadFunc, params);
160 success = !err; 166 success = !err;
161 if (!success) { 167 if (!success) {
162 errno = err; 168 errno = err;
163 PLOG(ERROR) << "pthread_create"; 169 PLOG(ERROR) << "pthread_create";
164 } 170 }
165 171
166 pthread_attr_destroy(&attributes); 172 pthread_attr_destroy(&attributes);
167 if (!success) 173 if (!success)
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 } 301 }
296 #endif 302 #endif
297 303
298 #if defined(OS_ANDROID) 304 #if defined(OS_ANDROID)
299 bool RegisterThreadUtils(JNIEnv* env) { 305 bool RegisterThreadUtils(JNIEnv* env) {
300 return RegisterNativesImpl(env); 306 return RegisterNativesImpl(env);
301 } 307 }
302 #endif // defined(OS_ANDROID) 308 #endif // defined(OS_ANDROID)
303 309
304 } // namespace base 310 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698