| Index: runtime/vm/os_thread_android.cc
|
| diff --git a/runtime/vm/os_thread_android.cc b/runtime/vm/os_thread_android.cc
|
| index fa8789692cab04ba2e914f45819f196c83b6a25a..f1c3a445838aef1bd2e4d965e87952340a2a63e4 100644
|
| --- a/runtime/vm/os_thread_android.cc
|
| +++ b/runtime/vm/os_thread_android.cc
|
| @@ -216,8 +216,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)
|
| }
|
| @@ -228,8 +228,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)
|
| }
|
| @@ -240,8 +240,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)
|
| }
|
| @@ -254,8 +254,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;
|
| @@ -263,8 +263,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_condattr_destroy(&cond_attr);
|
| 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.
|
| @@ -347,19 +373,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);
|
| }
|
|
|