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 13 matching lines...) Expand all Loading... |
24 | 24 |
25 namespace internal { | 25 namespace internal { |
26 | 26 |
27 namespace { | 27 namespace { |
28 #if !defined(OS_NACL) | 28 #if !defined(OS_NACL) |
29 const struct sched_param kRealTimePrio = {8}; | 29 const struct sched_param kRealTimePrio = {8}; |
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 {ThreadPriority::BACKGROUND, 10}, |
35 {kThreadPriority_Background, 10}, | 35 {ThreadPriority::NORMAL, 0}, |
36 {kThreadPriority_Normal, 0}, | 36 {ThreadPriority::DISPLAY, -6}, |
37 {kThreadPriority_Display, -6}, | 37 {ThreadPriority::REALTIME_AUDIO, -10}, |
38 }; | 38 }; |
39 | 39 |
40 bool SetThreadPriorityForPlatform(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 | 43 // TODO(gab): Assess the correctness of using |pthread_self()| below instead |
44 // of |handle|. http://crbug.com/468793. | 44 // of |handle|. http://crbug.com/468793. |
45 return priority == kThreadPriority_RealtimeAudio && | 45 return priority == ThreadPriority::REALTIME_AUDIO && |
46 pthread_setschedparam(pthread_self(), SCHED_RR, &kRealTimePrio) == 0; | 46 pthread_setschedparam(pthread_self(), SCHED_RR, &kRealTimePrio) == 0; |
47 #else | 47 #else |
48 return false; | 48 return false; |
49 #endif | 49 #endif |
50 } | 50 } |
51 | 51 |
52 bool GetThreadPriorityForPlatform(PlatformThreadHandle handle, | 52 bool GetThreadPriorityForPlatform(PlatformThreadHandle handle, |
53 ThreadPriority* priority) { | 53 ThreadPriority* priority) { |
54 #if !defined(OS_NACL) | 54 #if !defined(OS_NACL) |
55 int maybe_sched_rr = 0; | 55 int maybe_sched_rr = 0; |
56 struct sched_param maybe_realtime_prio = {0}; | 56 struct sched_param maybe_realtime_prio = {0}; |
57 // TODO(gab): Assess the correctness of using |pthread_self()| below instead | 57 // TODO(gab): Assess the correctness of using |pthread_self()| below instead |
58 // of |handle|. http://crbug.com/468793. | 58 // of |handle|. http://crbug.com/468793. |
59 if (pthread_getschedparam(pthread_self(), &maybe_sched_rr, | 59 if (pthread_getschedparam(pthread_self(), &maybe_sched_rr, |
60 &maybe_realtime_prio) == 0 && | 60 &maybe_realtime_prio) == 0 && |
61 maybe_sched_rr == SCHED_RR && | 61 maybe_sched_rr == SCHED_RR && |
62 maybe_realtime_prio.sched_priority == kRealTimePrio.sched_priority) { | 62 maybe_realtime_prio.sched_priority == kRealTimePrio.sched_priority) { |
63 *priority = kThreadPriority_RealtimeAudio; | 63 *priority = ThreadPriority::REALTIME_AUDIO; |
64 return true; | 64 return true; |
65 } | 65 } |
66 #endif | 66 #endif |
67 return false; | 67 return false; |
68 } | 68 } |
69 | 69 |
70 } // namespace internal | 70 } // namespace internal |
71 | 71 |
72 // static | 72 // static |
73 void PlatformThread::SetName(const char* name) { | 73 void PlatformThread::SetName(const char* name) { |
(...skipping 30 matching lines...) Expand all Loading... |
104 #if !defined(THREAD_SANITIZER) | 104 #if !defined(THREAD_SANITIZER) |
105 return 0; | 105 return 0; |
106 #else | 106 #else |
107 // ThreadSanitizer bloats the stack heavily. Evidence has been that the | 107 // ThreadSanitizer bloats the stack heavily. Evidence has been that the |
108 // default stack size isn't enough for some browser tests. | 108 // default stack size isn't enough for some browser tests. |
109 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). |
110 #endif | 110 #endif |
111 } | 111 } |
112 | 112 |
113 } // namespace base | 113 } // namespace base |
OLD | NEW |