OLD | NEW |
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_LINUX) | 6 #if defined(TARGET_OS_LINUX) |
7 | 7 |
8 #include "vm/os_thread.h" | 8 #include "vm/os_thread.h" |
9 | 9 |
10 #include <errno.h> // NOLINT | 10 #include <errno.h> // NOLINT |
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 #endif // defined(DEBUG) | 334 #endif // defined(DEBUG) |
335 | 335 |
336 int result = pthread_mutex_destroy(data_.mutex()); | 336 int result = pthread_mutex_destroy(data_.mutex()); |
337 VALIDATE_PTHREAD_RESULT(result); | 337 VALIDATE_PTHREAD_RESULT(result); |
338 | 338 |
339 result = pthread_cond_destroy(data_.cond()); | 339 result = pthread_cond_destroy(data_.cond()); |
340 VALIDATE_PTHREAD_RESULT(result); | 340 VALIDATE_PTHREAD_RESULT(result); |
341 } | 341 } |
342 | 342 |
343 | 343 |
| 344 bool Monitor::TryEnter() { |
| 345 int result = pthread_mutex_trylock(data_.mutex()); |
| 346 // Return false if the lock is busy and locking failed. |
| 347 if (result == EBUSY) { |
| 348 return false; |
| 349 } |
| 350 ASSERT_PTHREAD_SUCCESS(result); // Verify no other errors. |
| 351 #if defined(DEBUG) |
| 352 // When running with assertions enabled we track the owner. |
| 353 ASSERT(owner_ == OSThread::kInvalidThreadId); |
| 354 owner_ = OSThread::GetCurrentThreadId(); |
| 355 #endif // defined(DEBUG) |
| 356 return true; |
| 357 } |
| 358 |
| 359 |
344 void Monitor::Enter() { | 360 void Monitor::Enter() { |
345 int result = pthread_mutex_lock(data_.mutex()); | 361 int result = pthread_mutex_lock(data_.mutex()); |
346 VALIDATE_PTHREAD_RESULT(result); | 362 VALIDATE_PTHREAD_RESULT(result); |
347 | 363 |
348 #if defined(DEBUG) | 364 #if defined(DEBUG) |
349 // When running with assertions enabled we track the owner. | 365 // When running with assertions enabled we track the owner. |
350 ASSERT(owner_ == OSThread::kInvalidThreadId); | 366 ASSERT(owner_ == OSThread::kInvalidThreadId); |
351 owner_ = OSThread::GetCurrentThreadId(); | 367 owner_ = OSThread::GetCurrentThreadId(); |
352 #endif // defined(DEBUG) | 368 #endif // defined(DEBUG) |
353 } | 369 } |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 void Monitor::NotifyAll() { | 431 void Monitor::NotifyAll() { |
416 // When running with assertions enabled we track the owner. | 432 // When running with assertions enabled we track the owner. |
417 ASSERT(IsOwnedByCurrentThread()); | 433 ASSERT(IsOwnedByCurrentThread()); |
418 int result = pthread_cond_broadcast(data_.cond()); | 434 int result = pthread_cond_broadcast(data_.cond()); |
419 VALIDATE_PTHREAD_RESULT(result); | 435 VALIDATE_PTHREAD_RESULT(result); |
420 } | 436 } |
421 | 437 |
422 } // namespace dart | 438 } // namespace dart |
423 | 439 |
424 #endif // defined(TARGET_OS_LINUX) | 440 #endif // defined(TARGET_OS_LINUX) |
OLD | NEW |