OLD | NEW |
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_LINUX) | 6 #if defined(TARGET_OS_LINUX) |
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/resource.h> // NOLINT | 11 #include <sys/resource.h> // NOLINT |
12 #include <sys/syscall.h> // NOLINT | 12 #include <sys/syscall.h> // NOLINT |
13 #include <sys/time.h> // NOLINT | 13 #include <sys/time.h> // NOLINT |
14 | 14 |
15 #include "platform/assert.h" | 15 #include "platform/assert.h" |
| 16 #include "platform/utils.h" |
16 | 17 |
17 namespace dart { | 18 namespace dart { |
18 | 19 |
19 static char* strerror_helper(int err, char* buffer, size_t bufsize) { | |
20 #if !defined(__GLIBC__) || \ | |
21 ((_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && !_GNU_SOURCE) | |
22 // Use the standard version | |
23 return strerror_r(err, buffer, bufsize) == 0 ? | |
24 buffer : const_cast<char*>("strerror_r failed"); | |
25 #else | |
26 // Use the gnu specific version | |
27 return strerror_r(err, buffer, bufsize); | |
28 #endif | |
29 } | |
30 | |
31 #define VALIDATE_PTHREAD_RESULT(result) \ | 20 #define VALIDATE_PTHREAD_RESULT(result) \ |
32 if (result != 0) { \ | 21 if (result != 0) { \ |
33 const int kBufferSize = 1024; \ | 22 const int kBufferSize = 1024; \ |
34 char error_buf[kBufferSize]; \ | 23 char error_buf[kBufferSize]; \ |
35 FATAL2("pthread error: %d (%s)", result, \ | 24 FATAL2("pthread error: %d (%s)", result, \ |
36 strerror_helper(result, error_buf, kBufferSize)); \ | 25 Utils::StrError(result, error_buf, kBufferSize)); \ |
37 } | 26 } |
38 | 27 |
39 | 28 |
40 #if defined(DEBUG) | 29 #if defined(DEBUG) |
41 #define ASSERT_PTHREAD_SUCCESS(result) VALIDATE_PTHREAD_RESULT(result) | 30 #define ASSERT_PTHREAD_SUCCESS(result) VALIDATE_PTHREAD_RESULT(result) |
42 #else | 31 #else |
43 // NOTE: This (currently) expands to a no-op. | 32 // NOTE: This (currently) expands to a no-op. |
44 #define ASSERT_PTHREAD_SUCCESS(result) ASSERT(result == 0) | 33 #define ASSERT_PTHREAD_SUCCESS(result) ASSERT(result == 0) |
45 #endif | 34 #endif |
46 | 35 |
47 | 36 |
48 #ifdef DEBUG | 37 #ifdef DEBUG |
49 #define RETURN_ON_PTHREAD_FAILURE(result) \ | 38 #define RETURN_ON_PTHREAD_FAILURE(result) \ |
50 if (result != 0) { \ | 39 if (result != 0) { \ |
51 const int kBufferSize = 1024; \ | 40 const int kBufferSize = 1024; \ |
52 char error_buf[kBufferSize]; \ | 41 char error_buf[kBufferSize]; \ |
53 fprintf(stderr, "%s:%d: pthread error: %d (%s)\n", \ | 42 fprintf(stderr, "%s:%d: pthread error: %d (%s)\n", \ |
54 __FILE__, __LINE__, result, \ | 43 __FILE__, __LINE__, result, \ |
55 strerror_helper(result, error_buf, kBufferSize)); \ | 44 Utils::StrError(result, error_buf, kBufferSize)); \ |
56 return result; \ | 45 return result; \ |
57 } | 46 } |
58 #else | 47 #else |
59 #define RETURN_ON_PTHREAD_FAILURE(result) \ | 48 #define RETURN_ON_PTHREAD_FAILURE(result) \ |
60 if (result != 0) return result; | 49 if (result != 0) return result; |
61 #endif | 50 #endif |
62 | 51 |
63 | 52 |
64 static void ComputeTimeSpecMicros(struct timespec* ts, int64_t micros) { | 53 static void ComputeTimeSpecMicros(struct timespec* ts, int64_t micros) { |
65 int64_t secs = micros / kMicrosecondsPerSecond; | 54 int64_t secs = micros / kMicrosecondsPerSecond; |
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
424 void Monitor::NotifyAll() { | 413 void Monitor::NotifyAll() { |
425 // When running with assertions enabled we track the owner. | 414 // When running with assertions enabled we track the owner. |
426 ASSERT(IsOwnedByCurrentThread()); | 415 ASSERT(IsOwnedByCurrentThread()); |
427 int result = pthread_cond_broadcast(data_.cond()); | 416 int result = pthread_cond_broadcast(data_.cond()); |
428 VALIDATE_PTHREAD_RESULT(result); | 417 VALIDATE_PTHREAD_RESULT(result); |
429 } | 418 } |
430 | 419 |
431 } // namespace dart | 420 } // namespace dart |
432 | 421 |
433 #endif // defined(TARGET_OS_LINUX) | 422 #endif // defined(TARGET_OS_LINUX) |
OLD | NEW |