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

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

Issue 1748953003: - Add assertions in MutexLocker/MonitorLocker to ensure that the code enclosed (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: code-review-comments Created 4 years, 9 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 | « runtime/vm/os_thread_linux.cc ('k') | runtime/vm/os_thread_win.cc » ('j') | 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 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" // NOLINT 5 #include "platform/globals.h" // NOLINT
6 #if defined(TARGET_OS_MACOS) 6 #if defined(TARGET_OS_MACOS)
7 7
8 #include "vm/os_thread.h" 8 #include "vm/os_thread.h"
9 9
10 #include <sys/errno.h> // NOLINT 10 #include <sys/errno.h> // NOLINT
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 #endif // defined(DEBUG) 328 #endif // defined(DEBUG)
329 329
330 int result = pthread_mutex_destroy(data_.mutex()); 330 int result = pthread_mutex_destroy(data_.mutex());
331 VALIDATE_PTHREAD_RESULT(result); 331 VALIDATE_PTHREAD_RESULT(result);
332 332
333 result = pthread_cond_destroy(data_.cond()); 333 result = pthread_cond_destroy(data_.cond());
334 VALIDATE_PTHREAD_RESULT(result); 334 VALIDATE_PTHREAD_RESULT(result);
335 } 335 }
336 336
337 337
338 bool Monitor::TryEnter() {
339 int result = pthread_mutex_trylock(data_.mutex());
340 // Return false if the lock is busy and locking failed.
341 if ((result == EBUSY) || (result == EDEADLK)) {
342 return false;
343 }
344 ASSERT_PTHREAD_SUCCESS(result); // Verify no other errors.
345 #if defined(DEBUG)
346 // When running with assertions enabled we track the owner.
347 ASSERT(owner_ == OSThread::kInvalidThreadId);
348 owner_ = OSThread::GetCurrentThreadId();
349 #endif // defined(DEBUG)
350 return true;
351 }
352
353
338 void Monitor::Enter() { 354 void Monitor::Enter() {
339 int result = pthread_mutex_lock(data_.mutex()); 355 int result = pthread_mutex_lock(data_.mutex());
340 VALIDATE_PTHREAD_RESULT(result); 356 VALIDATE_PTHREAD_RESULT(result);
341 357
342 #if defined(DEBUG) 358 #if defined(DEBUG)
343 // When running with assertions enabled we track the owner. 359 // When running with assertions enabled we track the owner.
344 ASSERT(owner_ == OSThread::kInvalidThreadId); 360 ASSERT(owner_ == OSThread::kInvalidThreadId);
345 owner_ = OSThread::GetCurrentThreadId(); 361 owner_ = OSThread::GetCurrentThreadId();
346 #endif // defined(DEBUG) 362 #endif // defined(DEBUG)
347 } 363 }
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 void Monitor::NotifyAll() { 434 void Monitor::NotifyAll() {
419 // When running with assertions enabled we track the owner. 435 // When running with assertions enabled we track the owner.
420 ASSERT(IsOwnedByCurrentThread()); 436 ASSERT(IsOwnedByCurrentThread());
421 int result = pthread_cond_broadcast(data_.cond()); 437 int result = pthread_cond_broadcast(data_.cond());
422 VALIDATE_PTHREAD_RESULT(result); 438 VALIDATE_PTHREAD_RESULT(result);
423 } 439 }
424 440
425 } // namespace dart 441 } // namespace dart
426 442
427 #endif // defined(TARGET_OS_MACOS) 443 #endif // defined(TARGET_OS_MACOS)
OLDNEW
« no previous file with comments | « runtime/vm/os_thread_linux.cc ('k') | runtime/vm/os_thread_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698