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

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

Issue 1450113003: Avoid strerror_r portability issues (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: oops namespace Created 5 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_android.cc ('k') | runtime/vm/os_thread_macos.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_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 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 void Monitor::NotifyAll() { 402 void Monitor::NotifyAll() {
414 // When running with assertions enabled we track the owner. 403 // When running with assertions enabled we track the owner.
415 ASSERT(IsOwnedByCurrentThread()); 404 ASSERT(IsOwnedByCurrentThread());
416 int result = pthread_cond_broadcast(data_.cond()); 405 int result = pthread_cond_broadcast(data_.cond());
417 VALIDATE_PTHREAD_RESULT(result); 406 VALIDATE_PTHREAD_RESULT(result);
418 } 407 }
419 408
420 } // namespace dart 409 } // namespace dart
421 410
422 #endif // defined(TARGET_OS_LINUX) 411 #endif // defined(TARGET_OS_LINUX)
OLDNEW
« no previous file with comments | « runtime/vm/os_thread_android.cc ('k') | runtime/vm/os_thread_macos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698