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

Side by Side Diff: runtime/platform/thread_linux.cc

Issue 109803002: Profiler Take 2 (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years 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 | Annotate | Revision Log
« no previous file with comments | « runtime/platform/thread_android.cc ('k') | runtime/platform/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" 5 #include "platform/globals.h"
6 #if defined(TARGET_OS_LINUX) 6 #if defined(TARGET_OS_LINUX)
7 7
8 #include "platform/thread.h" 8 #include "platform/thread.h"
9 9
10 #include <errno.h> // NOLINT 10 #include <errno.h> // NOLINT
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 RETURN_ON_PTHREAD_FAILURE(result); 107 RETURN_ON_PTHREAD_FAILURE(result);
108 108
109 result = pthread_attr_destroy(&attr); 109 result = pthread_attr_destroy(&attr);
110 RETURN_ON_PTHREAD_FAILURE(result); 110 RETURN_ON_PTHREAD_FAILURE(result);
111 111
112 return 0; 112 return 0;
113 } 113 }
114 114
115 115
116 ThreadLocalKey Thread::kUnsetThreadLocalKey = static_cast<pthread_key_t>(-1); 116 ThreadLocalKey Thread::kUnsetThreadLocalKey = static_cast<pthread_key_t>(-1);
117 117 ThreadId Thread::kInvalidThreadId = static_cast<ThreadId>(0);
118 118
119 ThreadLocalKey Thread::CreateThreadLocal() { 119 ThreadLocalKey Thread::CreateThreadLocal() {
120 pthread_key_t key = kUnsetThreadLocalKey; 120 pthread_key_t key = kUnsetThreadLocalKey;
121 int result = pthread_key_create(&key, NULL); 121 int result = pthread_key_create(&key, NULL);
122 VALIDATE_PTHREAD_RESULT(result); 122 VALIDATE_PTHREAD_RESULT(result);
123 ASSERT(key != kUnsetThreadLocalKey); 123 ASSERT(key != kUnsetThreadLocalKey);
124 return key; 124 return key;
125 } 125 }
126 126
127 127
(...skipping 15 matching lines...) Expand all
143 const int kStackSize = (128 * kWordSize * KB); 143 const int kStackSize = (128 * kWordSize * KB);
144 return kStackSize; 144 return kStackSize;
145 } 145 }
146 146
147 147
148 ThreadId Thread::GetCurrentThreadId() { 148 ThreadId Thread::GetCurrentThreadId() {
149 return pthread_self(); 149 return pthread_self();
150 } 150 }
151 151
152 152
153 intptr_t Thread::ThreadIdToIntPtr(ThreadId id) {
154 ASSERT(sizeof(id) == sizeof(intptr_t));
155 return static_cast<intptr_t>(id);
156 }
157
158
159 bool Thread::Compare(ThreadId a, ThreadId b) {
160 return pthread_equal(a, b) != 0;
161 }
162
163
153 void Thread::GetThreadCpuUsage(ThreadId thread_id, int64_t* cpu_usage) { 164 void Thread::GetThreadCpuUsage(ThreadId thread_id, int64_t* cpu_usage) {
154 ASSERT(thread_id == GetCurrentThreadId()); 165 ASSERT(thread_id == GetCurrentThreadId());
155 ASSERT(cpu_usage != NULL); 166 ASSERT(cpu_usage != NULL);
156 struct timespec ts; 167 struct timespec ts;
157 int r = clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts); 168 int r = clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts);
158 ASSERT(r == 0); 169 ASSERT(r == 0);
159 *cpu_usage = (ts.tv_sec * kNanosecondsPerSecond + ts.tv_nsec) / 170 *cpu_usage = (ts.tv_sec * kNanosecondsPerSecond + ts.tv_nsec) /
160 kNanosecondsPerMicrosecond; 171 kNanosecondsPerMicrosecond;
161 } 172 }
162 173
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 316
306 void Monitor::NotifyAll() { 317 void Monitor::NotifyAll() {
307 // TODO(iposva): Do we need to track lock owners? 318 // TODO(iposva): Do we need to track lock owners?
308 int result = pthread_cond_broadcast(data_.cond()); 319 int result = pthread_cond_broadcast(data_.cond());
309 VALIDATE_PTHREAD_RESULT(result); 320 VALIDATE_PTHREAD_RESULT(result);
310 } 321 }
311 322
312 } // namespace dart 323 } // namespace dart
313 324
314 #endif // defined(TARGET_OS_LINUX) 325 #endif // defined(TARGET_OS_LINUX)
OLDNEW
« no previous file with comments | « runtime/platform/thread_android.cc ('k') | runtime/platform/thread_macos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698