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

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

Issue 1233563004: Avoid race in isolate shutdown; add assertions, error messages (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Move wait per suggestion; port to all platforms. Created 5 years, 5 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
« no previous file with comments | « runtime/vm/os_thread_linux.cc ('k') | runtime/vm/thread.h » ('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_MACOS) 6 #if defined(TARGET_OS_MACOS)
7 7
8 #include "vm/os_thread.h" 8 #include "vm/os_thread.h"
9 9
10 #include <sys/errno.h> // NOLINT 10 #include <sys/errno.h> // NOLINT
(...skipping 13 matching lines...) Expand all
24 24
25 #define VALIDATE_PTHREAD_RESULT(result) \ 25 #define VALIDATE_PTHREAD_RESULT(result) \
26 if (result != 0) { \ 26 if (result != 0) { \
27 const int kBufferSize = 1024; \ 27 const int kBufferSize = 1024; \
28 char error_message[kBufferSize]; \ 28 char error_message[kBufferSize]; \
29 strerror_r(result, error_message, kBufferSize); \ 29 strerror_r(result, error_message, kBufferSize); \
30 FATAL2("pthread error: %d (%s)", result, error_message); \ 30 FATAL2("pthread error: %d (%s)", result, error_message); \
31 } 31 }
32 32
33 33
34 #if defined(DEBUG)
35 #define ASSERT_PTHREAD_SUCCESS(result) VALIDATE_PTHREAD_RESULT(result)
36 #else
37 // NOTE: This (currently) expands to a no-op.
38 #define ASSERT_PTHREAD_SUCCESS(result) ASSERT(result == 0)
39 #endif
40
41
34 #ifdef DEBUG 42 #ifdef DEBUG
35 #define RETURN_ON_PTHREAD_FAILURE(result) \ 43 #define RETURN_ON_PTHREAD_FAILURE(result) \
36 if (result != 0) { \ 44 if (result != 0) { \
37 const int kBufferSize = 1024; \ 45 const int kBufferSize = 1024; \
38 char error_message[kBufferSize]; \ 46 char error_message[kBufferSize]; \
39 strerror_r(result, error_message, kBufferSize); \ 47 strerror_r(result, error_message, kBufferSize); \
40 fprintf(stderr, "%s:%d: pthread error: %d (%s)\n", \ 48 fprintf(stderr, "%s:%d: pthread error: %d (%s)\n", \
41 __FILE__, __LINE__, result, error_message); \ 49 __FILE__, __LINE__, result, error_message); \
42 return result; \ 50 return result; \
43 } 51 }
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 #if defined(DEBUG) 224 #if defined(DEBUG)
217 ASSERT(owner_ == OSThread::kInvalidThreadId); 225 ASSERT(owner_ == OSThread::kInvalidThreadId);
218 #endif // defined(DEBUG) 226 #endif // defined(DEBUG)
219 } 227 }
220 228
221 229
222 void Mutex::Lock() { 230 void Mutex::Lock() {
223 int result = pthread_mutex_lock(data_.mutex()); 231 int result = pthread_mutex_lock(data_.mutex());
224 // Specifically check for dead lock to help debugging. 232 // Specifically check for dead lock to help debugging.
225 ASSERT(result != EDEADLK); 233 ASSERT(result != EDEADLK);
226 ASSERT(result == 0); // Verify no other errors. 234 ASSERT_PTHREAD_SUCCESS(result); // Verify no other errors.
227 // When running with assertions enabled we do track the owner. 235 // When running with assertions enabled we do track the owner.
228 #if defined(DEBUG) 236 #if defined(DEBUG)
229 owner_ = OSThread::GetCurrentThreadId(); 237 owner_ = OSThread::GetCurrentThreadId();
230 #endif // defined(DEBUG) 238 #endif // defined(DEBUG)
231 } 239 }
232 240
233 241
234 bool Mutex::TryLock() { 242 bool Mutex::TryLock() {
235 int result = pthread_mutex_trylock(data_.mutex()); 243 int result = pthread_mutex_trylock(data_.mutex());
236 // Return false if the lock is busy and locking failed. 244 // Return false if the lock is busy and locking failed.
237 if ((result == EBUSY) || (result == EDEADLK)) { 245 if ((result == EBUSY) || (result == EDEADLK)) {
238 return false; 246 return false;
239 } 247 }
240 ASSERT(result == 0); // Verify no other errors. 248 ASSERT_PTHREAD_SUCCESS(result); // Verify no other errors.
241 // When running with assertions enabled we do track the owner. 249 // When running with assertions enabled we do track the owner.
242 #if defined(DEBUG) 250 #if defined(DEBUG)
243 owner_ = OSThread::GetCurrentThreadId(); 251 owner_ = OSThread::GetCurrentThreadId();
244 #endif // defined(DEBUG) 252 #endif // defined(DEBUG)
245 return true; 253 return true;
246 } 254 }
247 255
248 256
249 void Mutex::Unlock() { 257 void Mutex::Unlock() {
250 // When running with assertions enabled we do track the owner. 258 // When running with assertions enabled we do track the owner.
251 #if defined(DEBUG) 259 #if defined(DEBUG)
252 ASSERT(IsOwnedByCurrentThread()); 260 ASSERT(IsOwnedByCurrentThread());
253 owner_ = OSThread::kInvalidThreadId; 261 owner_ = OSThread::kInvalidThreadId;
254 #endif // defined(DEBUG) 262 #endif // defined(DEBUG)
255 int result = pthread_mutex_unlock(data_.mutex()); 263 int result = pthread_mutex_unlock(data_.mutex());
256 // Specifically check for wrong thread unlocking to aid debugging. 264 // Specifically check for wrong thread unlocking to aid debugging.
257 ASSERT(result != EPERM); 265 ASSERT(result != EPERM);
258 ASSERT(result == 0); // Verify no other errors. 266 ASSERT_PTHREAD_SUCCESS(result); // Verify no other errors.
259 } 267 }
260 268
261 269
262 Monitor::Monitor() { 270 Monitor::Monitor() {
263 pthread_mutexattr_t attr; 271 pthread_mutexattr_t attr;
264 int result = pthread_mutexattr_init(&attr); 272 int result = pthread_mutexattr_init(&attr);
265 VALIDATE_PTHREAD_RESULT(result); 273 VALIDATE_PTHREAD_RESULT(result);
266 274
267 #if defined(DEBUG) 275 #if defined(DEBUG)
268 result = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK); 276 result = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK);
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 355
348 void Monitor::NotifyAll() { 356 void Monitor::NotifyAll() {
349 // TODO(iposva): Do we need to track lock owners? 357 // TODO(iposva): Do we need to track lock owners?
350 int result = pthread_cond_broadcast(data_.cond()); 358 int result = pthread_cond_broadcast(data_.cond());
351 VALIDATE_PTHREAD_RESULT(result); 359 VALIDATE_PTHREAD_RESULT(result);
352 } 360 }
353 361
354 } // namespace dart 362 } // namespace dart
355 363
356 #endif // defined(TARGET_OS_MACOS) 364 #endif // defined(TARGET_OS_MACOS)
OLDNEW
« no previous file with comments | « runtime/vm/os_thread_linux.cc ('k') | runtime/vm/thread.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698