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

Side by Side Diff: src/v8threads.cc

Issue 23625003: Cleanup Mutex and related classes. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: REBASE Created 7 years, 3 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
« no previous file with comments | « src/v8threads.h ('k') | src/win32-headers.h » ('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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 state->set_terminate_on_restore(false); 207 state->set_terminate_on_restore(false);
208 } 208 }
209 state->set_id(ThreadId::Invalid()); 209 state->set_id(ThreadId::Invalid());
210 state->Unlink(); 210 state->Unlink();
211 state->LinkInto(ThreadState::FREE_LIST); 211 state->LinkInto(ThreadState::FREE_LIST);
212 return true; 212 return true;
213 } 213 }
214 214
215 215
216 void ThreadManager::Lock() { 216 void ThreadManager::Lock() {
217 mutex_->Lock(); 217 mutex_.Lock();
218 mutex_owner_ = ThreadId::Current(); 218 mutex_owner_ = ThreadId::Current();
219 ASSERT(IsLockedByCurrentThread()); 219 ASSERT(IsLockedByCurrentThread());
220 } 220 }
221 221
222 222
223 void ThreadManager::Unlock() { 223 void ThreadManager::Unlock() {
224 mutex_owner_ = ThreadId::Invalid(); 224 mutex_owner_ = ThreadId::Invalid();
225 mutex_->Unlock(); 225 mutex_.Unlock();
226 } 226 }
227 227
228 228
229 static int ArchiveSpacePerThread() { 229 static int ArchiveSpacePerThread() {
230 return HandleScopeImplementer::ArchiveSpacePerThread() + 230 return HandleScopeImplementer::ArchiveSpacePerThread() +
231 Isolate::ArchiveSpacePerThread() + 231 Isolate::ArchiveSpacePerThread() +
232 #ifdef ENABLE_DEBUGGER_SUPPORT 232 #ifdef ENABLE_DEBUGGER_SUPPORT
233 Debug::ArchiveSpacePerThread() + 233 Debug::ArchiveSpacePerThread() +
234 #endif 234 #endif
235 StackGuard::ArchiveSpacePerThread() + 235 StackGuard::ArchiveSpacePerThread() +
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 ThreadState* ThreadState::Next() { 296 ThreadState* ThreadState::Next() {
297 if (next_ == thread_manager_->in_use_anchor_) return NULL; 297 if (next_ == thread_manager_->in_use_anchor_) return NULL;
298 return next_; 298 return next_;
299 } 299 }
300 300
301 301
302 // Thread ids must start with 1, because in TLS having thread id 0 can't 302 // Thread ids must start with 1, because in TLS having thread id 0 can't
303 // be distinguished from not having a thread id at all (since NULL is 303 // be distinguished from not having a thread id at all (since NULL is
304 // defined as 0.) 304 // defined as 0.)
305 ThreadManager::ThreadManager() 305 ThreadManager::ThreadManager()
306 : mutex_(OS::CreateMutex()), 306 : mutex_owner_(ThreadId::Invalid()),
307 mutex_owner_(ThreadId::Invalid()),
308 lazily_archived_thread_(ThreadId::Invalid()), 307 lazily_archived_thread_(ThreadId::Invalid()),
309 lazily_archived_thread_state_(NULL), 308 lazily_archived_thread_state_(NULL),
310 free_anchor_(NULL), 309 free_anchor_(NULL),
311 in_use_anchor_(NULL) { 310 in_use_anchor_(NULL) {
312 free_anchor_ = new ThreadState(this); 311 free_anchor_ = new ThreadState(this);
313 in_use_anchor_ = new ThreadState(this); 312 in_use_anchor_ = new ThreadState(this);
314 } 313 }
315 314
316 315
317 ThreadManager::~ThreadManager() { 316 ThreadManager::~ThreadManager() {
318 delete mutex_;
319 DeleteThreadStateList(free_anchor_); 317 DeleteThreadStateList(free_anchor_);
320 DeleteThreadStateList(in_use_anchor_); 318 DeleteThreadStateList(in_use_anchor_);
321 } 319 }
322 320
323 321
324 void ThreadManager::DeleteThreadStateList(ThreadState* anchor) { 322 void ThreadManager::DeleteThreadStateList(ThreadState* anchor) {
325 // The list starts and ends with the anchor. 323 // The list starts and ends with the anchor.
326 for (ThreadState* current = anchor->next_; current != anchor;) { 324 for (ThreadState* current = anchor->next_; current != anchor;) {
327 ThreadState* next = current->next_; 325 ThreadState* next = current->next_;
328 delete current; 326 delete current;
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 // Acknowledge the preemption by the receiving thread. 483 // Acknowledge the preemption by the receiving thread.
486 void ContextSwitcher::PreemptionReceived() { 484 void ContextSwitcher::PreemptionReceived() {
487 ASSERT(Locker::IsLocked(i::Isolate::GetDefaultIsolateForLocking())); 485 ASSERT(Locker::IsLocked(i::Isolate::GetDefaultIsolateForLocking()));
488 // There is currently no accounting being done for this. But could be in the 486 // There is currently no accounting being done for this. But could be in the
489 // future, which is why we leave this in. 487 // future, which is why we leave this in.
490 } 488 }
491 489
492 490
493 } // namespace internal 491 } // namespace internal
494 } // namespace v8 492 } // namespace v8
OLDNEW
« no previous file with comments | « src/v8threads.h ('k') | src/win32-headers.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698