OLD | NEW |
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 #import <Foundation/Foundation.h> | 7 #import <Foundation/Foundation.h> |
8 #include <dlfcn.h> | 8 #include <dlfcn.h> |
9 #include <mach/mach.h> | 9 #include <mach/mach.h> |
10 #include <mach/mach_time.h> | 10 #include <mach/mach_time.h> |
11 #include <mach/thread_policy.h> | 11 #include <mach/thread_policy.h> |
12 | 12 |
13 #include "base/lazy_instance.h" | 13 #include "base/lazy_instance.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/threading/thread_id_name_manager.h" |
15 #include "base/threading/thread_local.h" | 16 #include "base/threading/thread_local.h" |
16 #include "base/tracked_objects.h" | 17 #include "base/tracked_objects.h" |
17 | 18 |
18 namespace base { | 19 namespace base { |
19 | 20 |
20 namespace { | 21 namespace { |
21 | 22 |
22 LazyInstance<ThreadLocalPointer<char> >::Leaky | 23 LazyInstance<ThreadLocalPointer<char> >::Leaky |
23 current_thread_name = LAZY_INSTANCE_INITIALIZER; | 24 current_thread_name = LAZY_INSTANCE_INITIALIZER; |
24 | 25 |
(...skipping 18 matching lines...) Expand all Loading... |
43 | 44 |
44 DCHECK([NSThread isMultiThreaded]); | 45 DCHECK([NSThread isMultiThreaded]); |
45 } | 46 } |
46 } | 47 } |
47 | 48 |
48 // static | 49 // static |
49 void PlatformThread::SetName(const char* name) { | 50 void PlatformThread::SetName(const char* name) { |
50 current_thread_name.Pointer()->Set(const_cast<char*>(name)); | 51 current_thread_name.Pointer()->Set(const_cast<char*>(name)); |
51 tracked_objects::ThreadData::InitializeThreadContext(name); | 52 tracked_objects::ThreadData::InitializeThreadContext(name); |
52 | 53 |
| 54 ThreadIdNameManager::GetInstance()->SetNameForId(CurrentId(), name); |
| 55 |
53 // pthread_setname_np is only available in 10.6 or later, so test | 56 // pthread_setname_np is only available in 10.6 or later, so test |
54 // for it at runtime. | 57 // for it at runtime. |
55 int (*dynamic_pthread_setname_np)(const char*); | 58 int (*dynamic_pthread_setname_np)(const char*); |
56 *reinterpret_cast<void**>(&dynamic_pthread_setname_np) = | 59 *reinterpret_cast<void**>(&dynamic_pthread_setname_np) = |
57 dlsym(RTLD_DEFAULT, "pthread_setname_np"); | 60 dlsym(RTLD_DEFAULT, "pthread_setname_np"); |
58 if (!dynamic_pthread_setname_np) | 61 if (!dynamic_pthread_setname_np) |
59 return; | 62 return; |
60 | 63 |
61 // Mac OS X does not expose the length limit of the name, so | 64 // Mac OS X does not expose the length limit of the name, so |
62 // hardcode it. | 65 // hardcode it. |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 case kThreadPriority_Normal: | 184 case kThreadPriority_Normal: |
182 SetPriorityNormal(mach_thread_id); | 185 SetPriorityNormal(mach_thread_id); |
183 break; | 186 break; |
184 case kThreadPriority_RealtimeAudio: | 187 case kThreadPriority_RealtimeAudio: |
185 SetPriorityRealtimeAudio(mach_thread_id); | 188 SetPriorityRealtimeAudio(mach_thread_id); |
186 break; | 189 break; |
187 } | 190 } |
188 } | 191 } |
189 | 192 |
190 } // namespace base | 193 } // namespace base |
OLD | NEW |