Changeset 53579 in webkit for trunk/JavaScriptCore/wtf/FastMalloc.cpp
- Timestamp:
- Jan 20, 2010, 5:01:54 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/wtf/FastMalloc.cpp
r53151 r53579 392 392 #include <wtf/Vector.h> 393 393 #endif 394 #if HAVE(DISPATCH_H) 395 #include <dispatch/dispatch.h> 396 #endif 397 394 398 395 399 #ifndef PRIuS … … 1373 1377 1374 1378 #if USE_BACKGROUND_THREAD_TO_SCAVENGE_MEMORY 1379 void initializeScavenger(); 1380 ALWAYS_INLINE void signalScavenger(); 1381 void scavenge(); 1382 ALWAYS_INLINE bool shouldContinueScavenging() const; 1383 1384 #if !HAVE(DISPATCH_H) 1375 1385 static NO_RETURN void* runScavengerThread(void*); 1376 1377 1386 NO_RETURN void scavengerThread(); 1378 1379 void scavenge();1380 1381 inline bool shouldContinueScavenging() const;1382 1383 pthread_mutex_t m_scavengeMutex;1384 1385 pthread_cond_t m_scavengeCondition;1386 1387 1387 1388 // Keeps track of whether the background thread is actively scavenging memory every kScavengeTimerDelayInSeconds, or 1388 1389 // it's blocked waiting for more pages to be deleted. 1389 1390 bool m_scavengeThreadActive; 1391 1392 pthread_mutex_t m_scavengeMutex; 1393 pthread_cond_t m_scavengeCondition; 1394 #else // !HAVE(DISPATCH_H) 1395 void periodicScavenge(); 1396 1397 dispatch_queue_t m_scavengeQueue; 1398 dispatch_source_t m_scavengeTimer; 1399 bool m_scavengingScheduled; 1400 #endif 1401 1390 1402 #endif // USE_BACKGROUND_THREAD_TO_SCAVENGE_MEMORY 1391 1403 }; … … 1415 1427 1416 1428 #if USE_BACKGROUND_THREAD_TO_SCAVENGE_MEMORY 1429 initializeScavenger(); 1430 #endif // USE_BACKGROUND_THREAD_TO_SCAVENGE_MEMORY 1431 } 1432 1433 #if USE_BACKGROUND_THREAD_TO_SCAVENGE_MEMORY 1434 1435 #if !HAVE(DISPATCH_H) 1436 1437 void TCMalloc_PageHeap::initializeScavenger() 1438 { 1417 1439 pthread_mutex_init(&m_scavengeMutex, 0); 1418 1440 pthread_cond_init(&m_scavengeCondition, 0); … … 1420 1442 pthread_t thread; 1421 1443 pthread_create(&thread, 0, runScavengerThread, this); 1422 #endif // USE_BACKGROUND_THREAD_TO_SCAVENGE_MEMORY 1423 } 1424 1425 #if USE_BACKGROUND_THREAD_TO_SCAVENGE_MEMORY 1444 } 1445 1426 1446 void* TCMalloc_PageHeap::runScavengerThread(void* context) 1427 1447 { … … 1432 1452 #endif 1433 1453 } 1454 1455 ALWAYS_INLINE void TCMalloc_PageHeap::signalScavenger() 1456 { 1457 if (!m_scavengeThreadActive && shouldContinueScavenging()) 1458 pthread_cond_signal(&m_scavengeCondition); 1459 } 1460 1461 #else // !HAVE(DISPATCH_H) 1462 1463 void TCMalloc_PageHeap::initializeScavenger() 1464 { 1465 m_scavengeQueue = dispatch_queue_create("com.apple.JavaScriptCore.FastMallocSavenger", NULL); 1466 m_scavengeTimer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, m_scavengeQueue); 1467 dispatch_time_t startTime = dispatch_time(DISPATCH_TIME_NOW, kScavengeTimerDelayInSeconds * NSEC_PER_SEC); 1468 dispatch_source_set_timer(m_scavengeTimer, startTime, kScavengeTimerDelayInSeconds * NSEC_PER_SEC, 1000 * NSEC_PER_USEC); 1469 dispatch_source_set_context(m_scavengeTimer, this); 1470 dispatch_source_set_event_handler(m_scavengeTimer, ^{ periodicScavenge(); }); 1471 m_scavengingScheduled = false; 1472 } 1473 1474 ALWAYS_INLINE void TCMalloc_PageHeap::signalScavenger() 1475 { 1476 if (!m_scavengingScheduled && shouldContinueScavenging()) { 1477 m_scavengingScheduled = true; 1478 dispatch_resume(m_scavengeTimer); 1479 } 1480 } 1481 1482 #endif 1434 1483 1435 1484 void TCMalloc_PageHeap::scavenge() … … 1468 1517 } 1469 1518 1470 inlinebool TCMalloc_PageHeap::shouldContinueScavenging() const1519 ALWAYS_INLINE bool TCMalloc_PageHeap::shouldContinueScavenging() const 1471 1520 { 1472 1521 return free_committed_pages_ > kMinimumFreeCommittedPageCount; … … 1730 1779 1731 1780 // Make sure the scavenge thread becomes active if we have enough freed pages to release some back to the system. 1732 if (!m_scavengeThreadActive && shouldContinueScavenging()) 1733 pthread_cond_signal(&m_scavengeCondition); 1781 signalScavenger(); 1734 1782 #else 1735 1783 IncrementalScavenge(n); … … 2274 2322 2275 2323 #if USE_BACKGROUND_THREAD_TO_SCAVENGE_MEMORY 2324 2325 #if !HAVE(DISPATCH_H) 2276 2326 #if OS(WINDOWS) 2277 2327 static void sleep(unsigned seconds) … … 2303 2353 } 2304 2354 } 2355 2356 #else 2357 2358 void TCMalloc_PageHeap::periodicScavenge() 2359 { 2360 { 2361 SpinLockHolder h(&pageheap_lock); 2362 pageheap->scavenge(); 2363 } 2364 2365 if (!shouldContinueScavenging()) { 2366 m_scavengingScheduled = false; 2367 dispatch_suspend(m_scavengeTimer); 2368 } 2369 } 2370 #endif // HAVE(DISPATCH_H) 2371 2305 2372 #endif 2306 2373
Note:
See TracChangeset
for help on using the changeset viewer.