Changeset 19209 in webkit for trunk/JavaScriptCore/wtf
- Timestamp:
- Jan 28, 2007, 10:17:38 PM (18 years ago)
- Location:
- trunk/JavaScriptCore/wtf
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/wtf/FastMalloc.cpp
r17065 r19209 104 104 105 105 #if !PLATFORM(WIN_OS) 106 void fastMalloc RegisterThread(pthread_t)106 void fastMallocSetIsMultiThreaded() 107 107 { 108 108 } … … 382 382 private: 383 383 // How much to allocate from system at a time 384 static const int kAllocIncrement = 32 << 10;384 static const size_t kAllocIncrement = 32 << 10; 385 385 386 386 // Aligned size of T … … 1394 1394 bool isMultiThreaded; 1395 1395 TCMalloc_ThreadCache *mainThreadCache; 1396 pthread_t mainThreadID; 1397 static SpinLock multiThreadedLock = SPINLOCK_INITIALIZER; 1398 1399 void fastMallocRegisterThread(pthread_t thread) 1396 1397 void fastMallocSetIsMultiThreaded() 1400 1398 { 1401 if (thread != mainThreadID) { 1402 // We lock when writing isMultiThreaded but not when reading it. 1403 // It's ok if the main thread gets it wrong - for the main thread, the 1404 // global variable cache is the same as the thread-specific cache. 1405 // And other threads can't get it wrong because they must have gone through 1406 // this function before allocating so they've synchronized. 1407 // Also, mainThreadCache is only set when isMultiThreaded is false, 1408 // to save a branch in some cases. 1409 SpinLockHolder lock(&multiThreadedLock); 1410 isMultiThreaded = true; 1411 mainThreadCache = 0; 1412 } 1399 // We lock when writing mainThreadCache but not when reading it. It's OK if 1400 // the main thread reads a stale, non-NULL value for mainThreadCache because 1401 // mainThreadCache is the same as the main thread's thread-specific cache. 1402 // Other threads can't read a stale, non-NULL value for mainThreadCache because 1403 // clients must call this function before allocating on other threads, so they'll 1404 // 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; 1413 1412 } 1414 1413 … … 1524 1523 thread_heap_count++; 1525 1524 RecomputeThreadCacheSize(); 1526 if (!isMultiThreaded) { 1527 mainThreadCache = heap; 1528 mainThreadID = pthread_self(); 1529 } 1525 if (!isMultiThreaded) 1526 mainThreadCache = heap; 1530 1527 } 1531 1528 } … … 1857 1854 static ALWAYS_INLINE void* do_malloc(size_t size) { 1858 1855 1856 #ifdef WTF_CHANGES 1857 ASSERT(isMultiThreaded || pthread_main_np()); 1858 #endif 1859 1859 1860 #ifndef WTF_CHANGES 1860 1861 if (TCMallocDebug::level >= TCMallocDebug::kVerbose) 1861 1862 MESSAGE("In tcmalloc do_malloc(%" PRIuS")\n", size); 1862 1863 #endif 1863 1864 #ifndef WTF_CHANGES1865 1864 // The following call forces module initialization 1866 1865 TCMalloc_ThreadCache* heap = TCMalloc_ThreadCache::GetCache(); 1866 #ifndef WTF_CHANGES 1867 1867 if (heap->SampleAllocation(size)) { 1868 1868 Span* span = DoSampledAllocation(size); … … 1873 1873 if (size > kMaxSize) { 1874 1874 // Use page-level allocator 1875 if (!tsd_inited && !phinited)1876 TCMalloc_ThreadCache::InitModule();1877 1878 1875 SpinLockHolder h(&pageheap_lock); 1879 1880 1881 1876 Span* span = pageheap->New(pages(size)); 1882 1877 if (span == NULL) return NULL; 1883 1878 return reinterpret_cast<void*>(span->start << kPageShift); 1884 1879 } else { 1885 #ifdef WTF_CHANGES 1886 TCMalloc_ThreadCache* heap = TCMalloc_ThreadCache::GetCache(); 1887 #endif 1888 return heap->Allocate(size); 1880 return heap->Allocate(size); 1889 1881 } 1890 1882 } -
trunk/JavaScriptCore/wtf/FastMallocInternal.h
r17127 r19209 29 29 30 30 namespace WTF { 31 void fastMallocRegisterThread(pthread_t thread); 31 // Clients must call this function before allocating memory on a secondary thread. 32 void fastMallocSetIsMultiThreaded(); 32 33 } 33 34
Note:
See TracChangeset
for help on using the changeset viewer.