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

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
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) {
siva 2013/12/11 02:52:21 Ditto comment about asserting sizes.
Cutch 2013/12/11 17:44:56 Done.
154 return static_cast<intptr_t>(id);
155 }
156
157
158 bool Thread::Compare(ThreadId a, ThreadId b) {
159 return pthread_equal(a, b) != 0;
160 }
161
162
153 void Thread::GetThreadCpuUsage(ThreadId thread_id, int64_t* cpu_usage) { 163 void Thread::GetThreadCpuUsage(ThreadId thread_id, int64_t* cpu_usage) {
154 ASSERT(thread_id == GetCurrentThreadId()); 164 ASSERT(thread_id == GetCurrentThreadId());
155 ASSERT(cpu_usage != NULL); 165 ASSERT(cpu_usage != NULL);
156 struct timespec ts; 166 struct timespec ts;
157 int r = clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts); 167 int r = clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts);
158 ASSERT(r == 0); 168 ASSERT(r == 0);
159 *cpu_usage = (ts.tv_sec * kNanosecondsPerSecond + ts.tv_nsec) / 169 *cpu_usage = (ts.tv_sec * kNanosecondsPerSecond + ts.tv_nsec) /
160 kNanosecondsPerMicrosecond; 170 kNanosecondsPerMicrosecond;
161 } 171 }
162 172
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 315
306 void Monitor::NotifyAll() { 316 void Monitor::NotifyAll() {
307 // TODO(iposva): Do we need to track lock owners? 317 // TODO(iposva): Do we need to track lock owners?
308 int result = pthread_cond_broadcast(data_.cond()); 318 int result = pthread_cond_broadcast(data_.cond());
309 VALIDATE_PTHREAD_RESULT(result); 319 VALIDATE_PTHREAD_RESULT(result);
310 } 320 }
311 321
312 } // namespace dart 322 } // namespace dart
313 323
314 #endif // defined(TARGET_OS_LINUX) 324 #endif // defined(TARGET_OS_LINUX)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698