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

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

Issue 2481873005: clang-format runtime/vm (Closed)
Patch Set: Merge Created 4 years, 1 month 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/os_thread_win.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
11 #include <sys/types.h> // NOLINT 11 #include <sys/types.h> // NOLINT
12 #include <sys/sysctl.h> // NOLINT 12 #include <sys/sysctl.h> // NOLINT
13 #include <mach/mach_init.h> // NOLINT 13 #include <mach/mach_init.h> // NOLINT
14 #include <mach/mach_host.h> // NOLINT 14 #include <mach/mach_host.h> // NOLINT
15 #include <mach/mach_port.h> // NOLINT 15 #include <mach/mach_port.h> // NOLINT
16 #include <mach/mach_traps.h> // NOLINT 16 #include <mach/mach_traps.h> // NOLINT
17 #include <mach/task_info.h> // NOLINT 17 #include <mach/task_info.h> // NOLINT
18 #include <mach/thread_info.h> // NOLINT 18 #include <mach/thread_info.h> // NOLINT
19 #include <mach/thread_act.h> // NOLINT 19 #include <mach/thread_act.h> // NOLINT
20 20
21 #include "platform/assert.h" 21 #include "platform/assert.h"
22 #include "platform/utils.h" 22 #include "platform/utils.h"
23 23
24 #include "vm/profiler.h" 24 #include "vm/profiler.h"
25 25
26 namespace dart { 26 namespace dart {
27 27
28 #define VALIDATE_PTHREAD_RESULT(result) \ 28 #define VALIDATE_PTHREAD_RESULT(result) \
29 if (result != 0) { \ 29 if (result != 0) { \
30 const int kBufferSize = 1024; \ 30 const int kBufferSize = 1024; \
31 char error_message[kBufferSize]; \ 31 char error_message[kBufferSize]; \
32 NOT_IN_PRODUCT(Profiler::DumpStackTrace(true /* native_stack_trace */)); \ 32 NOT_IN_PRODUCT(Profiler::DumpStackTrace(true /* native_stack_trace */)); \
33 Utils::StrError(result, error_message, kBufferSize); \ 33 Utils::StrError(result, error_message, kBufferSize); \
34 FATAL2("pthread error: %d (%s)", result, error_message); \ 34 FATAL2("pthread error: %d (%s)", result, error_message); \
35 } 35 }
36 36
37 37
38 #if defined(DEBUG) 38 #if defined(DEBUG)
39 #define ASSERT_PTHREAD_SUCCESS(result) VALIDATE_PTHREAD_RESULT(result) 39 #define ASSERT_PTHREAD_SUCCESS(result) VALIDATE_PTHREAD_RESULT(result)
40 #else 40 #else
41 // NOTE: This (currently) expands to a no-op. 41 // NOTE: This (currently) expands to a no-op.
42 #define ASSERT_PTHREAD_SUCCESS(result) ASSERT(result == 0) 42 #define ASSERT_PTHREAD_SUCCESS(result) ASSERT(result == 0)
43 #endif 43 #endif
44 44
45 45
46 #ifdef DEBUG 46 #ifdef DEBUG
47 #define RETURN_ON_PTHREAD_FAILURE(result) \ 47 #define RETURN_ON_PTHREAD_FAILURE(result) \
48 if (result != 0) { \ 48 if (result != 0) { \
49 const int kBufferSize = 1024; \ 49 const int kBufferSize = 1024; \
50 char error_message[kBufferSize]; \ 50 char error_message[kBufferSize]; \
51 Utils::StrError(result, error_message, kBufferSize); \ 51 Utils::StrError(result, error_message, kBufferSize); \
52 fprintf(stderr, "%s:%d: pthread error: %d (%s)\n", \ 52 fprintf(stderr, "%s:%d: pthread error: %d (%s)\n", __FILE__, __LINE__, \
53 __FILE__, __LINE__, result, error_message); \ 53 result, error_message); \
54 return result; \ 54 return result; \
55 } 55 }
56 #else 56 #else
57 #define RETURN_ON_PTHREAD_FAILURE(result) \ 57 #define RETURN_ON_PTHREAD_FAILURE(result) \
58 if (result != 0) return result; 58 if (result != 0) return result;
59 #endif 59 #endif
60 60
61 61
62 class ThreadStartData { 62 class ThreadStartData {
63 public: 63 public:
64 ThreadStartData(const char* name, 64 ThreadStartData(const char* name,
65 OSThread::ThreadStartFunction function, 65 OSThread::ThreadStartFunction function,
66 uword parameter) 66 uword parameter)
67 : name_(name), function_(function), parameter_(parameter) {} 67 : name_(name), function_(function), parameter_(parameter) {}
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 struct timespec ts; 387 struct timespec ts;
388 int64_t secs = micros / kMicrosecondsPerSecond; 388 int64_t secs = micros / kMicrosecondsPerSecond;
389 if (secs > kMaxInt32) { 389 if (secs > kMaxInt32) {
390 // Avoid truncation of overly large timeout values. 390 // Avoid truncation of overly large timeout values.
391 secs = kMaxInt32; 391 secs = kMaxInt32;
392 } 392 }
393 int64_t nanos = 393 int64_t nanos =
394 (micros - (secs * kMicrosecondsPerSecond)) * kNanosecondsPerMicrosecond; 394 (micros - (secs * kMicrosecondsPerSecond)) * kNanosecondsPerMicrosecond;
395 ts.tv_sec = static_cast<int32_t>(secs); 395 ts.tv_sec = static_cast<int32_t>(secs);
396 ts.tv_nsec = static_cast<long>(nanos); // NOLINT (long used in timespec). 396 ts.tv_nsec = static_cast<long>(nanos); // NOLINT (long used in timespec).
397 int result = pthread_cond_timedwait_relative_np(data_.cond(), 397 int result =
398 data_.mutex(), 398 pthread_cond_timedwait_relative_np(data_.cond(), data_.mutex(), &ts);
399 &ts);
400 ASSERT((result == 0) || (result == ETIMEDOUT)); 399 ASSERT((result == 0) || (result == ETIMEDOUT));
401 if (result == ETIMEDOUT) { 400 if (result == ETIMEDOUT) {
402 retval = kTimedOut; 401 retval = kTimedOut;
403 } 402 }
404 } 403 }
405 404
406 #if defined(DEBUG) 405 #if defined(DEBUG)
407 // When running with assertions enabled we track the owner. 406 // When running with assertions enabled we track the owner.
408 ASSERT(owner_ == OSThread::kInvalidThreadId); 407 ASSERT(owner_ == OSThread::kInvalidThreadId);
409 owner_ = OSThread::GetCurrentThreadId(); 408 owner_ = OSThread::GetCurrentThreadId();
(...skipping 14 matching lines...) Expand all
424 void Monitor::NotifyAll() { 423 void Monitor::NotifyAll() {
425 // When running with assertions enabled we track the owner. 424 // When running with assertions enabled we track the owner.
426 ASSERT(IsOwnedByCurrentThread()); 425 ASSERT(IsOwnedByCurrentThread());
427 int result = pthread_cond_broadcast(data_.cond()); 426 int result = pthread_cond_broadcast(data_.cond());
428 VALIDATE_PTHREAD_RESULT(result); 427 VALIDATE_PTHREAD_RESULT(result);
429 } 428 }
430 429
431 } // namespace dart 430 } // namespace dart
432 431
433 #endif // defined(TARGET_OS_MACOS) 432 #endif // defined(TARGET_OS_MACOS)
OLDNEW
« no previous file with comments | « runtime/vm/os_thread_linux.cc ('k') | runtime/vm/os_thread_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698