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

Side by Side Diff: src/isolate.cc

Issue 24036002: Some thread data simplifications. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Use Mutex. 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/isolate.h ('k') | no next file » | 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 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 storage->LinkTo(&free_list_); 336 storage->LinkTo(&free_list_);
337 } 337 }
338 338
339 Isolate* Isolate::default_isolate_ = NULL; 339 Isolate* Isolate::default_isolate_ = NULL;
340 Thread::LocalStorageKey Isolate::isolate_key_; 340 Thread::LocalStorageKey Isolate::isolate_key_;
341 Thread::LocalStorageKey Isolate::thread_id_key_; 341 Thread::LocalStorageKey Isolate::thread_id_key_;
342 Thread::LocalStorageKey Isolate::per_isolate_thread_data_key_; 342 Thread::LocalStorageKey Isolate::per_isolate_thread_data_key_;
343 #ifdef DEBUG 343 #ifdef DEBUG
344 Thread::LocalStorageKey PerThreadAssertScopeBase::thread_local_key; 344 Thread::LocalStorageKey PerThreadAssertScopeBase::thread_local_key;
345 #endif // DEBUG 345 #endif // DEBUG
346 RecursiveMutex Isolate::process_wide_mutex_; 346 Mutex Isolate::process_wide_mutex_;
347 Isolate::ThreadDataTable* Isolate::thread_data_table_ = NULL; 347 Isolate::ThreadDataTable* Isolate::thread_data_table_ = NULL;
348 Atomic32 Isolate::isolate_counter_ = 0; 348 Atomic32 Isolate::isolate_counter_ = 0;
349 349
350 Isolate::PerIsolateThreadData* Isolate::AllocatePerIsolateThreadData(
351 ThreadId thread_id) {
352 ASSERT(!thread_id.Equals(ThreadId::Invalid()));
353 PerIsolateThreadData* per_thread = new PerIsolateThreadData(this, thread_id);
354 {
355 LockGuard<RecursiveMutex> lock_guard(&process_wide_mutex_);
356 ASSERT(thread_data_table_->Lookup(this, thread_id) == NULL);
357 thread_data_table_->Insert(per_thread);
358 ASSERT(thread_data_table_->Lookup(this, thread_id) == per_thread);
359 }
360 return per_thread;
361 }
362
363
364 Isolate::PerIsolateThreadData* 350 Isolate::PerIsolateThreadData*
365 Isolate::FindOrAllocatePerThreadDataForThisThread() { 351 Isolate::FindOrAllocatePerThreadDataForThisThread() {
366 ThreadId thread_id = ThreadId::Current(); 352 ThreadId thread_id = ThreadId::Current();
367 PerIsolateThreadData* per_thread = NULL; 353 PerIsolateThreadData* per_thread = NULL;
368 { 354 {
369 LockGuard<RecursiveMutex> lock_guard(&process_wide_mutex_); 355 LockGuard<Mutex> lock_guard(&process_wide_mutex_);
370 per_thread = thread_data_table_->Lookup(this, thread_id); 356 per_thread = thread_data_table_->Lookup(this, thread_id);
371 if (per_thread == NULL) { 357 if (per_thread == NULL) {
372 per_thread = AllocatePerIsolateThreadData(thread_id); 358 per_thread = new PerIsolateThreadData(this, thread_id);
359 thread_data_table_->Insert(per_thread);
373 } 360 }
374 } 361 }
362 ASSERT(thread_data_table_->Lookup(this, thread_id) == per_thread);
375 return per_thread; 363 return per_thread;
376 } 364 }
377 365
378 366
379 Isolate::PerIsolateThreadData* Isolate::FindPerThreadDataForThisThread() { 367 Isolate::PerIsolateThreadData* Isolate::FindPerThreadDataForThisThread() {
380 ThreadId thread_id = ThreadId::Current(); 368 ThreadId thread_id = ThreadId::Current();
381 return FindPerThreadDataForThread(thread_id); 369 return FindPerThreadDataForThread(thread_id);
382 } 370 }
383 371
384 372
385 Isolate::PerIsolateThreadData* Isolate::FindPerThreadDataForThread( 373 Isolate::PerIsolateThreadData* Isolate::FindPerThreadDataForThread(
386 ThreadId thread_id) { 374 ThreadId thread_id) {
387 PerIsolateThreadData* per_thread = NULL; 375 PerIsolateThreadData* per_thread = NULL;
388 { 376 {
389 LockGuard<RecursiveMutex> lock_guard(&process_wide_mutex_); 377 LockGuard<Mutex> lock_guard(&process_wide_mutex_);
390 per_thread = thread_data_table_->Lookup(this, thread_id); 378 per_thread = thread_data_table_->Lookup(this, thread_id);
391 } 379 }
392 return per_thread; 380 return per_thread;
393 } 381 }
394 382
395 383
396 void Isolate::EnsureDefaultIsolate() { 384 void Isolate::EnsureDefaultIsolate() {
397 LockGuard<RecursiveMutex> lock_guard(&process_wide_mutex_); 385 LockGuard<Mutex> lock_guard(&process_wide_mutex_);
398 if (default_isolate_ == NULL) { 386 if (default_isolate_ == NULL) {
399 isolate_key_ = Thread::CreateThreadLocalKey(); 387 isolate_key_ = Thread::CreateThreadLocalKey();
400 thread_id_key_ = Thread::CreateThreadLocalKey(); 388 thread_id_key_ = Thread::CreateThreadLocalKey();
401 per_isolate_thread_data_key_ = Thread::CreateThreadLocalKey(); 389 per_isolate_thread_data_key_ = Thread::CreateThreadLocalKey();
402 #ifdef DEBUG 390 #ifdef DEBUG
403 PerThreadAssertScopeBase::thread_local_key = Thread::CreateThreadLocalKey(); 391 PerThreadAssertScopeBase::thread_local_key = Thread::CreateThreadLocalKey();
404 #endif // DEBUG 392 #endif // DEBUG
405 thread_data_table_ = new Isolate::ThreadDataTable(); 393 thread_data_table_ = new Isolate::ThreadDataTable();
406 default_isolate_ = new Isolate(); 394 default_isolate_ = new Isolate();
407 } 395 }
(...skipping 1302 matching lines...) Expand 10 before | Expand all | Expand 10 after
1710 1698
1711 1699
1712 void Isolate::ThreadDataTable::Remove(PerIsolateThreadData* data) { 1700 void Isolate::ThreadDataTable::Remove(PerIsolateThreadData* data) {
1713 if (list_ == data) list_ = data->next_; 1701 if (list_ == data) list_ = data->next_;
1714 if (data->next_ != NULL) data->next_->prev_ = data->prev_; 1702 if (data->next_ != NULL) data->next_->prev_ = data->prev_;
1715 if (data->prev_ != NULL) data->prev_->next_ = data->next_; 1703 if (data->prev_ != NULL) data->prev_->next_ = data->next_;
1716 delete data; 1704 delete data;
1717 } 1705 }
1718 1706
1719 1707
1720 void Isolate::ThreadDataTable::Remove(Isolate* isolate,
1721 ThreadId thread_id) {
1722 PerIsolateThreadData* data = Lookup(isolate, thread_id);
1723 if (data != NULL) {
1724 Remove(data);
1725 }
1726 }
1727
1728
1729 void Isolate::ThreadDataTable::RemoveAllThreads(Isolate* isolate) { 1708 void Isolate::ThreadDataTable::RemoveAllThreads(Isolate* isolate) {
1730 PerIsolateThreadData* data = list_; 1709 PerIsolateThreadData* data = list_;
1731 while (data != NULL) { 1710 while (data != NULL) {
1732 PerIsolateThreadData* next = data->next_; 1711 PerIsolateThreadData* next = data->next_;
1733 if (data->isolate() == isolate) Remove(data); 1712 if (data->isolate() == isolate) Remove(data);
1734 data = next; 1713 data = next;
1735 } 1714 }
1736 } 1715 }
1737 1716
1738 1717
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
1857 // Temporarily set this isolate as current so that various parts of 1836 // Temporarily set this isolate as current so that various parts of
1858 // the isolate can access it in their destructors without having a 1837 // the isolate can access it in their destructors without having a
1859 // direct pointer. We don't use Enter/Exit here to avoid 1838 // direct pointer. We don't use Enter/Exit here to avoid
1860 // initializing the thread data. 1839 // initializing the thread data.
1861 PerIsolateThreadData* saved_data = CurrentPerIsolateThreadData(); 1840 PerIsolateThreadData* saved_data = CurrentPerIsolateThreadData();
1862 Isolate* saved_isolate = UncheckedCurrent(); 1841 Isolate* saved_isolate = UncheckedCurrent();
1863 SetIsolateThreadLocals(this, NULL); 1842 SetIsolateThreadLocals(this, NULL);
1864 1843
1865 Deinit(); 1844 Deinit();
1866 1845
1867 { LockGuard<RecursiveMutex> lock_guard(&process_wide_mutex_); 1846 { LockGuard<Mutex> lock_guard(&process_wide_mutex_);
1868 thread_data_table_->RemoveAllThreads(this); 1847 thread_data_table_->RemoveAllThreads(this);
1869 } 1848 }
1870 1849
1871 if (serialize_partial_snapshot_cache_ != NULL) { 1850 if (serialize_partial_snapshot_cache_ != NULL) {
1872 delete[] serialize_partial_snapshot_cache_; 1851 delete[] serialize_partial_snapshot_cache_;
1873 serialize_partial_snapshot_cache_ = NULL; 1852 serialize_partial_snapshot_cache_ = NULL;
1874 } 1853 }
1875 1854
1876 if (!IsDefaultIsolate()) { 1855 if (!IsDefaultIsolate()) {
1877 delete this; 1856 delete this;
(...skipping 656 matching lines...) Expand 10 before | Expand all | Expand 10 after
2534 2513
2535 #ifdef DEBUG 2514 #ifdef DEBUG
2536 #define ISOLATE_FIELD_OFFSET(type, name, ignored) \ 2515 #define ISOLATE_FIELD_OFFSET(type, name, ignored) \
2537 const intptr_t Isolate::name##_debug_offset_ = OFFSET_OF(Isolate, name##_); 2516 const intptr_t Isolate::name##_debug_offset_ = OFFSET_OF(Isolate, name##_);
2538 ISOLATE_INIT_LIST(ISOLATE_FIELD_OFFSET) 2517 ISOLATE_INIT_LIST(ISOLATE_FIELD_OFFSET)
2539 ISOLATE_INIT_ARRAY_LIST(ISOLATE_FIELD_OFFSET) 2518 ISOLATE_INIT_ARRAY_LIST(ISOLATE_FIELD_OFFSET)
2540 #undef ISOLATE_FIELD_OFFSET 2519 #undef ISOLATE_FIELD_OFFSET
2541 #endif 2520 #endif
2542 2521
2543 } } // namespace v8::internal 2522 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/isolate.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698