| Index: runtime/vm/os_thread_macos.cc
|
| diff --git a/runtime/vm/os_thread_macos.cc b/runtime/vm/os_thread_macos.cc
|
| index e7c7c90878908369333f7b1a7915f411cf01fdd7..851a4678ab6f783424eb877befcc7fcfae1384d5 100644
|
| --- a/runtime/vm/os_thread_macos.cc
|
| +++ b/runtime/vm/os_thread_macos.cc
|
| @@ -223,8 +223,8 @@ Mutex::Mutex() {
|
| result = pthread_mutexattr_destroy(&attr);
|
| VALIDATE_PTHREAD_RESULT(result);
|
|
|
| - // When running with assertions enabled we do track the owner.
|
| #if defined(DEBUG)
|
| + // When running with assertions enabled we do track the owner.
|
| owner_ = OSThread::kInvalidThreadId;
|
| #endif // defined(DEBUG)
|
| }
|
| @@ -235,8 +235,8 @@ Mutex::~Mutex() {
|
| // Verify that the pthread_mutex was destroyed.
|
| VALIDATE_PTHREAD_RESULT(result);
|
|
|
| - // When running with assertions enabled we do track the owner.
|
| #if defined(DEBUG)
|
| + // When running with assertions enabled we do track the owner.
|
| ASSERT(owner_ == OSThread::kInvalidThreadId);
|
| #endif // defined(DEBUG)
|
| }
|
| @@ -247,8 +247,8 @@ void Mutex::Lock() {
|
| // Specifically check for dead lock to help debugging.
|
| ASSERT(result != EDEADLK);
|
| ASSERT_PTHREAD_SUCCESS(result); // Verify no other errors.
|
| - // When running with assertions enabled we do track the owner.
|
| #if defined(DEBUG)
|
| + // When running with assertions enabled we do track the owner.
|
| owner_ = OSThread::GetCurrentThreadId();
|
| #endif // defined(DEBUG)
|
| }
|
| @@ -261,8 +261,8 @@ bool Mutex::TryLock() {
|
| return false;
|
| }
|
| ASSERT_PTHREAD_SUCCESS(result); // Verify no other errors.
|
| - // When running with assertions enabled we do track the owner.
|
| #if defined(DEBUG)
|
| + // When running with assertions enabled we do track the owner.
|
| owner_ = OSThread::GetCurrentThreadId();
|
| #endif // defined(DEBUG)
|
| return true;
|
| @@ -270,8 +270,8 @@ bool Mutex::TryLock() {
|
|
|
|
|
| void Mutex::Unlock() {
|
| - // When running with assertions enabled we do track the owner.
|
| #if defined(DEBUG)
|
| + // When running with assertions enabled we do track the owner.
|
| ASSERT(IsOwnedByCurrentThread());
|
| owner_ = OSThread::kInvalidThreadId;
|
| #endif // defined(DEBUG)
|
| @@ -300,10 +300,20 @@ Monitor::Monitor() {
|
|
|
| result = pthread_cond_init(data_.cond(), NULL);
|
| VALIDATE_PTHREAD_RESULT(result);
|
| +
|
| +#if defined(DEBUG)
|
| + // When running with assertions enabled we track the owner.
|
| + owner_ = OSThread::kInvalidThreadId;
|
| +#endif // defined(DEBUG)
|
| }
|
|
|
|
|
| Monitor::~Monitor() {
|
| +#if defined(DEBUG)
|
| + // When running with assertions enabled we track the owner.
|
| + ASSERT(owner_ == OSThread::kInvalidThreadId);
|
| +#endif // defined(DEBUG)
|
| +
|
| int result = pthread_mutex_destroy(data_.mutex());
|
| VALIDATE_PTHREAD_RESULT(result);
|
|
|
| @@ -315,12 +325,22 @@ Monitor::~Monitor() {
|
| void Monitor::Enter() {
|
| int result = pthread_mutex_lock(data_.mutex());
|
| VALIDATE_PTHREAD_RESULT(result);
|
| - // TODO(iposva): Do we need to track lock owners?
|
| +
|
| +#if defined(DEBUG)
|
| + // When running with assertions enabled we track the owner.
|
| + ASSERT(owner_ == OSThread::kInvalidThreadId);
|
| + owner_ = OSThread::GetCurrentThreadId();
|
| +#endif // defined(DEBUG)
|
| }
|
|
|
|
|
| void Monitor::Exit() {
|
| - // TODO(iposva): Do we need to track lock owners?
|
| +#if defined(DEBUG)
|
| + // When running with assertions enabled we track the owner.
|
| + ASSERT(IsOwnedByCurrentThread());
|
| + owner_ = OSThread::kInvalidThreadId;
|
| +#endif // defined(DEBUG)
|
| +
|
| int result = pthread_mutex_unlock(data_.mutex());
|
| VALIDATE_PTHREAD_RESULT(result);
|
| }
|
| @@ -332,7 +352,13 @@ Monitor::WaitResult Monitor::Wait(int64_t millis) {
|
|
|
|
|
| Monitor::WaitResult Monitor::WaitMicros(int64_t micros) {
|
| - // TODO(iposva): Do we need to track lock owners?
|
| +#if defined(DEBUG)
|
| + // When running with assertions enabled we track the owner.
|
| + ASSERT(IsOwnedByCurrentThread());
|
| + ThreadId saved_owner = owner_;
|
| + owner_ = OSThread::kInvalidThreadId;
|
| +#endif // defined(DEBUG)
|
| +
|
| Monitor::WaitResult retval = kNotified;
|
| if (micros == kNoTimeout) {
|
| // Wait forever.
|
| @@ -357,19 +383,28 @@ Monitor::WaitResult Monitor::WaitMicros(int64_t micros) {
|
| retval = kTimedOut;
|
| }
|
| }
|
| +
|
| +#if defined(DEBUG)
|
| + // When running with assertions enabled we track the owner.
|
| + ASSERT(owner_ == OSThread::kInvalidThreadId);
|
| + owner_ = OSThread::GetCurrentThreadId();
|
| + ASSERT(owner_ == saved_owner);
|
| +#endif // defined(DEBUG)
|
| return retval;
|
| }
|
|
|
|
|
| void Monitor::Notify() {
|
| - // TODO(iposva): Do we need to track lock owners?
|
| + // When running with assertions enabled we track the owner.
|
| + ASSERT(IsOwnedByCurrentThread());
|
| int result = pthread_cond_signal(data_.cond());
|
| VALIDATE_PTHREAD_RESULT(result);
|
| }
|
|
|
|
|
| void Monitor::NotifyAll() {
|
| - // TODO(iposva): Do we need to track lock owners?
|
| + // When running with assertions enabled we track the owner.
|
| + ASSERT(IsOwnedByCurrentThread());
|
| int result = pthread_cond_broadcast(data_.cond());
|
| VALIDATE_PTHREAD_RESULT(result);
|
| }
|
|
|