Changeset 19245 in webkit for trunk/JavaScriptCore/wtf
- Timestamp:
- Jan 29, 2007, 9:07:25 PM (18 years ago)
- Location:
- trunk/JavaScriptCore/wtf
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/wtf/FastMalloc.cpp
r19209 r19245 1392 1392 } 1393 1393 1394 #ifdef WTF_CHANGES 1394 1395 bool isMultiThreaded; 1395 1396 TCMalloc_ThreadCache *mainThreadCache; 1396 1397 1397 void fastMallocSetIsMultiThreaded() 1398 void fastMallocSetIsMultiThreaded() 1398 1399 { 1399 1400 // We lock when writing mainThreadCache but not when reading it. It's OK if … … 1403 1404 // clients must call this function before allocating on other threads, so they'll 1404 1405 // have synchronized before reading mainThreadCache. 1405 1406 // mainThreadCache is only set when isMultiThreaded is false, to save a 1407 // branch in some cases. 1408 1409 SpinLockHolder lock(&pageheap_lock); 1410 isMultiThreaded = true; 1411 mainThreadCache = 0; 1412 } 1406 1407 // A similar principle applies to isMultiThreaded. It's OK for the main thread 1408 // in GetCache() to read a stale, false value for isMultiThreaded because 1409 // doing so will just cause it to make an unnecessary call to InitModule(), 1410 // which will synchronize it. 1411 1412 // To save a branch in some cases, mainThreadCache is only set when 1413 // isMultiThreaded is false. 1414 1415 { 1416 SpinLockHolder lock(&pageheap_lock); 1417 isMultiThreaded = true; 1418 mainThreadCache = 0; 1419 } 1420 1421 TCMalloc_ThreadCache::InitModule(); 1422 } 1423 #endif 1413 1424 1414 1425 ALWAYS_INLINE TCMalloc_ThreadCache* TCMalloc_ThreadCache::GetCache() { 1415 1426 void* ptr = NULL; 1427 #ifndef WTF_CHANGES 1416 1428 if (!tsd_inited) { 1417 1429 InitModule(); 1418 1430 } else { 1419 if (mainThreadCache) 1420 ptr = mainThreadCache; 1421 else 1422 ptr = pthread_getspecific(heap_key); 1423 } 1431 ptr = pthread_getspecific(heap_key); 1432 } 1433 #else 1434 if (mainThreadCache) // fast path for single-threaded mode 1435 return mainThreadCache; 1436 1437 if (isMultiThreaded) // fast path for multi-threaded mode -- heap_key already initialized 1438 ptr = pthread_getspecific(heap_key); 1439 else // slow path for possible first-time init 1440 InitModule(); 1441 #endif 1424 1442 if (ptr == NULL) ptr = CreateCacheIfNecessary(); 1425 1443 return reinterpret_cast<TCMalloc_ThreadCache*>(ptr); … … 1458 1476 SpinLockHolder h(&pageheap_lock); 1459 1477 if (!phinited) { 1478 #ifdef WTF_CHANGES 1479 InitTSD(); 1480 #endif 1460 1481 InitSizeClasses(); 1461 1482 threadheap_allocator.Init(); … … 1481 1502 pthread_t zero; 1482 1503 memset(&zero, 0, sizeof(zero)); 1504 #ifndef WTF_CHANGES 1483 1505 SpinLockHolder h(&pageheap_lock); 1506 #else 1507 ASSERT(pageheap_lock.IsLocked()); 1508 #endif 1484 1509 for (TCMalloc_ThreadCache* h = thread_heaps; h != NULL; h = h->next_) { 1485 1510 if (h->tid_ == zero) { … … 2053 2078 }; 2054 2079 2080 #ifndef WTF_CHANGES 2055 2081 static TCMallocGuard module_enter_exit_hook; 2056 2082 #endif 2057 2083 2058 2084 //------------------------------------------------------------------- -
trunk/JavaScriptCore/wtf/TCSpinLock.h
r13089 r19245 95 95 #endif 96 96 } 97 98 #ifdef WTF_CHANGES 99 inline bool IsLocked() { 100 return private_lockword_ != 0; 101 } 102 #endif 97 103 }; 98 104
Note:
See TracChangeset
for help on using the changeset viewer.