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

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

Issue 434803003: Linux, Android: fix call to setpriority(2). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Only substitute the thread id with 0 when appropriate. Created 6 years, 4 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
« no previous file with comments | « base/threading/platform_thread_android.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 if (err < 0 && errno != EPERM) 68 if (err < 0 && errno != EPERM)
69 DPLOG(ERROR) << "prctl(PR_SET_NAME)"; 69 DPLOG(ERROR) << "prctl(PR_SET_NAME)";
70 #endif // !defined(OS_NACL) 70 #endif // !defined(OS_NACL)
71 } 71 }
72 72
73 // static 73 // static
74 void PlatformThread::SetThreadPriority(PlatformThreadHandle handle, 74 void PlatformThread::SetThreadPriority(PlatformThreadHandle handle,
75 ThreadPriority priority) { 75 ThreadPriority priority) {
76 #if !defined(OS_NACL) 76 #if !defined(OS_NACL)
77 if (priority == kThreadPriority_RealtimeAudio) { 77 if (priority == kThreadPriority_RealtimeAudio) {
78 const struct sched_param kRealTimePrio = { 8 }; 78 const struct sched_param kRealTimePrio = {8};
79 if (pthread_setschedparam(pthread_self(), SCHED_RR, &kRealTimePrio) == 0) { 79 if (pthread_setschedparam(pthread_self(), SCHED_RR, &kRealTimePrio) == 0) {
80 // Got real time priority, no need to set nice level. 80 // Got real time priority, no need to set nice level.
81 return; 81 return;
82 } 82 }
83 } 83 }
84 84
85 // setpriority(2) will set a thread's priority if it is passed a tid as 85 // setpriority(2) should change the whole thread group's (i.e. process)
86 // the 'process identifier', not affecting the rest of the threads in the 86 // priority. however, on linux it will only change the target thread's
87 // process. Setting this priority will only succeed if the user has been 87 // priority. see the bugs section in
88 // granted permission to adjust nice values on the system. 88 // http://man7.org/linux/man-pages/man2/getpriority.2.html.
89 // we prefer using 0 rather than the current thread id since they are
90 // equivalent but it makes sandboxing easier (https://crbug.com/399473).
89 DCHECK_NE(handle.id_, kInvalidThreadId); 91 DCHECK_NE(handle.id_, kInvalidThreadId);
90 const int kNiceSetting = ThreadNiceValue(priority); 92 const int kNiceSetting = ThreadNiceValue(priority);
91 if (setpriority(PRIO_PROCESS, handle.id_, kNiceSetting)) { 93 const PlatformThreadId current_id = PlatformThread::CurrentId();
92 DVPLOG(1) << "Failed to set nice value of thread (" 94 if (setpriority(PRIO_PROCESS,
93 << handle.id_ << ") to " << kNiceSetting; 95 handle.id_ == current_id ? 0 : handle.id_,
96 kNiceSetting)) {
97 DVPLOG(1) << "Failed to set nice value of thread (" << handle.id_ << ") to "
98 << kNiceSetting;
94 } 99 }
95 #endif // !defined(OS_NACL) 100 #endif // !defined(OS_NACL)
96 } 101 }
97 102
98 void InitThreading() {} 103 void InitThreading() {}
99 104
100 void InitOnThread() {} 105 void InitOnThread() {}
101 106
102 void TerminateOnThread() {} 107 void TerminateOnThread() {}
103 108
104 size_t GetDefaultThreadStackSize(const pthread_attr_t& attributes) { 109 size_t GetDefaultThreadStackSize(const pthread_attr_t& attributes) {
105 #if !defined(THREAD_SANITIZER) && !defined(MEMORY_SANITIZER) 110 #if !defined(THREAD_SANITIZER) && !defined(MEMORY_SANITIZER)
106 return 0; 111 return 0;
107 #else 112 #else
108 // ThreadSanitizer bloats the stack heavily. Evidence has been that the 113 // ThreadSanitizer bloats the stack heavily. Evidence has been that the
109 // default stack size isn't enough for some browser tests. 114 // default stack size isn't enough for some browser tests.
110 // MemorySanitizer needs this as a temporary fix for http://crbug.com/353687 115 // MemorySanitizer needs this as a temporary fix for http://crbug.com/353687
111 return 2 * (1 << 23); // 2 times 8192K (the default stack size on Linux). 116 return 2 * (1 << 23); // 2 times 8192K (the default stack size on Linux).
112 #endif 117 #endif
113 } 118 }
114 119
115 } // namespace base 120 } // namespace base
OLDNEW
« no previous file with comments | « base/threading/platform_thread_android.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698