Changeset 25366 in webkit for trunk/JavaScriptCore/wtf/FastMalloc.cpp
- Timestamp:
- Sep 4, 2007, 10:15:06 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/wtf/FastMalloc.cpp
r25365 r25366 161 161 } 162 162 163 void fastMallocSetIsMultiThreaded() 164 { 165 } 166 163 167 } // namespace WTF 164 168 … … 1547 1551 } 1548 1552 1553 #ifdef WTF_CHANGES 1554 bool isMultiThreaded; 1555 TCMalloc_ThreadCache *mainThreadCache; 1556 1557 void fastMallocSetIsMultiThreaded() 1558 { 1559 // We lock when writing mainThreadCache but not when reading it. It's OK if 1560 // the main thread reads a stale, non-NULL value for mainThreadCache because 1561 // mainThreadCache is the same as the main thread's thread-specific cache. 1562 // Other threads can't read a stale, non-NULL value for mainThreadCache because 1563 // clients must call this function before allocating on other threads, so they'll 1564 // have synchronized before reading mainThreadCache. 1565 1566 // A similar principle applies to isMultiThreaded. It's OK for the main thread 1567 // in GetCache() to read a stale, false value for isMultiThreaded because 1568 // doing so will just cause it to make an unnecessary call to InitModule(), 1569 // which will synchronize it. 1570 1571 // To save a branch in some cases, mainThreadCache is only set when 1572 // isMultiThreaded is false. 1573 1574 { 1575 SpinLockHolder lock(&pageheap_lock); 1576 isMultiThreaded = true; 1577 mainThreadCache = 0; 1578 } 1579 1580 TCMalloc_ThreadCache::InitModule(); 1581 } 1582 #endif 1583 1549 1584 ALWAYS_INLINE TCMalloc_ThreadCache* TCMalloc_ThreadCache::GetCache() { 1550 1585 void* ptr = NULL; 1586 #ifndef WTF_CHANGES 1551 1587 if (!tsd_inited) { 1552 1588 InitModule(); … … 1554 1590 ptr = pthread_getspecific(heap_key); 1555 1591 } 1592 #else 1593 if (mainThreadCache) // fast path for single-threaded mode 1594 return mainThreadCache; 1595 1596 if (isMultiThreaded) // fast path for multi-threaded mode -- heap_key already initialized 1597 ptr = pthread_getspecific(heap_key); 1598 else // slow path for possible first-time init 1599 InitModule(); 1600 #endif 1556 1601 if (ptr == NULL) ptr = CreateCacheIfNecessary(); 1557 1602 return reinterpret_cast<TCMalloc_ThreadCache*>(ptr); … … 1562 1607 // already cleaned up the cache for this thread. 1563 1608 inline TCMalloc_ThreadCache* TCMalloc_ThreadCache::GetCacheIfPresent() { 1609 if (mainThreadCache) 1610 return mainThreadCache; 1564 1611 if (!tsd_inited) return NULL; 1565 1612 return reinterpret_cast<TCMalloc_ThreadCache*> … … 1663 1710 thread_heap_count++; 1664 1711 RecomputeThreadCacheSize(); 1712 if (!isMultiThreaded) 1713 mainThreadCache = heap; 1665 1714 } 1666 1715 } … … 1993 2042 1994 2043 #ifdef WTF_CHANGES 2044 ASSERT(isMultiThreaded || pthread_main_np()); 1995 2045 ASSERT(!isForbidden()); 1996 2046 #endif
Note:
See TracChangeset
for help on using the changeset viewer.