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

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

Issue 999983004: simMutex (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 5 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « runtime/vm/os_thread.h ('k') | runtime/vm/os_thread_linux.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_ANDROID) 6 #if defined(TARGET_OS_ANDROID)
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
11 #include <sys/time.h> // NOLINT 11 #include <sys/time.h> // NOLINT
12 12
13 #include "platform/assert.h" 13 #include "platform/assert.h"
14 #include "vm/isolate.h"
15 14
16 namespace dart { 15 namespace dart {
17 16
18 #define VALIDATE_PTHREAD_RESULT(result) \ 17 #define VALIDATE_PTHREAD_RESULT(result) \
19 if (result != 0) { \ 18 if (result != 0) { \
20 const int kBufferSize = 1024; \ 19 const int kBufferSize = 1024; \
21 char error_message[kBufferSize]; \ 20 char error_message[kBufferSize]; \
22 strerror_r(result, error_message, kBufferSize); \ 21 strerror_r(result, error_message, kBufferSize); \
23 FATAL2("pthread error: %d (%s)", result, error_message); \ 22 FATAL2("pthread error: %d (%s)", result, error_message); \
24 } 23 }
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 189
191 result = pthread_mutex_init(data_.mutex(), &attr); 190 result = pthread_mutex_init(data_.mutex(), &attr);
192 // Verify that creating a pthread_mutex succeeded. 191 // Verify that creating a pthread_mutex succeeded.
193 VALIDATE_PTHREAD_RESULT(result); 192 VALIDATE_PTHREAD_RESULT(result);
194 193
195 result = pthread_mutexattr_destroy(&attr); 194 result = pthread_mutexattr_destroy(&attr);
196 VALIDATE_PTHREAD_RESULT(result); 195 VALIDATE_PTHREAD_RESULT(result);
197 196
198 // When running with assertions enabled we do track the owner. 197 // When running with assertions enabled we do track the owner.
199 #if defined(DEBUG) 198 #if defined(DEBUG)
200 owner_ = NULL; 199 owner_ = OSThread::kInvalidThreadId;
201 #endif // defined(DEBUG) 200 #endif // defined(DEBUG)
202 } 201 }
203 202
204 203
205 Mutex::~Mutex() { 204 Mutex::~Mutex() {
206 int result = pthread_mutex_destroy(data_.mutex()); 205 int result = pthread_mutex_destroy(data_.mutex());
207 // Verify that the pthread_mutex was destroyed. 206 // Verify that the pthread_mutex was destroyed.
208 VALIDATE_PTHREAD_RESULT(result); 207 VALIDATE_PTHREAD_RESULT(result);
209 208
210 // When running with assertions enabled we do track the owner. 209 // When running with assertions enabled we do track the owner.
211 #if defined(DEBUG) 210 #if defined(DEBUG)
212 ASSERT(owner_ == NULL); 211 ASSERT(owner_ == OSThread::kInvalidThreadId);
213 #endif // defined(DEBUG) 212 #endif // defined(DEBUG)
214 } 213 }
215 214
216 215
217 void Mutex::Lock() { 216 void Mutex::Lock() {
218 int result = pthread_mutex_lock(data_.mutex()); 217 int result = pthread_mutex_lock(data_.mutex());
219 // Specifically check for dead lock to help debugging. 218 // Specifically check for dead lock to help debugging.
220 ASSERT(result != EDEADLK); 219 ASSERT(result != EDEADLK);
221 ASSERT(result == 0); // Verify no other errors. 220 ASSERT(result == 0); // Verify no other errors.
222 // When running with assertions enabled we do track the owner. 221 // When running with assertions enabled we do track the owner.
223 #if defined(DEBUG) 222 #if defined(DEBUG)
224 owner_ = Isolate::Current(); 223 owner_ = OSThread::GetCurrentThreadId();
225 #endif // defined(DEBUG) 224 #endif // defined(DEBUG)
226 } 225 }
227 226
228 227
229 bool Mutex::TryLock() { 228 bool Mutex::TryLock() {
230 int result = pthread_mutex_trylock(data_.mutex()); 229 int result = pthread_mutex_trylock(data_.mutex());
231 // Return false if the lock is busy and locking failed. 230 // Return false if the lock is busy and locking failed.
232 if (result == EBUSY) { 231 if (result == EBUSY) {
233 return false; 232 return false;
234 } 233 }
235 ASSERT(result == 0); // Verify no other errors. 234 ASSERT(result == 0); // Verify no other errors.
236 // When running with assertions enabled we do track the owner. 235 // When running with assertions enabled we do track the owner.
237 #if defined(DEBUG) 236 #if defined(DEBUG)
238 owner_ = Isolate::Current(); 237 owner_ = OSThread::GetCurrentThreadId();
239 #endif // defined(DEBUG) 238 #endif // defined(DEBUG)
240 return true; 239 return true;
241 } 240 }
242 241
243 242
244 void Mutex::Unlock() { 243 void Mutex::Unlock() {
245 // When running with assertions enabled we do track the owner. 244 // When running with assertions enabled we do track the owner.
246 #if defined(DEBUG) 245 #if defined(DEBUG)
247 ASSERT(owner_ == Isolate::Current()); 246 ASSERT(IsOwnedByCurrentThread());
248 owner_ = NULL; 247 owner_ = OSThread::kInvalidThreadId;
249 #endif // defined(DEBUG) 248 #endif // defined(DEBUG)
250 int result = pthread_mutex_unlock(data_.mutex()); 249 int result = pthread_mutex_unlock(data_.mutex());
251 // Specifically check for wrong thread unlocking to aid debugging. 250 // Specifically check for wrong thread unlocking to aid debugging.
252 ASSERT(result != EPERM); 251 ASSERT(result != EPERM);
253 ASSERT(result == 0); // Verify no other errors. 252 ASSERT(result == 0); // Verify no other errors.
254 } 253 }
255 254
256 255
257 Monitor::Monitor() { 256 Monitor::Monitor() {
258 pthread_mutexattr_t mutex_attr; 257 pthread_mutexattr_t mutex_attr;
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 338
340 void Monitor::NotifyAll() { 339 void Monitor::NotifyAll() {
341 // TODO(iposva): Do we need to track lock owners? 340 // TODO(iposva): Do we need to track lock owners?
342 int result = pthread_cond_broadcast(data_.cond()); 341 int result = pthread_cond_broadcast(data_.cond());
343 VALIDATE_PTHREAD_RESULT(result); 342 VALIDATE_PTHREAD_RESULT(result);
344 } 343 }
345 344
346 } // namespace dart 345 } // namespace dart
347 346
348 #endif // defined(TARGET_OS_ANDROID) 347 #endif // defined(TARGET_OS_ANDROID)
OLDNEW
« no previous file with comments | « runtime/vm/os_thread.h ('k') | runtime/vm/os_thread_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698