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

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

Issue 474913004: - Account for number of pending tasks in old-space collections. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 4 months 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 "vm/thread.h" 8 #include "vm/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/time.h> // NOLINT 12 #include <sys/time.h> // NOLINT
13 13
14 #include "platform/assert.h" 14 #include "platform/assert.h"
15 #include "vm/isolate.h"
15 16
16 namespace dart { 17 namespace dart {
17 18
18 #define VALIDATE_PTHREAD_RESULT(result) \ 19 #define VALIDATE_PTHREAD_RESULT(result) \
19 if (result != 0) { \ 20 if (result != 0) { \
20 const int kBufferSize = 1024; \ 21 const int kBufferSize = 1024; \
21 char error_buf[kBufferSize]; \ 22 char error_buf[kBufferSize]; \
22 FATAL2("pthread error: %d (%s)", result, \ 23 FATAL2("pthread error: %d (%s)", result, \
23 strerror_r(result, error_buf, kBufferSize)); \ 24 strerror_r(result, error_buf, kBufferSize)); \
24 } 25 }
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 result = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK); 187 result = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK);
187 VALIDATE_PTHREAD_RESULT(result); 188 VALIDATE_PTHREAD_RESULT(result);
188 #endif // defined(DEBUG) 189 #endif // defined(DEBUG)
189 190
190 result = pthread_mutex_init(data_.mutex(), &attr); 191 result = pthread_mutex_init(data_.mutex(), &attr);
191 // Verify that creating a pthread_mutex succeeded. 192 // Verify that creating a pthread_mutex succeeded.
192 VALIDATE_PTHREAD_RESULT(result); 193 VALIDATE_PTHREAD_RESULT(result);
193 194
194 result = pthread_mutexattr_destroy(&attr); 195 result = pthread_mutexattr_destroy(&attr);
195 VALIDATE_PTHREAD_RESULT(result); 196 VALIDATE_PTHREAD_RESULT(result);
197
198 // When running with assertions enabled we do track the owner.
199 #if defined(DEBUG)
200 owner_ = NULL;
201 #endif // defined(DEBUG)
196 } 202 }
197 203
198 204
199 Mutex::~Mutex() { 205 Mutex::~Mutex() {
200 int result = pthread_mutex_destroy(data_.mutex()); 206 int result = pthread_mutex_destroy(data_.mutex());
201 // Verify that the pthread_mutex was destroyed. 207 // Verify that the pthread_mutex was destroyed.
202 VALIDATE_PTHREAD_RESULT(result); 208 VALIDATE_PTHREAD_RESULT(result);
209
210 // When running with assertions enabled we do track the owner.
211 #if defined(DEBUG)
212 ASSERT(owner_ == NULL);
213 #endif // defined(DEBUG)
203 } 214 }
204 215
205 216
206 void Mutex::Lock() { 217 void Mutex::Lock() {
207 int result = pthread_mutex_lock(data_.mutex()); 218 int result = pthread_mutex_lock(data_.mutex());
208 // Specifically check for dead lock to help debugging. 219 // Specifically check for dead lock to help debugging.
209 ASSERT(result != EDEADLK); 220 ASSERT(result != EDEADLK);
210 ASSERT(result == 0); // Verify no other errors. 221 ASSERT(result == 0); // Verify no other errors.
211 // TODO(iposva): Do we need to track lock owners? 222 // When running with assertions enabled we do track the owner.
223 #if defined(DEBUG)
224 owner_ = Isolate::Current();
225 #endif // defined(DEBUG)
212 } 226 }
213 227
214 228
215 bool Mutex::TryLock() { 229 bool Mutex::TryLock() {
216 int result = pthread_mutex_trylock(data_.mutex()); 230 int result = pthread_mutex_trylock(data_.mutex());
217 // Return false if the lock is busy and locking failed. 231 // Return false if the lock is busy and locking failed.
218 if (result == EBUSY) { 232 if (result == EBUSY) {
219 return false; 233 return false;
220 } 234 }
221 ASSERT(result == 0); // Verify no other errors. 235 ASSERT(result == 0); // Verify no other errors.
222 // TODO(iposva): Do we need to track lock owners? 236 // When running with assertions enabled we do track the owner.
237 #if defined(DEBUG)
238 owner_ = Isolate::Current();
239 #endif // defined(DEBUG)
223 return true; 240 return true;
224 } 241 }
225 242
226 243
227 void Mutex::Unlock() { 244 void Mutex::Unlock() {
228 // TODO(iposva): Do we need to track lock owners? 245 // When running with assertions enabled we do track the owner.
246 #if defined(DEBUG)
247 ASSERT(owner_ == Isolate::Current());
248 owner_ = NULL;
249 #endif // defined(DEBUG)
229 int result = pthread_mutex_unlock(data_.mutex()); 250 int result = pthread_mutex_unlock(data_.mutex());
230 // Specifically check for wrong thread unlocking to aid debugging. 251 // Specifically check for wrong thread unlocking to aid debugging.
231 ASSERT(result != EPERM); 252 ASSERT(result != EPERM);
232 ASSERT(result == 0); // Verify no other errors. 253 ASSERT(result == 0); // Verify no other errors.
233 } 254 }
234 255
235 256
236 Monitor::Monitor() { 257 Monitor::Monitor() {
237 pthread_mutexattr_t mutex_attr; 258 pthread_mutexattr_t mutex_attr;
238 int result = pthread_mutexattr_init(&mutex_attr); 259 int result = pthread_mutexattr_init(&mutex_attr);
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 342
322 void Monitor::NotifyAll() { 343 void Monitor::NotifyAll() {
323 // TODO(iposva): Do we need to track lock owners? 344 // TODO(iposva): Do we need to track lock owners?
324 int result = pthread_cond_broadcast(data_.cond()); 345 int result = pthread_cond_broadcast(data_.cond());
325 VALIDATE_PTHREAD_RESULT(result); 346 VALIDATE_PTHREAD_RESULT(result);
326 } 347 }
327 348
328 } // namespace dart 349 } // namespace dart
329 350
330 #endif // defined(TARGET_OS_LINUX) 351 #endif // defined(TARGET_OS_LINUX)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698