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

Side by Side Diff: runtime/vm/thread_macos.cc

Issue 474913004: - Account for number of pending tasks in old-space collections. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: 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
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "platform/globals.h" 5 #include "platform/globals.h"
6 #if defined(TARGET_OS_MACOS) 6 #if defined(TARGET_OS_MACOS)
7 7
8 #include "vm/thread.h" 8 #include "vm/thread.h"
9 9
10 #include <sys/errno.h> // NOLINT 10 #include <sys/errno.h> // NOLINT
11 #include <sys/types.h> // NOLINT 11 #include <sys/types.h> // NOLINT
12 #include <sys/sysctl.h> // NOLINT 12 #include <sys/sysctl.h> // NOLINT
13 #include <mach/mach_init.h> // NOLINT 13 #include <mach/mach_init.h> // NOLINT
14 #include <mach/mach_host.h> // NOLINT 14 #include <mach/mach_host.h> // NOLINT
15 #include <mach/mach_port.h> // NOLINT 15 #include <mach/mach_port.h> // NOLINT
16 #include <mach/mach_traps.h> // NOLINT 16 #include <mach/mach_traps.h> // NOLINT
17 #include <mach/task_info.h> // NOLINT 17 #include <mach/task_info.h> // NOLINT
18 #include <mach/thread_info.h> // NOLINT 18 #include <mach/thread_info.h> // NOLINT
19 #include <mach/thread_act.h> // NOLINT 19 #include <mach/thread_act.h> // NOLINT
20 20
21 #include "platform/assert.h" 21 #include "platform/assert.h"
22 #include "vm/isolate.h"
22 23
23 namespace dart { 24 namespace dart {
24 25
25 #define VALIDATE_PTHREAD_RESULT(result) \ 26 #define VALIDATE_PTHREAD_RESULT(result) \
26 if (result != 0) { \ 27 if (result != 0) { \
27 const int kBufferSize = 1024; \ 28 const int kBufferSize = 1024; \
28 char error_message[kBufferSize]; \ 29 char error_message[kBufferSize]; \
29 strerror_r(result, error_message, kBufferSize); \ 30 strerror_r(result, error_message, kBufferSize); \
30 FATAL2("pthread error: %d (%s)", result, error_message); \ 31 FATAL2("pthread error: %d (%s)", result, error_message); \
31 } 32 }
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 result = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK); 192 result = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK);
192 VALIDATE_PTHREAD_RESULT(result); 193 VALIDATE_PTHREAD_RESULT(result);
193 #endif // defined(DEBUG) 194 #endif // defined(DEBUG)
194 195
195 result = pthread_mutex_init(data_.mutex(), &attr); 196 result = pthread_mutex_init(data_.mutex(), &attr);
196 // Verify that creating a pthread_mutex succeeded. 197 // Verify that creating a pthread_mutex succeeded.
197 VALIDATE_PTHREAD_RESULT(result); 198 VALIDATE_PTHREAD_RESULT(result);
198 199
199 result = pthread_mutexattr_destroy(&attr); 200 result = pthread_mutexattr_destroy(&attr);
200 VALIDATE_PTHREAD_RESULT(result); 201 VALIDATE_PTHREAD_RESULT(result);
202
203 // When running with assertions enabled we do track the owner.
204 #if defined(DEBUG)
205 owner_ = NULL;
206 #endif // defined(DEBUG)
201 } 207 }
202 208
203 209
204 Mutex::~Mutex() { 210 Mutex::~Mutex() {
205 int result = pthread_mutex_destroy(data_.mutex()); 211 int result = pthread_mutex_destroy(data_.mutex());
206 // Verify that the pthread_mutex was destroyed. 212 // Verify that the pthread_mutex was destroyed.
207 VALIDATE_PTHREAD_RESULT(result); 213 VALIDATE_PTHREAD_RESULT(result);
214
215 // When running with assertions enabled we do track the owner.
216 #if defined(DEBUG)
217 ASSERT(owner_ == NULL);
218 #endif // defined(DEBUG)
208 } 219 }
209 220
210 221
211 void Mutex::Lock() { 222 void Mutex::Lock() {
212 int result = pthread_mutex_lock(data_.mutex()); 223 int result = pthread_mutex_lock(data_.mutex());
213 // Specifically check for dead lock to help debugging. 224 // Specifically check for dead lock to help debugging.
214 ASSERT(result != EDEADLK); 225 ASSERT(result != EDEADLK);
215 ASSERT(result == 0); // Verify no other errors. 226 ASSERT(result == 0); // Verify no other errors.
216 // TODO(iposva): Do we need to track lock owners? 227 // When running with assertions enabled we do track the owner.
228 #if defined(DEBUG)
229 owner_ = Isolate::Current();
230 #endif // defined(DEBUG)
217 } 231 }
218 232
219 233
220 bool Mutex::TryLock() { 234 bool Mutex::TryLock() {
221 int result = pthread_mutex_trylock(data_.mutex()); 235 int result = pthread_mutex_trylock(data_.mutex());
222 // Return false if the lock is busy and locking failed. 236 // Return false if the lock is busy and locking failed.
223 if ((result == EBUSY) || (result == EDEADLK)) { 237 if ((result == EBUSY) || (result == EDEADLK)) {
224 return false; 238 return false;
225 } 239 }
226 ASSERT(result == 0); // Verify no other errors. 240 ASSERT(result == 0); // Verify no other errors.
227 // TODO(iposva): Do we need to track lock owners? 241 // When running with assertions enabled we do track the owner.
242 #if defined(DEBUG)
243 owner_ = Isolate::Current();
244 #endif // defined(DEBUG)
228 return true; 245 return true;
229 } 246 }
230 247
231 248
232 void Mutex::Unlock() { 249 void Mutex::Unlock() {
233 // TODO(iposva): Do we need to track lock owners? 250 // When running with assertions enabled we do track the owner.
251 #if defined(DEBUG)
252 ASSERT(owner_ == Isolate::Current());
253 owner_ = NULL;
254 #endif // defined(DEBUG)
234 int result = pthread_mutex_unlock(data_.mutex()); 255 int result = pthread_mutex_unlock(data_.mutex());
235 // Specifically check for wrong thread unlocking to aid debugging. 256 // Specifically check for wrong thread unlocking to aid debugging.
236 ASSERT(result != EPERM); 257 ASSERT(result != EPERM);
237 ASSERT(result == 0); // Verify no other errors. 258 ASSERT(result == 0); // Verify no other errors.
238 } 259 }
239 260
240 261
241 Monitor::Monitor() { 262 Monitor::Monitor() {
242 pthread_mutexattr_t attr; 263 pthread_mutexattr_t attr;
243 int result = pthread_mutexattr_init(&attr); 264 int result = pthread_mutexattr_init(&attr);
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 347
327 void Monitor::NotifyAll() { 348 void Monitor::NotifyAll() {
328 // TODO(iposva): Do we need to track lock owners? 349 // TODO(iposva): Do we need to track lock owners?
329 int result = pthread_cond_broadcast(data_.cond()); 350 int result = pthread_cond_broadcast(data_.cond());
330 VALIDATE_PTHREAD_RESULT(result); 351 VALIDATE_PTHREAD_RESULT(result);
331 } 352 }
332 353
333 } // namespace dart 354 } // namespace dart
334 355
335 #endif // defined(TARGET_OS_MACOS) 356 #endif // defined(TARGET_OS_MACOS)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698