Changeset 26760 in webkit for trunk/JavaScriptCore/wtf/FastMalloc.cpp
- Timestamp:
- Oct 18, 2007, 7:14:09 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/wtf/FastMalloc.cpp
r25637 r26760 1185 1185 static TCMalloc_ThreadCache* GetCache(); 1186 1186 static TCMalloc_ThreadCache* GetCacheIfPresent(); 1187 static void*CreateCacheIfNecessary();1187 static TCMalloc_ThreadCache* CreateCacheIfNecessary(); 1188 1188 static void DeleteCache(void* ptr); 1189 1189 static void RecomputeThreadCacheSize(); … … 1293 1293 static bool tsd_inited = false; 1294 1294 static pthread_key_t heap_key; 1295 #if COMPILER(MSVC) 1296 __declspec(thread) TCMalloc_ThreadCache* threadHeap; 1297 #endif 1298 1299 static ALWAYS_INLINE TCMalloc_ThreadCache* getThreadHeap() 1300 { 1301 #if COMPILER(MSVC) 1302 return threadHeap; 1303 #else 1304 return static_cast<TCMalloc_ThreadCache*>(pthread_getspecific(heap_key)); 1305 #endif 1306 } 1307 1308 static ALWAYS_INLINE void setThreadHeap(TCMalloc_ThreadCache* heap) 1309 { 1310 // still do pthread_setspecific when using MSVC fast TLS to 1311 // benefit from the delete callback. 1312 pthread_setspecific(heap_key, heap); 1313 #if COMPILER(MSVC) 1314 threadHeap = heap; 1315 #endif 1316 } 1295 1317 1296 1318 // Allocator for thread heaps … … 1558 1580 1559 1581 ALWAYS_INLINE TCMalloc_ThreadCache* TCMalloc_ThreadCache::GetCache() { 1560 void* ptr = NULL;1582 TCMalloc_ThreadCache* ptr = NULL; 1561 1583 if (!tsd_inited) { 1562 1584 InitModule(); 1563 1585 } else { 1564 ptr = pthread_getspecific(heap_key);1586 ptr = getThreadHeap(); 1565 1587 } 1566 1588 if (ptr == NULL) ptr = CreateCacheIfNecessary(); 1567 return static_cast<TCMalloc_ThreadCache*>(ptr);1589 return ptr; 1568 1590 } 1569 1591 … … 1573 1595 inline TCMalloc_ThreadCache* TCMalloc_ThreadCache::GetCacheIfPresent() { 1574 1596 if (!tsd_inited) return NULL; 1575 return static_cast<TCMalloc_ThreadCache*>(pthread_getspecific(heap_key));1597 return getThreadHeap(); 1576 1598 } 1577 1599 … … 1638 1660 } 1639 1661 1640 void* TCMalloc_ThreadCache::CreateCacheIfNecessary() {1662 TCMalloc_ThreadCache* TCMalloc_ThreadCache::CreateCacheIfNecessary() { 1641 1663 // Initialize per-thread data if necessary 1642 1664 TCMalloc_ThreadCache* heap = NULL; … … 1681 1703 if (!heap->setspecific_ && tsd_inited) { 1682 1704 heap->setspecific_ = true; 1683 pthread_setspecific(heap_key,heap);1705 setThreadHeap(heap); 1684 1706 } 1685 1707 return heap;
Note:
See TracChangeset
for help on using the changeset viewer.