| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 <sys/errno.h> | 5 #include <sys/errno.h> |
| 6 | 6 |
| 7 #include "vm/thread.h" | 7 #include "vm/thread.h" |
| 8 | 8 |
| 9 #include "vm/assert.h" | 9 #include "vm/assert.h" |
| 10 | 10 |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 // Specifically check for dead lock to help debugging. | 119 // Specifically check for dead lock to help debugging. |
| 120 ASSERT(result != EDEADLK); | 120 ASSERT(result != EDEADLK); |
| 121 ASSERT(result == 0); // Verify no other errors. | 121 ASSERT(result == 0); // Verify no other errors. |
| 122 // TODO(iposva): Do we need to track lock owners? | 122 // TODO(iposva): Do we need to track lock owners? |
| 123 } | 123 } |
| 124 | 124 |
| 125 | 125 |
| 126 bool Mutex::TryLock() { | 126 bool Mutex::TryLock() { |
| 127 int result = pthread_mutex_trylock(data_.mutex()); | 127 int result = pthread_mutex_trylock(data_.mutex()); |
| 128 // Return false if the lock is busy and locking failed. | 128 // Return false if the lock is busy and locking failed. |
| 129 if (result == EBUSY) { | 129 if ((result == EBUSY) || (result == EDEADLK)) { |
| 130 return false; | 130 return false; |
| 131 } | 131 } |
| 132 ASSERT(result == 0); // Verify no other errors. | 132 ASSERT(result == 0); // Verify no other errors. |
| 133 // TODO(iposva): Do we need to track lock owners? | 133 // TODO(iposva): Do we need to track lock owners? |
| 134 return true; | 134 return true; |
| 135 } | 135 } |
| 136 | 136 |
| 137 | 137 |
| 138 void Mutex::Unlock() { | 138 void Mutex::Unlock() { |
| 139 // TODO(iposva): Do we need to track lock owners? | 139 // TODO(iposva): Do we need to track lock owners? |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 } | 220 } |
| 221 | 221 |
| 222 | 222 |
| 223 void Monitor::NotifyAll() { | 223 void Monitor::NotifyAll() { |
| 224 // TODO(iposva): Do we need to track lock owners? | 224 // TODO(iposva): Do we need to track lock owners? |
| 225 int result = pthread_cond_broadcast(data_.cond()); | 225 int result = pthread_cond_broadcast(data_.cond()); |
| 226 VALIDATE_PTHREAD_RESULT(result); | 226 VALIDATE_PTHREAD_RESULT(result); |
| 227 } | 227 } |
| 228 | 228 |
| 229 } // namespace dart | 229 } // namespace dart |
| OLD | NEW |