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

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

Issue 10796098: Don't set "unlimited" stacks on iOS (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 5 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
« no previous file with comments | « no previous file | 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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 bool success = false; 80 bool success = false;
81 pthread_attr_t attributes; 81 pthread_attr_t attributes;
82 pthread_attr_init(&attributes); 82 pthread_attr_init(&attributes);
83 83
84 // Pthreads are joinable by default, so only specify the detached attribute if 84 // Pthreads are joinable by default, so only specify the detached attribute if
85 // the thread should be non-joinable. 85 // the thread should be non-joinable.
86 if (!joinable) { 86 if (!joinable) {
87 pthread_attr_setdetachstate(&attributes, PTHREAD_CREATE_DETACHED); 87 pthread_attr_setdetachstate(&attributes, PTHREAD_CREATE_DETACHED);
88 } 88 }
89 89
90 #if defined(OS_MACOSX) 90 #if defined(OS_MACOSX) && !defined(OS_IOS)
91 // The Mac OS X default for a pthread stack size is 512kB. 91 // The Mac OS X default for a pthread stack size is 512kB.
92 // Libc-594.1.4/pthreads/pthread.c's pthread_attr_init uses 92 // Libc-594.1.4/pthreads/pthread.c's pthread_attr_init uses
93 // DEFAULT_STACK_SIZE for this purpose. 93 // DEFAULT_STACK_SIZE for this purpose.
94 // 94 //
95 // 512kB isn't quite generous enough for some deeply recursive threads that 95 // 512kB isn't quite generous enough for some deeply recursive threads that
96 // otherwise request the default stack size by specifying 0. Here, adopt 96 // otherwise request the default stack size by specifying 0. Here, adopt
97 // glibc's behavior as on Linux, which is to use the current stack size 97 // glibc's behavior as on Linux, which is to use the current stack size
98 // limit (ulimit -s) as the default stack size. See 98 // limit (ulimit -s) as the default stack size. See
99 // glibc-2.11.1/nptl/nptl-init.c's __pthread_initialize_minimal_internal. To 99 // glibc-2.11.1/nptl/nptl-init.c's __pthread_initialize_minimal_internal. To
100 // avoid setting the limit below the Mac OS X default or the minimum usable 100 // avoid setting the limit below the Mac OS X default or the minimum usable
101 // stack size, these values are also considered. If any of these values 101 // stack size, these values are also considered. If any of these values
102 // can't be determined, or if stack size is unlimited (ulimit -s unlimited), 102 // can't be determined, or if stack size is unlimited (ulimit -s unlimited),
103 // stack_size is left at 0 to get the system default. 103 // stack_size is left at 0 to get the system default.
104 // 104 //
105 // Mac OS X normally only applies ulimit -s to the main thread stack. On 105 // Mac OS X normally only applies ulimit -s to the main thread stack. On
106 // contemporary OS X and Linux systems alike, this value is generally 8MB 106 // contemporary OS X and Linux systems alike, this value is generally 8MB
107 // or in that neighborhood. 107 // or in that neighborhood.
108 if (stack_size == 0) { 108 if (stack_size == 0) {
109 size_t default_stack_size; 109 size_t default_stack_size;
110 struct rlimit stack_rlimit; 110 struct rlimit stack_rlimit;
111 if (pthread_attr_getstacksize(&attributes, &default_stack_size) == 0 && 111 if (pthread_attr_getstacksize(&attributes, &default_stack_size) == 0 &&
112 getrlimit(RLIMIT_STACK, &stack_rlimit) == 0 && 112 getrlimit(RLIMIT_STACK, &stack_rlimit) == 0 &&
113 stack_rlimit.rlim_cur != RLIM_INFINITY) { 113 stack_rlimit.rlim_cur != RLIM_INFINITY) {
114 stack_size = std::max(std::max(default_stack_size, 114 stack_size = std::max(std::max(default_stack_size,
115 static_cast<size_t>(PTHREAD_STACK_MIN)), 115 static_cast<size_t>(PTHREAD_STACK_MIN)),
116 static_cast<size_t>(stack_rlimit.rlim_cur)); 116 static_cast<size_t>(stack_rlimit.rlim_cur));
117 } 117 }
118 } 118 }
119 #endif // OS_MACOSX 119 #endif // OS_MACOSX && !OS_IOS
120 120
121 if (stack_size > 0) 121 if (stack_size > 0)
122 pthread_attr_setstacksize(&attributes, stack_size); 122 pthread_attr_setstacksize(&attributes, stack_size);
123 123
124 ThreadParams* params = new ThreadParams; 124 ThreadParams* params = new ThreadParams;
125 params->delegate = delegate; 125 params->delegate = delegate;
126 params->joinable = joinable; 126 params->joinable = joinable;
127 success = !pthread_create(thread_handle, &attributes, ThreadFunc, params); 127 success = !pthread_create(thread_handle, &attributes, ThreadFunc, params);
128 128
129 if (priority != kThreadPriority_Normal) { 129 if (priority != kThreadPriority_Normal) {
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 #if !defined(OS_MACOSX) 275 #if !defined(OS_MACOSX)
276 // Mac OS X uses lower-level mach APIs. 276 // Mac OS X uses lower-level mach APIs.
277 277
278 // static 278 // static
279 void PlatformThread::SetThreadPriority(PlatformThreadHandle, ThreadPriority) { 279 void PlatformThread::SetThreadPriority(PlatformThreadHandle, ThreadPriority) {
280 // TODO(crogers): Implement, see http://crbug.com/116172 280 // TODO(crogers): Implement, see http://crbug.com/116172
281 } 281 }
282 #endif 282 #endif
283 283
284 } // namespace base 284 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698