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

Side by Side Diff: runtime/bin/thread_fuchsia.cc

Issue 2480793002: clang-format runtime/bin (Closed)
Patch Set: 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/bin/thread_android.cc ('k') | runtime/bin/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) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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" 5 #include "platform/globals.h"
6 #if defined(TARGET_OS_FUCHSIA) 6 #if defined(TARGET_OS_FUCHSIA)
7 7
8 #include "bin/thread.h" 8 #include "bin/thread.h"
9 #include "bin/thread_fuchsia.h" 9 #include "bin/thread_fuchsia.h"
10 10
11 #include <errno.h> // NOLINT 11 #include <errno.h> // NOLINT
12 #include <sys/resource.h> // NOLINT 12 #include <sys/resource.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 #include "platform/utils.h"
17 17
18 namespace dart { 18 namespace dart {
19 namespace bin { 19 namespace bin {
20 20
21 #define VALIDATE_PTHREAD_RESULT(result) \ 21 #define VALIDATE_PTHREAD_RESULT(result) \
22 if (result != 0) { \ 22 if (result != 0) { \
23 const int kBufferSize = 1024; \ 23 const int kBufferSize = 1024; \
24 char error_buf[kBufferSize]; \ 24 char error_buf[kBufferSize]; \
25 FATAL2("pthread error: %d (%s)", result, \ 25 FATAL2("pthread error: %d (%s)", result, \
26 Utils::StrError(result, error_buf, kBufferSize)); \ 26 Utils::StrError(result, error_buf, kBufferSize)); \
27 } 27 }
28 28
29 29
30 #ifdef DEBUG 30 #ifdef DEBUG
31 #define RETURN_ON_PTHREAD_FAILURE(result) \ 31 #define RETURN_ON_PTHREAD_FAILURE(result) \
32 if (result != 0) { \ 32 if (result != 0) { \
33 const int kBufferSize = 1024; \ 33 const int kBufferSize = 1024; \
34 char error_buf[kBufferSize]; \ 34 char error_buf[kBufferSize]; \
35 fprintf(stderr, "%s:%d: pthread error: %d (%s)\n", \ 35 fprintf(stderr, "%s:%d: pthread error: %d (%s)\n", __FILE__, __LINE__, \
36 __FILE__, __LINE__, result, \ 36 result, Utils::StrError(result, error_buf, kBufferSize)); \
37 Utils::StrError(result, error_buf, kBufferSize)); \ 37 return result; \
38 return result; \
39 } 38 }
40 #else 39 #else
41 #define RETURN_ON_PTHREAD_FAILURE(result) \ 40 #define RETURN_ON_PTHREAD_FAILURE(result) \
42 if (result != 0) { \ 41 if (result != 0) { \
43 return result; \ 42 return result; \
44 } 43 }
45 #endif 44 #endif
46 45
47 46
48 static void ComputeTimeSpecMicros(struct timespec* ts, int64_t micros) { 47 static void ComputeTimeSpecMicros(struct timespec* ts, int64_t micros) {
49 int64_t secs = micros / kMicrosecondsPerSecond; 48 int64_t secs = micros / kMicrosecondsPerSecond;
50 int64_t nanos = 49 int64_t nanos =
51 (micros - (secs * kMicrosecondsPerSecond)) * kNanosecondsPerMicrosecond; 50 (micros - (secs * kMicrosecondsPerSecond)) * kNanosecondsPerMicrosecond;
52 int result = clock_gettime(CLOCK_MONOTONIC, ts); 51 int result = clock_gettime(CLOCK_MONOTONIC, ts);
53 ASSERT(result == 0); 52 ASSERT(result == 0);
54 ts->tv_sec += secs; 53 ts->tv_sec += secs;
55 ts->tv_nsec += nanos; 54 ts->tv_nsec += nanos;
56 if (ts->tv_nsec >= kNanosecondsPerSecond) { 55 if (ts->tv_nsec >= kNanosecondsPerSecond) {
57 ts->tv_sec += 1; 56 ts->tv_sec += 1;
58 ts->tv_nsec -= kNanosecondsPerSecond; 57 ts->tv_nsec -= kNanosecondsPerSecond;
59 } 58 }
60 } 59 }
61 60
62 61
63 class ThreadStartData { 62 class ThreadStartData {
64 public: 63 public:
65 ThreadStartData(Thread::ThreadStartFunction function, 64 ThreadStartData(Thread::ThreadStartFunction function, uword parameter)
66 uword parameter)
67 : function_(function), parameter_(parameter) {} 65 : function_(function), parameter_(parameter) {}
68 66
69 Thread::ThreadStartFunction function() const { return function_; } 67 Thread::ThreadStartFunction function() const { return function_; }
70 uword parameter() const { return parameter_; } 68 uword parameter() const { return parameter_; }
71 69
72 private: 70 private:
73 Thread::ThreadStartFunction function_; 71 Thread::ThreadStartFunction function_;
74 uword parameter_; 72 uword parameter_;
75 73
76 DISALLOW_COPY_AND_ASSIGN(ThreadStartData); 74 DISALLOW_COPY_AND_ASSIGN(ThreadStartData);
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 void Monitor::NotifyAll() { 320 void Monitor::NotifyAll() {
323 // TODO(iposva): Do we need to track lock owners? 321 // TODO(iposva): Do we need to track lock owners?
324 int result = pthread_cond_broadcast(data_.cond()); 322 int result = pthread_cond_broadcast(data_.cond());
325 VALIDATE_PTHREAD_RESULT(result); 323 VALIDATE_PTHREAD_RESULT(result);
326 } 324 }
327 325
328 } // namespace bin 326 } // namespace bin
329 } // namespace dart 327 } // namespace dart
330 328
331 #endif // defined(TARGET_OS_FUCHSIA) 329 #endif // defined(TARGET_OS_FUCHSIA)
OLDNEW
« no previous file with comments | « runtime/bin/thread_android.cc ('k') | runtime/bin/thread_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698