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 #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 19 matching lines...) Expand all Loading... |
30 #endif | 30 #endif |
31 } // namespace | 31 } // namespace |
32 | 32 |
33 const ThreadPriorityToNiceValuePair kThreadPriorityToNiceValueMap[4] = { | 33 const ThreadPriorityToNiceValuePair kThreadPriorityToNiceValueMap[4] = { |
34 {kThreadPriority_RealtimeAudio, -10}, | 34 {kThreadPriority_RealtimeAudio, -10}, |
35 {kThreadPriority_Background, 10}, | 35 {kThreadPriority_Background, 10}, |
36 {kThreadPriority_Normal, 0}, | 36 {kThreadPriority_Normal, 0}, |
37 {kThreadPriority_Display, -6}, | 37 {kThreadPriority_Display, -6}, |
38 }; | 38 }; |
39 | 39 |
40 bool HandleSetThreadPriorityForPlatform(PlatformThreadHandle handle, | 40 bool SetThreadPriorityForPlatform(PlatformThreadHandle handle, |
41 ThreadPriority priority) { | 41 ThreadPriority priority) { |
42 #if !defined(OS_NACL) | 42 #if !defined(OS_NACL) |
| 43 // TODO(gab): Assess the correctness of using |pthread_self()| below instead |
| 44 // of |handle|. http://crbug.com/468793. |
43 return priority == kThreadPriority_RealtimeAudio && | 45 return priority == kThreadPriority_RealtimeAudio && |
44 pthread_setschedparam(pthread_self(), SCHED_RR, &kRealTimePrio) == 0; | 46 pthread_setschedparam(pthread_self(), SCHED_RR, &kRealTimePrio) == 0; |
45 #else | 47 #else |
46 return false; | 48 return false; |
47 #endif | 49 #endif |
48 } | 50 } |
49 | 51 |
| 52 bool GetThreadPriorityForPlatform(PlatformThreadHandle handle, |
| 53 ThreadPriority* priority) { |
| 54 #if !defined(OS_NACL) |
| 55 int maybe_sched_rr = 0; |
| 56 struct sched_param maybe_realtime_prio = {0}; |
| 57 // TODO(gab): Assess the correctness of using |pthread_self()| below instead |
| 58 // of |handle|. http://crbug.com/468793. |
| 59 if (pthread_getschedparam(pthread_self(), &maybe_sched_rr, |
| 60 &maybe_realtime_prio) == 0 && |
| 61 maybe_sched_rr == SCHED_RR && |
| 62 maybe_realtime_prio.sched_priority == kRealTimePrio.sched_priority) { |
| 63 *priority = kThreadPriority_RealtimeAudio; |
| 64 return true; |
| 65 } |
| 66 #endif |
| 67 return false; |
| 68 } |
| 69 |
50 } // namespace internal | 70 } // namespace internal |
51 | 71 |
52 // static | 72 // static |
53 void PlatformThread::SetName(const char* name) { | 73 void PlatformThread::SetName(const char* name) { |
54 ThreadIdNameManager::GetInstance()->SetName(CurrentId(), name); | 74 ThreadIdNameManager::GetInstance()->SetName(CurrentId(), name); |
55 tracked_objects::ThreadData::InitializeThreadContext(name); | 75 tracked_objects::ThreadData::InitializeThreadContext(name); |
56 | 76 |
57 #if !defined(OS_NACL) | 77 #if !defined(OS_NACL) |
58 // On linux we can get the thread names to show up in the debugger by setting | 78 // On linux we can get the thread names to show up in the debugger by setting |
59 // the process name for the LWP. We don't want to do this for the main | 79 // the process name for the LWP. We don't want to do this for the main |
(...skipping 24 matching lines...) Expand all Loading... |
84 #if !defined(THREAD_SANITIZER) | 104 #if !defined(THREAD_SANITIZER) |
85 return 0; | 105 return 0; |
86 #else | 106 #else |
87 // ThreadSanitizer bloats the stack heavily. Evidence has been that the | 107 // ThreadSanitizer bloats the stack heavily. Evidence has been that the |
88 // default stack size isn't enough for some browser tests. | 108 // default stack size isn't enough for some browser tests. |
89 return 2 * (1 << 23); // 2 times 8192K (the default stack size on Linux). | 109 return 2 * (1 << 23); // 2 times 8192K (the default stack size on Linux). |
90 #endif | 110 #endif |
91 } | 111 } |
92 | 112 |
93 } // namespace base | 113 } // namespace base |
OLD | NEW |