[bmalloc] Define alias for std::lock_guard and std::unique_lock for better readability
authorbasuke.suzuki@sony.com <basuke.suzuki@sony.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 18 Jan 2020 00:43:00 +0000 (00:43 +0000)
committerbasuke.suzuki@sony.com <basuke.suzuki@sony.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 18 Jan 2020 00:43:00 +0000 (00:43 +0000)
https://bugs.webkit.org/show_bug.cgi?id=206443

Reviewed by Yusuke Suzuki.

There are two types of lock holder in bmalloc: std::lock_guard and std::unique_lock. Their names are relatively long
and a bit harder to distinguish them each other. Define simple type name for them, LockHolder and UniqueLockHolder.

* bmalloc/AllIsoHeaps.cpp:
(bmalloc::AllIsoHeaps::AllIsoHeaps):
(bmalloc::AllIsoHeaps::add):
(bmalloc::AllIsoHeaps::head):
* bmalloc/AllIsoHeaps.h:
* bmalloc/Allocator.cpp:
(bmalloc::Allocator::reallocateImpl):
(bmalloc::Allocator::refillAllocatorSlowCase):
(bmalloc::Allocator::allocateLarge):
* bmalloc/CryptoRandom.cpp:
(bmalloc::ARC4RandomNumberGenerator::ARC4RandomNumberGenerator):
(bmalloc::ARC4RandomNumberGenerator::randomValues):
* bmalloc/Deallocator.cpp:
(bmalloc::Deallocator::scavenge):
(bmalloc::Deallocator::processObjectLog):
(bmalloc::Deallocator::deallocateSlowCase):
* bmalloc/Deallocator.h:
(bmalloc::Deallocator::lineCache):
* bmalloc/DebugHeap.cpp:
(bmalloc::DebugHeap::DebugHeap):
(bmalloc::DebugHeap::memalignLarge):
(bmalloc::DebugHeap::freeLarge):
* bmalloc/DebugHeap.h:
* bmalloc/DeferredTrigger.h:
* bmalloc/DeferredTriggerInlines.h:
(bmalloc::DeferredTrigger<trigger>::didBecome):
(bmalloc::DeferredTrigger<trigger>::handleDeferral):
* bmalloc/Environment.cpp:
(bmalloc::Environment::Environment):
* bmalloc/Environment.h:
* bmalloc/Gigacage.cpp:
(bmalloc::PrimitiveDisableCallbacks::PrimitiveDisableCallbacks):
(Gigacage::disablePrimitiveGigacage):
(Gigacage::addPrimitiveDisableCallback):
(Gigacage::removePrimitiveDisableCallback):
* bmalloc/Heap.cpp:
(bmalloc::Heap::Heap):
(bmalloc::Heap::freeableMemory):
(bmalloc::Heap::markAllLargeAsEligibile):
(bmalloc::Heap::decommitLargeRange):
(bmalloc::Heap::scavenge):
(bmalloc::Heap::scavengeToHighWatermark):
(bmalloc::Heap::deallocateLineCache):
(bmalloc::Heap::allocateSmallChunk):
(bmalloc::Heap::allocateSmallPage):
(bmalloc::Heap::deallocateSmallLine):
(bmalloc::Heap::allocateSmallBumpRangesByMetadata):
(bmalloc::Heap::allocateSmallBumpRangesByObject):
(bmalloc::Heap::splitAndAllocate):
(bmalloc::Heap::allocateLarge):
(bmalloc::Heap::isLarge):
(bmalloc::Heap::largeSize):
(bmalloc::Heap::shrinkLarge):
(bmalloc::Heap::deallocateLarge):
(bmalloc::Heap::externalCommit):
(bmalloc::Heap::externalDecommit):
* bmalloc/Heap.h:
(bmalloc::Heap::allocateSmallBumpRanges):
(bmalloc::Heap::derefSmallLine):
* bmalloc/HeapConstants.cpp:
(bmalloc::HeapConstants::HeapConstants):
* bmalloc/HeapConstants.h:
* bmalloc/IsoAllocatorInlines.h:
(bmalloc::IsoAllocator<Config>::allocateSlow):
(bmalloc::IsoAllocator<Config>::scavenge):
* bmalloc/IsoDeallocatorInlines.h:
(bmalloc::IsoDeallocator<Config>::deallocate):
(bmalloc::IsoDeallocator<Config>::scavenge):
* bmalloc/IsoDirectory.h:
* bmalloc/IsoDirectoryInlines.h:
(bmalloc::passedNumPages>::takeFirstEligible):
(bmalloc::passedNumPages>::didBecome):
(bmalloc::passedNumPages>::didDecommit):
(bmalloc::passedNumPages>::scavengePage):
(bmalloc::passedNumPages>::scavenge):
(bmalloc::passedNumPages>::scavengeToHighWatermark):
(bmalloc::passedNumPages>::forEachCommittedPage):
* bmalloc/IsoHeapImpl.h:
* bmalloc/IsoHeapImplInlines.h:
(bmalloc::IsoHeapImpl<Config>::takeFirstEligible):
(bmalloc::IsoHeapImpl<Config>::didBecomeEligibleOrDecommited):
(bmalloc::IsoHeapImpl<Config>::scavenge):
(bmalloc::IsoHeapImpl<Config>::scavengeToHighWatermark):
(bmalloc::IsoHeapImpl<Config>::numLiveObjects):
(bmalloc::IsoHeapImpl<Config>::numCommittedPages):
(bmalloc::IsoHeapImpl<Config>::forEachDirectory):
(bmalloc::IsoHeapImpl<Config>::forEachCommittedPage):
(bmalloc::IsoHeapImpl<Config>::forEachLiveObject):
(bmalloc::IsoHeapImpl<Config>::allocateFromShared):
* bmalloc/IsoPage.h:
* bmalloc/IsoPageInlines.h:
(bmalloc::IsoPage<Config>::free):
(bmalloc::IsoPage<Config>::startAllocating):
(bmalloc::IsoPage<Config>::stopAllocating):
(bmalloc::IsoPage<Config>::forEachLiveObject):
* bmalloc/IsoSharedHeap.h:
(bmalloc::IsoSharedHeap::IsoSharedHeap):
* bmalloc/IsoSharedHeapInlines.h:
(bmalloc::IsoSharedHeap::allocateNew):
(bmalloc::IsoSharedHeap::allocateSlow):
* bmalloc/IsoSharedPage.h:
* bmalloc/IsoSharedPageInlines.h:
(bmalloc::IsoSharedPage::free):
(bmalloc::IsoSharedPage::startAllocating):
(bmalloc::IsoSharedPage::stopAllocating):
* bmalloc/IsoTLSDeallocatorEntry.h:
* bmalloc/IsoTLSDeallocatorEntryInlines.h:
(bmalloc::IsoTLSDeallocatorEntry<Config>::IsoTLSDeallocatorEntry):
* bmalloc/IsoTLSInlines.h:
(bmalloc::IsoTLS::ensureHeap):
* bmalloc/IsoTLSLayout.cpp:
(bmalloc::IsoTLSLayout::IsoTLSLayout):
(bmalloc::IsoTLSLayout::add):
* bmalloc/IsoTLSLayout.h:
* bmalloc/Mutex.h:
(bmalloc::sleep):
(bmalloc::waitUntilFalse):
* bmalloc/ObjectType.cpp:
(bmalloc::objectType):
* bmalloc/PerProcess.cpp:
(bmalloc::getPerProcessData):
* bmalloc/PerProcess.h:
(bmalloc::PerProcess::getSlowCase):
* bmalloc/Scavenger.cpp:
(bmalloc::Scavenger::Scavenger):
(bmalloc::Scavenger::run):
(bmalloc::Scavenger::runSoon):
(bmalloc::Scavenger::scheduleIfUnderMemoryPressure):
(bmalloc::Scavenger::schedule):
(bmalloc::Scavenger::timeSinceLastFullScavenge):
(bmalloc::Scavenger::timeSinceLastPartialScavenge):
(bmalloc::Scavenger::scavenge):
(bmalloc::Scavenger::partialScavenge):
(bmalloc::Scavenger::freeableMemory):
(bmalloc::Scavenger::threadRunLoop):
* bmalloc/Scavenger.h:
* bmalloc/SmallLine.h:
(bmalloc::SmallLine::refCount):
(bmalloc::SmallLine::ref):
(bmalloc::SmallLine::deref):
* bmalloc/SmallPage.h:
(bmalloc::SmallPage::refCount):
(bmalloc::SmallPage::hasFreeLines const):
(bmalloc::SmallPage::setHasFreeLines):
(bmalloc::SmallPage::ref):
(bmalloc::SmallPage::deref):
* bmalloc/StaticPerProcess.h:
* bmalloc/VMHeap.cpp:
(bmalloc::VMHeap::VMHeap):
* bmalloc/VMHeap.h:
* bmalloc/Zone.cpp:
(bmalloc::Zone::Zone):
* bmalloc/Zone.h:
* bmalloc/bmalloc.cpp:
(bmalloc::api::tryLargeZeroedMemalignVirtual):
(bmalloc::api::freeLargeVirtual):
(bmalloc::api::setScavengerThreadQOSClass):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@254781 268f45cc-cd09-0410-ab3c-d52691b4dbfc

49 files changed:
Source/bmalloc/ChangeLog
Source/bmalloc/bmalloc/AllIsoHeaps.cpp
Source/bmalloc/bmalloc/AllIsoHeaps.h
Source/bmalloc/bmalloc/Allocator.cpp
Source/bmalloc/bmalloc/CryptoRandom.cpp
Source/bmalloc/bmalloc/Deallocator.cpp
Source/bmalloc/bmalloc/Deallocator.h
Source/bmalloc/bmalloc/DebugHeap.cpp
Source/bmalloc/bmalloc/DebugHeap.h
Source/bmalloc/bmalloc/DeferredTrigger.h
Source/bmalloc/bmalloc/DeferredTriggerInlines.h
Source/bmalloc/bmalloc/Environment.cpp
Source/bmalloc/bmalloc/Environment.h
Source/bmalloc/bmalloc/Gigacage.cpp
Source/bmalloc/bmalloc/Heap.cpp
Source/bmalloc/bmalloc/Heap.h
Source/bmalloc/bmalloc/HeapConstants.cpp
Source/bmalloc/bmalloc/HeapConstants.h
Source/bmalloc/bmalloc/IsoAllocatorInlines.h
Source/bmalloc/bmalloc/IsoDeallocatorInlines.h
Source/bmalloc/bmalloc/IsoDirectory.h
Source/bmalloc/bmalloc/IsoDirectoryInlines.h
Source/bmalloc/bmalloc/IsoHeapImpl.h
Source/bmalloc/bmalloc/IsoHeapImplInlines.h
Source/bmalloc/bmalloc/IsoPage.h
Source/bmalloc/bmalloc/IsoPageInlines.h
Source/bmalloc/bmalloc/IsoSharedHeap.h
Source/bmalloc/bmalloc/IsoSharedHeapInlines.h
Source/bmalloc/bmalloc/IsoSharedPage.h
Source/bmalloc/bmalloc/IsoSharedPageInlines.h
Source/bmalloc/bmalloc/IsoTLSDeallocatorEntry.h
Source/bmalloc/bmalloc/IsoTLSDeallocatorEntryInlines.h
Source/bmalloc/bmalloc/IsoTLSInlines.h
Source/bmalloc/bmalloc/IsoTLSLayout.cpp
Source/bmalloc/bmalloc/IsoTLSLayout.h
Source/bmalloc/bmalloc/Mutex.h
Source/bmalloc/bmalloc/ObjectType.cpp
Source/bmalloc/bmalloc/PerProcess.cpp
Source/bmalloc/bmalloc/PerProcess.h
Source/bmalloc/bmalloc/Scavenger.cpp
Source/bmalloc/bmalloc/Scavenger.h
Source/bmalloc/bmalloc/SmallLine.h
Source/bmalloc/bmalloc/SmallPage.h
Source/bmalloc/bmalloc/StaticPerProcess.h
Source/bmalloc/bmalloc/VMHeap.cpp
Source/bmalloc/bmalloc/VMHeap.h
Source/bmalloc/bmalloc/Zone.cpp
Source/bmalloc/bmalloc/Zone.h
Source/bmalloc/bmalloc/bmalloc.cpp

index 1ae66f7..20d79e3 100644 (file)
@@ -1,3 +1,171 @@
+2020-01-17  Basuke Suzuki  <basuke.suzuki@sony.com>
+
+        [bmalloc] Define alias for std::lock_guard and std::unique_lock for better readability
+        https://bugs.webkit.org/show_bug.cgi?id=206443
+
+        Reviewed by Yusuke Suzuki.
+
+        There are two types of lock holder in bmalloc: std::lock_guard and std::unique_lock. Their names are relatively long
+        and a bit harder to distinguish them each other. Define simple type name for them, LockHolder and UniqueLockHolder.
+
+        * bmalloc/AllIsoHeaps.cpp:
+        (bmalloc::AllIsoHeaps::AllIsoHeaps):
+        (bmalloc::AllIsoHeaps::add):
+        (bmalloc::AllIsoHeaps::head):
+        * bmalloc/AllIsoHeaps.h:
+        * bmalloc/Allocator.cpp:
+        (bmalloc::Allocator::reallocateImpl):
+        (bmalloc::Allocator::refillAllocatorSlowCase):
+        (bmalloc::Allocator::allocateLarge):
+        * bmalloc/CryptoRandom.cpp:
+        (bmalloc::ARC4RandomNumberGenerator::ARC4RandomNumberGenerator):
+        (bmalloc::ARC4RandomNumberGenerator::randomValues):
+        * bmalloc/Deallocator.cpp:
+        (bmalloc::Deallocator::scavenge):
+        (bmalloc::Deallocator::processObjectLog):
+        (bmalloc::Deallocator::deallocateSlowCase):
+        * bmalloc/Deallocator.h:
+        (bmalloc::Deallocator::lineCache):
+        * bmalloc/DebugHeap.cpp:
+        (bmalloc::DebugHeap::DebugHeap):
+        (bmalloc::DebugHeap::memalignLarge):
+        (bmalloc::DebugHeap::freeLarge):
+        * bmalloc/DebugHeap.h:
+        * bmalloc/DeferredTrigger.h:
+        * bmalloc/DeferredTriggerInlines.h:
+        (bmalloc::DeferredTrigger<trigger>::didBecome):
+        (bmalloc::DeferredTrigger<trigger>::handleDeferral):
+        * bmalloc/Environment.cpp:
+        (bmalloc::Environment::Environment):
+        * bmalloc/Environment.h:
+        * bmalloc/Gigacage.cpp:
+        (bmalloc::PrimitiveDisableCallbacks::PrimitiveDisableCallbacks):
+        (Gigacage::disablePrimitiveGigacage):
+        (Gigacage::addPrimitiveDisableCallback):
+        (Gigacage::removePrimitiveDisableCallback):
+        * bmalloc/Heap.cpp:
+        (bmalloc::Heap::Heap):
+        (bmalloc::Heap::freeableMemory):
+        (bmalloc::Heap::markAllLargeAsEligibile):
+        (bmalloc::Heap::decommitLargeRange):
+        (bmalloc::Heap::scavenge):
+        (bmalloc::Heap::scavengeToHighWatermark):
+        (bmalloc::Heap::deallocateLineCache):
+        (bmalloc::Heap::allocateSmallChunk):
+        (bmalloc::Heap::allocateSmallPage):
+        (bmalloc::Heap::deallocateSmallLine):
+        (bmalloc::Heap::allocateSmallBumpRangesByMetadata):
+        (bmalloc::Heap::allocateSmallBumpRangesByObject):
+        (bmalloc::Heap::splitAndAllocate):
+        (bmalloc::Heap::allocateLarge):
+        (bmalloc::Heap::isLarge):
+        (bmalloc::Heap::largeSize):
+        (bmalloc::Heap::shrinkLarge):
+        (bmalloc::Heap::deallocateLarge):
+        (bmalloc::Heap::externalCommit):
+        (bmalloc::Heap::externalDecommit):
+        * bmalloc/Heap.h:
+        (bmalloc::Heap::allocateSmallBumpRanges):
+        (bmalloc::Heap::derefSmallLine):
+        * bmalloc/HeapConstants.cpp:
+        (bmalloc::HeapConstants::HeapConstants):
+        * bmalloc/HeapConstants.h:
+        * bmalloc/IsoAllocatorInlines.h:
+        (bmalloc::IsoAllocator<Config>::allocateSlow):
+        (bmalloc::IsoAllocator<Config>::scavenge):
+        * bmalloc/IsoDeallocatorInlines.h:
+        (bmalloc::IsoDeallocator<Config>::deallocate):
+        (bmalloc::IsoDeallocator<Config>::scavenge):
+        * bmalloc/IsoDirectory.h:
+        * bmalloc/IsoDirectoryInlines.h:
+        (bmalloc::passedNumPages>::takeFirstEligible):
+        (bmalloc::passedNumPages>::didBecome):
+        (bmalloc::passedNumPages>::didDecommit):
+        (bmalloc::passedNumPages>::scavengePage):
+        (bmalloc::passedNumPages>::scavenge):
+        (bmalloc::passedNumPages>::scavengeToHighWatermark):
+        (bmalloc::passedNumPages>::forEachCommittedPage):
+        * bmalloc/IsoHeapImpl.h:
+        * bmalloc/IsoHeapImplInlines.h:
+        (bmalloc::IsoHeapImpl<Config>::takeFirstEligible):
+        (bmalloc::IsoHeapImpl<Config>::didBecomeEligibleOrDecommited):
+        (bmalloc::IsoHeapImpl<Config>::scavenge):
+        (bmalloc::IsoHeapImpl<Config>::scavengeToHighWatermark):
+        (bmalloc::IsoHeapImpl<Config>::numLiveObjects):
+        (bmalloc::IsoHeapImpl<Config>::numCommittedPages):
+        (bmalloc::IsoHeapImpl<Config>::forEachDirectory):
+        (bmalloc::IsoHeapImpl<Config>::forEachCommittedPage):
+        (bmalloc::IsoHeapImpl<Config>::forEachLiveObject):
+        (bmalloc::IsoHeapImpl<Config>::allocateFromShared):
+        * bmalloc/IsoPage.h:
+        * bmalloc/IsoPageInlines.h:
+        (bmalloc::IsoPage<Config>::free):
+        (bmalloc::IsoPage<Config>::startAllocating):
+        (bmalloc::IsoPage<Config>::stopAllocating):
+        (bmalloc::IsoPage<Config>::forEachLiveObject):
+        * bmalloc/IsoSharedHeap.h:
+        (bmalloc::IsoSharedHeap::IsoSharedHeap):
+        * bmalloc/IsoSharedHeapInlines.h:
+        (bmalloc::IsoSharedHeap::allocateNew):
+        (bmalloc::IsoSharedHeap::allocateSlow):
+        * bmalloc/IsoSharedPage.h:
+        * bmalloc/IsoSharedPageInlines.h:
+        (bmalloc::IsoSharedPage::free):
+        (bmalloc::IsoSharedPage::startAllocating):
+        (bmalloc::IsoSharedPage::stopAllocating):
+        * bmalloc/IsoTLSDeallocatorEntry.h:
+        * bmalloc/IsoTLSDeallocatorEntryInlines.h:
+        (bmalloc::IsoTLSDeallocatorEntry<Config>::IsoTLSDeallocatorEntry):
+        * bmalloc/IsoTLSInlines.h:
+        (bmalloc::IsoTLS::ensureHeap):
+        * bmalloc/IsoTLSLayout.cpp:
+        (bmalloc::IsoTLSLayout::IsoTLSLayout):
+        (bmalloc::IsoTLSLayout::add):
+        * bmalloc/IsoTLSLayout.h:
+        * bmalloc/Mutex.h:
+        (bmalloc::sleep):
+        (bmalloc::waitUntilFalse):
+        * bmalloc/ObjectType.cpp:
+        (bmalloc::objectType):
+        * bmalloc/PerProcess.cpp:
+        (bmalloc::getPerProcessData):
+        * bmalloc/PerProcess.h:
+        (bmalloc::PerProcess::getSlowCase):
+        * bmalloc/Scavenger.cpp:
+        (bmalloc::Scavenger::Scavenger):
+        (bmalloc::Scavenger::run):
+        (bmalloc::Scavenger::runSoon):
+        (bmalloc::Scavenger::scheduleIfUnderMemoryPressure):
+        (bmalloc::Scavenger::schedule):
+        (bmalloc::Scavenger::timeSinceLastFullScavenge):
+        (bmalloc::Scavenger::timeSinceLastPartialScavenge):
+        (bmalloc::Scavenger::scavenge):
+        (bmalloc::Scavenger::partialScavenge):
+        (bmalloc::Scavenger::freeableMemory):
+        (bmalloc::Scavenger::threadRunLoop):
+        * bmalloc/Scavenger.h:
+        * bmalloc/SmallLine.h:
+        (bmalloc::SmallLine::refCount):
+        (bmalloc::SmallLine::ref):
+        (bmalloc::SmallLine::deref):
+        * bmalloc/SmallPage.h:
+        (bmalloc::SmallPage::refCount):
+        (bmalloc::SmallPage::hasFreeLines const):
+        (bmalloc::SmallPage::setHasFreeLines):
+        (bmalloc::SmallPage::ref):
+        (bmalloc::SmallPage::deref):
+        * bmalloc/StaticPerProcess.h:
+        * bmalloc/VMHeap.cpp:
+        (bmalloc::VMHeap::VMHeap):
+        * bmalloc/VMHeap.h:
+        * bmalloc/Zone.cpp:
+        (bmalloc::Zone::Zone):
+        * bmalloc/Zone.h:
+        * bmalloc/bmalloc.cpp:
+        (bmalloc::api::tryLargeZeroedMemalignVirtual):
+        (bmalloc::api::freeLargeVirtual):
+        (bmalloc::api::setScavengerThreadQOSClass):
+
 2020-01-17  Yusuke Suzuki  <ysuzuki@apple.com>
 
         [bmalloc] Fix IsoHeapImpl's assertion introduced in r254708
index ca420e5..7790a1a 100644 (file)
@@ -29,20 +29,20 @@ namespace bmalloc {
 
 DEFINE_STATIC_PER_PROCESS_STORAGE(AllIsoHeaps);
 
-AllIsoHeaps::AllIsoHeaps(const std::lock_guard<Mutex>&)
+AllIsoHeaps::AllIsoHeaps(const LockHolder&)
 {
 }
 
 void AllIsoHeaps::add(IsoHeapImplBase* heap)
 {
-    std::lock_guard<Mutex> locker(mutex());
+    LockHolder locker(mutex());
     heap->m_next = m_head;
     m_head = heap;
 }
 
 IsoHeapImplBase* AllIsoHeaps::head()
 {
-    std::lock_guard<Mutex> locker(mutex());
+    LockHolder locker(mutex());
     return m_head;
 }
 
index 6fb9c06..42ddc11 100644 (file)
@@ -33,7 +33,7 @@ namespace bmalloc {
 
 class BEXPORT AllIsoHeaps : public StaticPerProcess<AllIsoHeaps> {
 public:
-    AllIsoHeaps(const std::lock_guard<Mutex>&);
+    AllIsoHeaps(const LockHolder&);
     
     void add(IsoHeapImplBase*);
     IsoHeapImplBase* head();
index 0cddd69..506d2d8 100644 (file)
@@ -76,7 +76,7 @@ void* Allocator::reallocateImpl(void* object, size_t newSize, FailureAction acti
         break;
     }
     case ObjectType::Large: {
-        std::unique_lock<Mutex> lock(Heap::mutex());
+        UniqueLockHolder lock(Heap::mutex());
         oldSize = m_heap.largeSize(lock, object);
 
         if (newSize < oldSize && newSize > smallMax) {
@@ -122,7 +122,7 @@ BNO_INLINE void Allocator::refillAllocatorSlowCase(BumpAllocator& allocator, siz
 {
     BumpRangeCache& bumpRangeCache = m_bumpRangeCaches[sizeClass];
 
-    std::unique_lock<Mutex> lock(Heap::mutex());
+    UniqueLockHolder lock(Heap::mutex());
     m_deallocator.processObjectLog(lock);
     m_heap.allocateSmallBumpRanges(lock, sizeClass, allocator, bumpRangeCache, m_deallocator.lineCache(lock), action);
 }
@@ -137,7 +137,7 @@ BINLINE void Allocator::refillAllocator(BumpAllocator& allocator, size_t sizeCla
 
 BNO_INLINE void* Allocator::allocateLarge(size_t size, FailureAction action)
 {
-    std::unique_lock<Mutex> lock(Heap::mutex());
+    UniqueLockHolder lock(Heap::mutex());
     return m_heap.allocateLarge(lock, alignment, size, action);
 }
 
index 91c35fc..dc831c8 100644 (file)
@@ -61,7 +61,7 @@ public:
 
 class ARC4RandomNumberGenerator : public StaticPerProcess<ARC4RandomNumberGenerator> {
 public:
-    ARC4RandomNumberGenerator(const std::lock_guard<Mutex>&);
+    ARC4RandomNumberGenerator(const LockHolder&);
 
     uint32_t randomNumber();
     void randomValues(void* buffer, size_t length);
@@ -86,7 +86,7 @@ ARC4Stream::ARC4Stream()
     j = 0;
 }
 
-ARC4RandomNumberGenerator::ARC4RandomNumberGenerator(const std::lock_guard<Mutex>&)
+ARC4RandomNumberGenerator::ARC4RandomNumberGenerator(const LockHolder&)
     : m_count(0)
 {
 }
@@ -164,7 +164,7 @@ uint8_t ARC4RandomNumberGenerator::getByte()
 
 void ARC4RandomNumberGenerator::randomValues(void* buffer, size_t length)
 {
-    std::lock_guard<Mutex> lock(mutex());
+    LockHolder lock(mutex());
 
     unsigned char* result = reinterpret_cast<unsigned char*>(buffer);
     stirIfNeeded();
index 3772270..d141407 100644 (file)
@@ -50,13 +50,13 @@ Deallocator::~Deallocator()
     
 void Deallocator::scavenge()
 {
-    std::unique_lock<Mutex> lock(Heap::mutex());
+    UniqueLockHolder lock(Heap::mutex());
 
     processObjectLog(lock);
     m_heap.deallocateLineCache(lock, lineCache(lock));
 }
 
-void Deallocator::processObjectLog(std::unique_lock<Mutex>& lock)
+void Deallocator::processObjectLog(UniqueLockHolder& lock)
 {
     for (Object object : m_objectLog)
         m_heap.derefSmallLine(lock, object, lineCache(lock));
@@ -68,7 +68,7 @@ void Deallocator::deallocateSlowCase(void* object)
     if (!object)
         return;
 
-    std::unique_lock<Mutex> lock(Heap::mutex());
+    UniqueLockHolder lock(Heap::mutex());
     if (m_heap.isLarge(lock, object)) {
         m_heap.deallocateLarge(lock, object);
         return;
index 1342c4c..f14feea 100644 (file)
@@ -46,9 +46,9 @@ public:
     void deallocate(void*);
     void scavenge();
     
-    void processObjectLog(std::unique_lock<Mutex>&);
+    void processObjectLog(UniqueLockHolder&);
     
-    LineCache& lineCache(std::unique_lock<Mutex>&) { return m_lineCache; }
+    LineCache& lineCache(UniqueLockHolder&) { return m_lineCache; }
 
 private:
     bool deallocateFastCase(void*);
index 2c9f5b4..e89a427 100644 (file)
@@ -40,7 +40,7 @@ DEFINE_STATIC_PER_PROCESS_STORAGE(DebugHeap);
 
 #if BOS(DARWIN)
 
-DebugHeap::DebugHeap(const std::lock_guard<Mutex>&)
+DebugHeap::DebugHeap(const LockHolder&)
     : m_zone(malloc_create_zone(0, 0))
     , m_pageSize(vmPageSize())
 {
@@ -88,7 +88,7 @@ void DebugHeap::dump()
 
 #else
 
-DebugHeap::DebugHeap(const std::lock_guard<Mutex>&)
+DebugHeap::DebugHeap(const LockHolder&)
     : m_pageSize(vmPageSize())
 {
 }
@@ -141,7 +141,7 @@ void* DebugHeap::memalignLarge(size_t alignment, size_t size)
     if (!result)
         return nullptr;
     {
-        std::lock_guard<Mutex> locker(mutex());
+        LockHolder locker(mutex());
         m_sizeMap[result] = size;
     }
     return result;
@@ -154,7 +154,7 @@ void DebugHeap::freeLarge(void* base)
     
     size_t size;
     {
-        std::lock_guard<Mutex> locker(mutex());
+        LockHolder locker(mutex());
         size = m_sizeMap[base];
         size_t numErased = m_sizeMap.erase(base);
         RELEASE_BASSERT(numErased == 1);
index 9db8552..35dc534 100644 (file)
@@ -40,7 +40,7 @@ namespace bmalloc {
     
 class DebugHeap : private StaticPerProcess<DebugHeap> {
 public:
-    DebugHeap(const std::lock_guard<Mutex>&);
+    DebugHeap(const LockHolder&);
     
     void* malloc(size_t, FailureAction);
     void* memalign(size_t alignment, size_t, FailureAction);
index 29fb197..d337a13 100644 (file)
@@ -39,10 +39,10 @@ public:
     DeferredTrigger() { }
     
     template<typename Config>
-    void didBecome(const std::lock_guard<Mutex>&, IsoPage<Config>&);
+    void didBecome(const LockHolder&, IsoPage<Config>&);
     
     template<typename Config>
-    void handleDeferral(const std::lock_guard<Mutex>&, IsoPage<Config>&);
+    void handleDeferral(const LockHolder&, IsoPage<Config>&);
     
 private:
     bool m_hasBeenDeferred { false };
index 71ea726..4272982 100644 (file)
@@ -32,7 +32,7 @@ namespace bmalloc {
 
 template<IsoPageTrigger trigger>
 template<typename Config>
-void DeferredTrigger<trigger>::didBecome(const std::lock_guard<Mutex>& locker, IsoPage<Config>& page)
+void DeferredTrigger<trigger>::didBecome(const LockHolder& locker, IsoPage<Config>& page)
 {
     if (page.isInUseForAllocation())
         m_hasBeenDeferred = true;
@@ -42,7 +42,7 @@ void DeferredTrigger<trigger>::didBecome(const std::lock_guard<Mutex>& locker, I
 
 template<IsoPageTrigger trigger>
 template<typename Config>
-void DeferredTrigger<trigger>::handleDeferral(const std::lock_guard<Mutex>& locker, IsoPage<Config>& page)
+void DeferredTrigger<trigger>::handleDeferral(const LockHolder& locker, IsoPage<Config>& page)
 {
     RELEASE_BASSERT(!page.isInUseForAllocation());
     
index 877a6c2..5a1d815 100644 (file)
@@ -127,7 +127,7 @@ static bool isNanoMallocEnabled()
 
 DEFINE_STATIC_PER_PROCESS_STORAGE(Environment);
 
-Environment::Environment(const std::lock_guard<Mutex>&)
+Environment::Environment(const LockHolder&)
     : m_isDebugHeapEnabled(computeIsDebugHeapEnabled())
 {
 }
index 7b28de9..37e5fb2 100644 (file)
@@ -33,7 +33,7 @@ namespace bmalloc {
 
 class Environment : public StaticPerProcess<Environment> {
 public:
-    BEXPORT Environment(const std::lock_guard<Mutex>&);
+    BEXPORT Environment(const LockHolder&);
     
     bool isDebugHeapEnabled() { return m_isDebugHeapEnabled; }
 
index 4201959..f04651b 100644 (file)
@@ -61,7 +61,7 @@ struct Callback {
 namespace bmalloc {
 
 struct PrimitiveDisableCallbacks : public StaticPerProcess<PrimitiveDisableCallbacks> {
-    PrimitiveDisableCallbacks(const std::lock_guard<Mutex>&) { }
+    PrimitiveDisableCallbacks(const LockHolder&) { }
     
     Vector<Gigacage::Callback> callbacks;
 };
@@ -257,7 +257,7 @@ void disablePrimitiveGigacage()
     }
     
     PrimitiveDisableCallbacks& callbacks = *PrimitiveDisableCallbacks::get();
-    std::unique_lock<Mutex> lock(PrimitiveDisableCallbacks::mutex());
+    UniqueLockHolder lock(PrimitiveDisableCallbacks::mutex());
     for (Callback& callback : callbacks.callbacks)
         callback.function(callback.argument);
     callbacks.callbacks.shrink(0);
@@ -275,14 +275,14 @@ void addPrimitiveDisableCallback(void (*function)(void*), void* argument)
     }
     
     PrimitiveDisableCallbacks& callbacks = *PrimitiveDisableCallbacks::get();
-    std::unique_lock<Mutex> lock(PrimitiveDisableCallbacks::mutex());
+    UniqueLockHolder lock(PrimitiveDisableCallbacks::mutex());
     callbacks.callbacks.push(Callback(function, argument));
 }
 
 void removePrimitiveDisableCallback(void (*function)(void*), void* argument)
 {
     PrimitiveDisableCallbacks& callbacks = *PrimitiveDisableCallbacks::get();
-    std::unique_lock<Mutex> lock(PrimitiveDisableCallbacks::mutex());
+    UniqueLockHolder lock(PrimitiveDisableCallbacks::mutex());
     for (size_t i = 0; i < callbacks.callbacks.size(); ++i) {
         if (callbacks.callbacks[i].function == function
             && callbacks.callbacks[i].argument == argument) {
index 3aae43a..6d714f0 100644 (file)
@@ -45,7 +45,7 @@
 
 namespace bmalloc {
 
-Heap::Heap(HeapKind kind, std::lock_guard<Mutex>&)
+Heap::Heap(HeapKind kind, LockHolder&)
     : m_kind { kind }, m_constants { *HeapConstants::get() }
 {
     BASSERT(!Environment::get()->isDebugHeapEnabled());
@@ -81,7 +81,7 @@ size_t Heap::gigacageSize()
     return Gigacage::size(gigacageKind(m_kind));
 }
 
-size_t Heap::freeableMemory(const std::lock_guard<Mutex>&)
+size_t Heap::freeableMemory(const LockHolder&)
 {
     return m_freeableMemory;
 }
@@ -91,14 +91,14 @@ size_t Heap::footprint()
     return m_footprint;
 }
 
-void Heap::markAllLargeAsEligibile(const std::lock_guard<Mutex>&)
+void Heap::markAllLargeAsEligibile(const LockHolder&)
 {
     m_largeFree.markAllAsEligibile();
     m_hasPendingDecommits = false;
     m_condition.notify_all();
 }
 
-void Heap::decommitLargeRange(const std::lock_guard<Mutex>&, LargeRange& range, BulkDecommit& decommitter)
+void Heap::decommitLargeRange(const LockHolder&, LargeRange& range, BulkDecommit& decommitter)
 {
     m_footprint -= range.totalPhysicalSize();
     m_freeableMemory -= range.totalPhysicalSize();
@@ -114,9 +114,9 @@ void Heap::decommitLargeRange(const std::lock_guard<Mutex>&, LargeRange& range,
 }
 
 #if BUSE(PARTIAL_SCAVENGE)
-void Heap::scavenge(const std::lock_guard<Mutex>& lock, BulkDecommit& decommitter)
+void Heap::scavenge(const LockHolder& lock, BulkDecommit& decommitter)
 #else
-void Heap::scavenge(const std::lock_guard<Mutex>& lock, BulkDecommit& decommitter, size_t& deferredDecommits)
+void Heap::scavenge(const LockHolder& lock, BulkDecommit& decommitter, size_t& deferredDecommits)
 #endif
 {
     for (auto& list : m_freePages) {
@@ -169,7 +169,7 @@ void Heap::scavenge(const std::lock_guard<Mutex>& lock, BulkDecommit& decommitte
 }
 
 #if BUSE(PARTIAL_SCAVENGE)
-void Heap::scavengeToHighWatermark(const std::lock_guard<Mutex>& lock, BulkDecommit& decommitter)
+void Heap::scavengeToHighWatermark(const LockHolder& lock, BulkDecommit& decommitter)
 {
     void* newHighWaterMark = nullptr;
     for (LargeRange& range : m_largeFree) {
@@ -182,7 +182,7 @@ void Heap::scavengeToHighWatermark(const std::lock_guard<Mutex>& lock, BulkDecom
 }
 #endif
 
-void Heap::deallocateLineCache(std::unique_lock<Mutex>&, LineCache& lineCache)
+void Heap::deallocateLineCache(UniqueLockHolder&, LineCache& lineCache)
 {
     for (auto& list : lineCache) {
         while (!list.isEmpty()) {
@@ -192,7 +192,7 @@ void Heap::deallocateLineCache(std::unique_lock<Mutex>&, LineCache& lineCache)
     }
 }
 
-void Heap::allocateSmallChunk(std::unique_lock<Mutex>& lock, size_t pageClass, FailureAction action)
+void Heap::allocateSmallChunk(UniqueLockHolder& lock, size_t pageClass, FailureAction action)
 {
     RELEASE_BASSERT(isActiveHeapKind(m_kind));
     
@@ -267,7 +267,7 @@ void Heap::deallocateSmallChunk(Chunk* chunk, size_t pageClass)
     m_largeFree.add(LargeRange(chunk, size, startPhysicalSize, totalPhysicalSize));
 }
 
-SmallPage* Heap::allocateSmallPage(std::unique_lock<Mutex>& lock, size_t sizeClass, LineCache& lineCache, FailureAction action)
+SmallPage* Heap::allocateSmallPage(UniqueLockHolder& lock, size_t sizeClass, LineCache& lineCache, FailureAction action)
 {
     RELEASE_BASSERT(isActiveHeapKind(m_kind));
 
@@ -323,7 +323,7 @@ SmallPage* Heap::allocateSmallPage(std::unique_lock<Mutex>& lock, size_t sizeCla
     return page;
 }
 
-void Heap::deallocateSmallLine(std::unique_lock<Mutex>& lock, Object object, LineCache& lineCache)
+void Heap::deallocateSmallLine(UniqueLockHolder& lock, Object object, LineCache& lineCache)
 {
     BASSERT(!object.line()->refCount(lock));
     SmallPage* page = object.page();
@@ -363,7 +363,7 @@ void Heap::deallocateSmallLine(std::unique_lock<Mutex>& lock, Object object, Lin
 }
 
 void Heap::allocateSmallBumpRangesByMetadata(
-    std::unique_lock<Mutex>& lock, size_t sizeClass,
+    UniqueLockHolder& lock, size_t sizeClass,
     BumpAllocator& allocator, BumpRangeCache& rangeCache,
     LineCache& lineCache, FailureAction action)
 {
@@ -431,7 +431,7 @@ void Heap::allocateSmallBumpRangesByMetadata(
 }
 
 void Heap::allocateSmallBumpRangesByObject(
-    std::unique_lock<Mutex>& lock, size_t sizeClass,
+    UniqueLockHolder& lock, size_t sizeClass,
     BumpAllocator& allocator, BumpRangeCache& rangeCache,
     LineCache& lineCache, FailureAction action)
 {
@@ -492,7 +492,7 @@ void Heap::allocateSmallBumpRangesByObject(
     }
 }
 
-LargeRange Heap::splitAndAllocate(std::unique_lock<Mutex>&, LargeRange& range, size_t alignment, size_t size)
+LargeRange Heap::splitAndAllocate(UniqueLockHolder&, LargeRange& range, size_t alignment, size_t size)
 {
     RELEASE_BASSERT(isActiveHeapKind(m_kind));
 
@@ -540,7 +540,7 @@ LargeRange Heap::splitAndAllocate(std::unique_lock<Mutex>&, LargeRange& range, s
     return range;
 }
 
-void* Heap::allocateLarge(std::unique_lock<Mutex>& lock, size_t alignment, size_t size, FailureAction action)
+void* Heap::allocateLarge(UniqueLockHolder& lock, size_t alignment, size_t size, FailureAction action)
 {
 #define ASSERT_OR_RETURN_ON_FAILURE(cond) do { \
         if (action == FailureAction::Crash) \
@@ -593,17 +593,17 @@ void* Heap::allocateLarge(std::unique_lock<Mutex>& lock, size_t alignment, size_
 #undef ASSERT_OR_RETURN_ON_FAILURE
 }
 
-bool Heap::isLarge(std::unique_lock<Mutex>&, void* object)
+bool Heap::isLarge(UniqueLockHolder&, void* object)
 {
     return m_objectTypes.get(Object(object).chunk()) == ObjectType::Large;
 }
 
-size_t Heap::largeSize(std::unique_lock<Mutex>&, void* object)
+size_t Heap::largeSize(UniqueLockHolder&, void* object)
 {
     return m_largeAllocated.get(object);
 }
 
-void Heap::shrinkLarge(std::unique_lock<Mutex>& lock, const Range& object, size_t newSize)
+void Heap::shrinkLarge(UniqueLockHolder& lock, const Range& object, size_t newSize)
 {
     BASSERT(object.size() > newSize);
 
@@ -614,7 +614,7 @@ void Heap::shrinkLarge(std::unique_lock<Mutex>& lock, const Range& object, size_
     m_scavenger->schedule(size);
 }
 
-void Heap::deallocateLarge(std::unique_lock<Mutex>&, void* object)
+void Heap::deallocateLarge(UniqueLockHolder&, void* object)
 {
     size_t size = m_largeAllocated.remove(object);
     m_largeFree.add(LargeRange(object, size, size, size));
@@ -624,11 +624,11 @@ void Heap::deallocateLarge(std::unique_lock<Mutex>&, void* object)
 
 void Heap::externalCommit(void* ptr, size_t size)
 {
-    std::unique_lock<Mutex> lock(Heap::mutex());
+    UniqueLockHolder lock(Heap::mutex());
     externalCommit(lock, ptr, size);
 }
 
-void Heap::externalCommit(std::unique_lock<Mutex>&, void* ptr, size_t size)
+void Heap::externalCommit(UniqueLockHolder&, void* ptr, size_t size)
 {
     BUNUSED_PARAM(ptr);
 
@@ -640,11 +640,11 @@ void Heap::externalCommit(std::unique_lock<Mutex>&, void* ptr, size_t size)
 
 void Heap::externalDecommit(void* ptr, size_t size)
 {
-    std::unique_lock<Mutex> lock(Heap::mutex());
+    UniqueLockHolder lock(Heap::mutex());
     externalDecommit(lock, ptr, size);
 }
 
-void Heap::externalDecommit(std::unique_lock<Mutex>&, void* ptr, size_t size)
+void Heap::externalDecommit(UniqueLockHolder&, void* ptr, size_t size)
 {
     BUNUSED_PARAM(ptr);
 
index 59c75f2..26d7743 100644 (file)
@@ -57,44 +57,44 @@ class Scavenger;
 
 class Heap {
 public:
-    Heap(HeapKind, std::lock_guard<Mutex>&);
+    Heap(HeapKind, LockHolder&);
     
     static Mutex& mutex() { return PerProcess<PerHeapKind<Heap>>::mutex(); }
     
     HeapKind kind() const { return m_kind; }
     
-    void allocateSmallBumpRanges(std::unique_lock<Mutex>&, size_t sizeClass,
+    void allocateSmallBumpRanges(UniqueLockHolder&, size_t sizeClass,
         BumpAllocator&, BumpRangeCache&, LineCache&, FailureAction);
-    void derefSmallLine(std::unique_lock<Mutex>&, Object, LineCache&);
-    void deallocateLineCache(std::unique_lock<Mutex>&, LineCache&);
+    void derefSmallLine(UniqueLockHolder&, Object, LineCache&);
+    void deallocateLineCache(UniqueLockHolder&, LineCache&);
 
-    void* allocateLarge(std::unique_lock<Mutex>&, size_t alignment, size_t, FailureAction);
-    void deallocateLarge(std::unique_lock<Mutex>&, void*);
+    void* allocateLarge(UniqueLockHolder&, size_t alignment, size_t, FailureAction);
+    void deallocateLarge(UniqueLockHolder&, void*);
 
-    bool isLarge(std::unique_lock<Mutex>&, void*);
-    size_t largeSize(std::unique_lock<Mutex>&, void*);
-    void shrinkLarge(std::unique_lock<Mutex>&, const Range&, size_t);
+    bool isLarge(UniqueLockHolder&, void*);
+    size_t largeSize(UniqueLockHolder&, void*);
+    void shrinkLarge(UniqueLockHolder&, const Range&, size_t);
 
 #if BUSE(PARTIAL_SCAVENGE)
-    void scavengeToHighWatermark(const std::lock_guard<Mutex>&, BulkDecommit&);
-    void scavenge(const std::lock_guard<Mutex>&, BulkDecommit&);
+    void scavengeToHighWatermark(const LockHolder&, BulkDecommit&);
+    void scavenge(const LockHolder&, BulkDecommit&);
 #else
-    void scavenge(const std::lock_guard<Mutex>&, BulkDecommit&, size_t& deferredDecommits);
+    void scavenge(const LockHolder&, BulkDecommit&, size_t& deferredDecommits);
 #endif
-    void scavenge(const std::lock_guard<Mutex>&, BulkDecommit&, size_t& freed, size_t goal);
+    void scavenge(const LockHolder&, BulkDecommit&, size_t& freed, size_t goal);
 
-    size_t freeableMemory(const std::lock_guard<Mutex>&);
+    size_t freeableMemory(const LockHolder&);
     size_t footprint();
 
     void externalDecommit(void* ptr, size_t);
-    void externalDecommit(std::unique_lock<Mutex>&, void* ptr, size_t);
+    void externalDecommit(UniqueLockHolder&, void* ptr, size_t);
     void externalCommit(void* ptr, size_t);
-    void externalCommit(std::unique_lock<Mutex>&, void* ptr, size_t);
+    void externalCommit(UniqueLockHolder&, void* ptr, size_t);
 
-    void markAllLargeAsEligibile(const std::lock_guard<Mutex>&);
+    void markAllLargeAsEligibile(const LockHolder&);
 
 private:
-    void decommitLargeRange(const std::lock_guard<Mutex>&, LargeRange&, BulkDecommit&);
+    void decommitLargeRange(const LockHolder&, LargeRange&, BulkDecommit&);
 
     struct LargeObjectHash {
         static unsigned hash(void* key)
@@ -110,22 +110,22 @@ private:
     void* gigacageBasePtr(); // May crash if !usingGigacage().
     size_t gigacageSize();
 
-    void allocateSmallBumpRangesByMetadata(std::unique_lock<Mutex>&,
+    void allocateSmallBumpRangesByMetadata(UniqueLockHolder&,
         size_t sizeClass, BumpAllocator&, BumpRangeCache&, LineCache&, FailureAction);
-    void allocateSmallBumpRangesByObject(std::unique_lock<Mutex>&,
+    void allocateSmallBumpRangesByObject(UniqueLockHolder&,
         size_t sizeClass, BumpAllocator&, BumpRangeCache&, LineCache&, FailureAction);
 
-    SmallPage* allocateSmallPage(std::unique_lock<Mutex>&, size_t sizeClass, LineCache&, FailureAction);
-    void deallocateSmallLine(std::unique_lock<Mutex>&, Object, LineCache&);
+    SmallPage* allocateSmallPage(UniqueLockHolder&, size_t sizeClass, LineCache&, FailureAction);
+    void deallocateSmallLine(UniqueLockHolder&, Object, LineCache&);
 
-    void allocateSmallChunk(std::unique_lock<Mutex>&, size_t pageClass, FailureAction);
+    void allocateSmallChunk(UniqueLockHolder&, size_t pageClass, FailureAction);
     void deallocateSmallChunk(Chunk*, size_t pageClass);
 
     void mergeLarge(BeginTag*&, EndTag*&, Range&);
     void mergeLargeLeft(EndTag*&, BeginTag*&, Range&, bool& inVMHeap);
     void mergeLargeRight(EndTag*&, BeginTag*&, Range&, bool& inVMHeap);
 
-    LargeRange splitAndAllocate(std::unique_lock<Mutex>&, LargeRange&, size_t alignment, size_t);
+    LargeRange splitAndAllocate(UniqueLockHolder&, LargeRange&, size_t alignment, size_t);
 
     HeapKind m_kind;
     HeapConstants& m_constants;
@@ -157,7 +157,7 @@ private:
 };
 
 inline void Heap::allocateSmallBumpRanges(
-    std::unique_lock<Mutex>& lock, size_t sizeClass,
+    UniqueLockHolder& lock, size_t sizeClass,
     BumpAllocator& allocator, BumpRangeCache& rangeCache,
     LineCache& lineCache, FailureAction action)
 {
@@ -166,7 +166,7 @@ inline void Heap::allocateSmallBumpRanges(
     return allocateSmallBumpRangesByObject(lock, sizeClass, allocator, rangeCache, lineCache, action);
 }
 
-inline void Heap::derefSmallLine(std::unique_lock<Mutex>& lock, Object object, LineCache& lineCache)
+inline void Heap::derefSmallLine(UniqueLockHolder& lock, Object object, LineCache& lineCache)
 {
     if (!object.line()->deref(lock))
         return;
index f384a54..4601d2f 100644 (file)
@@ -30,7 +30,7 @@ namespace bmalloc {
 
 DEFINE_STATIC_PER_PROCESS_STORAGE(HeapConstants);
 
-HeapConstants::HeapConstants(const std::lock_guard<Mutex>&)
+HeapConstants::HeapConstants(const LockHolder&)
     : m_vmPageSizePhysical { vmPageSizePhysical() }
 {
     RELEASE_BASSERT(m_vmPageSizePhysical >= smallPageSize);
index 0ebc950..fb40738 100644 (file)
@@ -37,7 +37,7 @@ namespace bmalloc {
 
 class HeapConstants : public StaticPerProcess<HeapConstants> {
 public:
-    HeapConstants(const std::lock_guard<Mutex>&);
+    HeapConstants(const LockHolder&);
     ~HeapConstants() = delete;
 
     inline size_t pageClass(size_t sizeClass) const { return m_pageClasses[sizeClass]; }
index d79f424..37f7611 100644 (file)
@@ -59,7 +59,7 @@ void* IsoAllocator<Config>::allocate(IsoHeapImpl<Config>& heap, bool abortOnFail
 template<typename Config>
 BNO_INLINE void* IsoAllocator<Config>::allocateSlow(IsoHeapImpl<Config>& heap, bool abortOnFailure)
 {
-    std::lock_guard<Mutex> locker(heap.lock);
+    LockHolder locker(heap.lock);
 
     AllocationMode allocationMode = heap.updateAllocationMode();
     if (allocationMode == AllocationMode::Shared) {
@@ -93,7 +93,7 @@ template<typename Config>
 void IsoAllocator<Config>::scavenge(IsoHeapImpl<Config>& heap)
 {
     if (m_currentPage) {
-        std::lock_guard<Mutex> locker(heap.lock);
+        LockHolder locker(heap.lock);
         m_currentPage->stopAllocating(locker, m_freeList);
         m_currentPage = nullptr;
         m_freeList.clear();
index 032fb77..3f49ee6 100644 (file)
@@ -59,7 +59,7 @@ void IsoDeallocator<Config>::deallocate(api::IsoHeap<Type>& handle, void* ptr)
     // should be rarely taken. If we see frequent malloc-and-free pattern, we tier up the allocator from shared mode to fast mode.
     IsoPageBase* page = IsoPageBase::pageFor(ptr);
     if (page->isShared()) {
-        std::lock_guard<Mutex> locker(*m_lock);
+        LockHolder locker(*m_lock);
         static_cast<IsoSharedPage*>(page)->free<Config>(locker, handle, ptr);
         return;
     }
@@ -73,7 +73,7 @@ void IsoDeallocator<Config>::deallocate(api::IsoHeap<Type>& handle, void* ptr)
 template<typename Config>
 BNO_INLINE void IsoDeallocator<Config>::scavenge()
 {
-    std::lock_guard<Mutex> locker(*m_lock);
+    LockHolder locker(*m_lock);
     
     for (void* ptr : m_objectLog)
         IsoPage<Config>::pageFor(ptr)->free(locker, ptr);
index e72b2d1..5a27111 100644 (file)
@@ -50,7 +50,7 @@ public:
     
     IsoHeapImpl<Config>& heap() { return m_heap; }
     
-    virtual void didBecome(const std::lock_guard<Mutex>&, IsoPage<Config>*, IsoPageTrigger) = 0;
+    virtual void didBecome(const LockHolder&, IsoPage<Config>*, IsoPageTrigger) = 0;
     
 protected:
     IsoHeapImpl<Config>& m_heap;
@@ -65,9 +65,9 @@ public:
     
     // Find the first page that is eligible for allocation and return it. May return null if there is no
     // such thing. May allocate a new page if we have an uncommitted page.
-    EligibilityResult<Config> takeFirstEligible(const std::lock_guard<Mutex>&);
+    EligibilityResult<Config> takeFirstEligible(const LockHolder&);
     
-    void didBecome(const std::lock_guard<Mutex>&, IsoPage<Config>*, IsoPageTrigger) override;
+    void didBecome(const LockHolder&, IsoPage<Config>*, IsoPageTrigger) override;
     
     // This gets called from a bulk decommit function in the Scavenger, so no locks are held. This function
     // needs to get the heap lock.
@@ -75,16 +75,16 @@ public:
     
     // Iterate over all empty and committed pages, and put them into the vector. This also records the
     // pages as being decommitted. It's the caller's job to do the actual decommitting.
-    void scavenge(const std::lock_guard<Mutex>&, Vector<DeferredDecommit>&);
+    void scavenge(const LockHolder&, Vector<DeferredDecommit>&);
 #if BUSE(PARTIAL_SCAVENGE)
-    void scavengeToHighWatermark(const std::lock_guard<Mutex>&, Vector<DeferredDecommit>&);
+    void scavengeToHighWatermark(const LockHolder&, Vector<DeferredDecommit>&);
 #endif
 
     template<typename Func>
-    void forEachCommittedPage(const std::lock_guard<Mutex>&, const Func&);
+    void forEachCommittedPage(const LockHolder&, const Func&);
     
 private:
-    void scavengePage(const std::lock_guard<Mutex>&, size_t, Vector<DeferredDecommit>&);
+    void scavengePage(const LockHolder&, size_t, Vector<DeferredDecommit>&);
 
     std::array<PackedAlignedPtr<IsoPage<Config>, IsoPage<Config>::pageSize>, numPages> m_pages { };
     // NOTE: I suppose that this could be two bitvectors. But from working on the GC, I found that the
index 85542df..9cf5401 100644 (file)
@@ -42,7 +42,7 @@ IsoDirectory<Config, passedNumPages>::IsoDirectory(IsoHeapImpl<Config>& heap)
 }
 
 template<typename Config, unsigned passedNumPages>
-EligibilityResult<Config> IsoDirectory<Config, passedNumPages>::takeFirstEligible(const std::lock_guard<Mutex>&)
+EligibilityResult<Config> IsoDirectory<Config, passedNumPages>::takeFirstEligible(const LockHolder&)
 {
     unsigned pageIndex = (m_eligible | ~m_committed).findBit(m_firstEligibleOrDecommitted, true);
     m_firstEligibleOrDecommitted = pageIndex;
@@ -91,7 +91,7 @@ EligibilityResult<Config> IsoDirectory<Config, passedNumPages>::takeFirstEligibl
 }
 
 template<typename Config, unsigned passedNumPages>
-void IsoDirectory<Config, passedNumPages>::didBecome(const std::lock_guard<Mutex>& locker, IsoPage<Config>* page, IsoPageTrigger trigger)
+void IsoDirectory<Config, passedNumPages>::didBecome(const LockHolder& locker, IsoPage<Config>* page, IsoPageTrigger trigger)
 {
     static constexpr bool verbose = false;
     unsigned pageIndex = page->index();
@@ -121,7 +121,7 @@ void IsoDirectory<Config, passedNumPages>::didDecommit(unsigned index)
     // FIXME: We could do this without grabbing the lock. I just doubt that it matters. This is not going
     // to be a frequently executed path, in the sense that decommitting perf will be dominated by the
     // syscall itself (which has to do many hard things).
-    std::lock_guard<Mutex> locker(this->m_heap.lock);
+    LockHolder locker(this->m_heap.lock);
     BASSERT(!!m_committed[index]);
     this->m_heap.isNoLongerFreeable(m_pages[index].get(), IsoPageBase::pageSize);
     m_committed[index] = false;
@@ -131,7 +131,7 @@ void IsoDirectory<Config, passedNumPages>::didDecommit(unsigned index)
 }
 
 template<typename Config, unsigned passedNumPages>
-void IsoDirectory<Config, passedNumPages>::scavengePage(const std::lock_guard<Mutex>&, size_t index, Vector<DeferredDecommit>& decommits)
+void IsoDirectory<Config, passedNumPages>::scavengePage(const LockHolder&, size_t index, Vector<DeferredDecommit>& decommits)
 {
     // Make sure that this page is now off limits.
     m_empty[index] = false;
@@ -140,7 +140,7 @@ void IsoDirectory<Config, passedNumPages>::scavengePage(const std::lock_guard<Mu
 }
 
 template<typename Config, unsigned passedNumPages>
-void IsoDirectory<Config, passedNumPages>::scavenge(const std::lock_guard<Mutex>& locker, Vector<DeferredDecommit>& decommits)
+void IsoDirectory<Config, passedNumPages>::scavenge(const LockHolder& locker, Vector<DeferredDecommit>& decommits)
 {
     (m_empty & m_committed).forEachSetBit(
         [&] (size_t index) {
@@ -153,7 +153,7 @@ void IsoDirectory<Config, passedNumPages>::scavenge(const std::lock_guard<Mutex>
 
 #if BUSE(PARTIAL_SCAVENGE)
 template<typename Config, unsigned passedNumPages>
-void IsoDirectory<Config, passedNumPages>::scavengeToHighWatermark(const std::lock_guard<Mutex>& locker, Vector<DeferredDecommit>& decommits)
+void IsoDirectory<Config, passedNumPages>::scavengeToHighWatermark(const LockHolder& locker, Vector<DeferredDecommit>& decommits)
 {
     (m_empty & m_committed).forEachSetBit(
         [&] (size_t index) {
@@ -166,7 +166,7 @@ void IsoDirectory<Config, passedNumPages>::scavengeToHighWatermark(const std::lo
 
 template<typename Config, unsigned passedNumPages>
 template<typename Func>
-void IsoDirectory<Config, passedNumPages>::forEachCommittedPage(const std::lock_guard<Mutex>&, const Func& func)
+void IsoDirectory<Config, passedNumPages>::forEachCommittedPage(const LockHolder&, const Func& func)
 {
     m_committed.forEachSetBit(
         [&] (size_t index) {
index 0baa808..8d06b07 100644 (file)
@@ -105,11 +105,11 @@ class IsoHeapImpl final : public IsoHeapImplBase {
 public:
     IsoHeapImpl();
     
-    EligibilityResult<Config> takeFirstEligible(const std::lock_guard<Mutex>&);
+    EligibilityResult<Config> takeFirstEligible(const LockHolder&);
     
     // Callbacks from directory.
-    void didBecomeEligibleOrDecommited(const std::lock_guard<Mutex>&, IsoDirectory<Config, numPagesInInlineDirectory>*);
-    void didBecomeEligibleOrDecommited(const std::lock_guard<Mutex>&, IsoDirectory<Config, IsoDirectoryPage<Config>::numPages>*);
+    void didBecomeEligibleOrDecommited(const LockHolder&, IsoDirectory<Config, numPagesInInlineDirectory>*);
+    void didBecomeEligibleOrDecommited(const LockHolder&, IsoDirectory<Config, IsoDirectoryPage<Config>::numPages>*);
     
     void scavenge(Vector<DeferredDecommit>&) override;
 #if BUSE(PARTIAL_SCAVENGE)
@@ -124,17 +124,17 @@ public:
     unsigned numCommittedPages();
     
     template<typename Func>
-    void forEachDirectory(const std::lock_guard<Mutex>&, const Func&);
+    void forEachDirectory(const LockHolder&, const Func&);
     
     template<typename Func>
-    void forEachCommittedPage(const std::lock_guard<Mutex>&, const Func&);
+    void forEachCommittedPage(const LockHolder&, const Func&);
     
     // This is only accurate when all threads are scavenged. Otherwise it will overestimate.
     template<typename Func>
-    void forEachLiveObject(const std::lock_guard<Mutex>&, const Func&);
+    void forEachLiveObject(const LockHolder&, const Func&);
 
     AllocationMode updateAllocationMode();
-    void* allocateFromShared(const std::lock_guard<Mutex>&, bool abortOnFailure);
+    void* allocateFromShared(const LockHolder&, bool abortOnFailure);
 
 private:
     PackedPtr<IsoDirectoryPage<Config>> m_headDirectory { nullptr };
index 7f0fc31..61e9e26 100644 (file)
@@ -41,7 +41,7 @@ IsoHeapImpl<Config>::IsoHeapImpl()
 }
 
 template<typename Config>
-EligibilityResult<Config> IsoHeapImpl<Config>::takeFirstEligible(const std::lock_guard<Mutex>& locker)
+EligibilityResult<Config> IsoHeapImpl<Config>::takeFirstEligible(const LockHolder& locker)
 {
     if (m_isInlineDirectoryEligibleOrDecommitted) {
         EligibilityResult<Config> result = m_inlineDirectory.takeFirstEligible(locker);
@@ -94,14 +94,14 @@ EligibilityResult<Config> IsoHeapImpl<Config>::takeFirstEligible(const std::lock
 }
 
 template<typename Config>
-void IsoHeapImpl<Config>::didBecomeEligibleOrDecommited(const std::lock_guard<Mutex>&, IsoDirectory<Config, numPagesInInlineDirectory>* directory)
+void IsoHeapImpl<Config>::didBecomeEligibleOrDecommited(const LockHolder&, IsoDirectory<Config, numPagesInInlineDirectory>* directory)
 {
     RELEASE_BASSERT(directory == &m_inlineDirectory);
     m_isInlineDirectoryEligibleOrDecommitted = true;
 }
 
 template<typename Config>
-void IsoHeapImpl<Config>::didBecomeEligibleOrDecommited(const std::lock_guard<Mutex>&, IsoDirectory<Config, IsoDirectoryPage<Config>::numPages>* directory)
+void IsoHeapImpl<Config>::didBecomeEligibleOrDecommited(const LockHolder&, IsoDirectory<Config, IsoDirectoryPage<Config>::numPages>* directory)
 {
     RELEASE_BASSERT(m_firstEligibleOrDecommitedDirectory);
     auto* directoryPage = IsoDirectoryPage<Config>::pageFor(directory);
@@ -112,7 +112,7 @@ void IsoHeapImpl<Config>::didBecomeEligibleOrDecommited(const std::lock_guard<Mu
 template<typename Config>
 void IsoHeapImpl<Config>::scavenge(Vector<DeferredDecommit>& decommits)
 {
-    std::lock_guard<Mutex> locker(this->lock);
+    LockHolder locker(this->lock);
     forEachDirectory(
         locker,
         [&] (auto& directory) {
@@ -125,7 +125,7 @@ void IsoHeapImpl<Config>::scavenge(Vector<DeferredDecommit>& decommits)
 template<typename Config>
 void IsoHeapImpl<Config>::scavengeToHighWatermark(Vector<DeferredDecommit>& decommits)
 {
-    std::lock_guard<Mutex> locker(this->lock);
+    LockHolder locker(this->lock);
     if (!m_directoryHighWatermark)
         m_inlineDirectory.scavengeToHighWatermark(locker, decommits);
     for (IsoDirectoryPage<Config>* page = m_headDirectory.get(); page; page = page->next) {
@@ -156,7 +156,7 @@ unsigned IsoHeapImpl<Config>::deallocatorOffset()
 template<typename Config>
 unsigned IsoHeapImpl<Config>::numLiveObjects()
 {
-    std::lock_guard<Mutex> locker(this->lock);
+    LockHolder locker(this->lock);
     unsigned result = 0;
     forEachLiveObject(
         locker,
@@ -169,7 +169,7 @@ unsigned IsoHeapImpl<Config>::numLiveObjects()
 template<typename Config>
 unsigned IsoHeapImpl<Config>::numCommittedPages()
 {
-    std::lock_guard<Mutex> locker(this->lock);
+    LockHolder locker(this->lock);
     unsigned result = 0;
     forEachCommittedPage(
         locker,
@@ -181,7 +181,7 @@ unsigned IsoHeapImpl<Config>::numCommittedPages()
 
 template<typename Config>
 template<typename Func>
-void IsoHeapImpl<Config>::forEachDirectory(const std::lock_guard<Mutex>&, const Func& func)
+void IsoHeapImpl<Config>::forEachDirectory(const LockHolder&, const Func& func)
 {
     func(m_inlineDirectory);
     for (IsoDirectoryPage<Config>* page = m_headDirectory.get(); page; page = page->next)
@@ -190,7 +190,7 @@ void IsoHeapImpl<Config>::forEachDirectory(const std::lock_guard<Mutex>&, const
 
 template<typename Config>
 template<typename Func>
-void IsoHeapImpl<Config>::forEachCommittedPage(const std::lock_guard<Mutex>& locker, const Func& func)
+void IsoHeapImpl<Config>::forEachCommittedPage(const LockHolder& locker, const Func& func)
 {
     forEachDirectory(
         locker,
@@ -201,7 +201,7 @@ void IsoHeapImpl<Config>::forEachCommittedPage(const std::lock_guard<Mutex>& loc
 
 template<typename Config>
 template<typename Func>
-void IsoHeapImpl<Config>::forEachLiveObject(const std::lock_guard<Mutex>& locker, const Func& func)
+void IsoHeapImpl<Config>::forEachLiveObject(const LockHolder& locker, const Func& func)
 {
     forEachCommittedPage(
         locker,
@@ -305,7 +305,7 @@ AllocationMode IsoHeapImpl<Config>::updateAllocationMode()
 }
 
 template<typename Config>
-void* IsoHeapImpl<Config>::allocateFromShared(const std::lock_guard<Mutex>&, bool abortOnFailure)
+void* IsoHeapImpl<Config>::allocateFromShared(const LockHolder&, bool abortOnFailure)
 {
     static constexpr bool verbose = false;
 
index a151cf9..cf5b553 100644 (file)
@@ -77,19 +77,19 @@ public:
 
     unsigned index() const { return m_index; }
     
-    void free(const std::lock_guard<Mutex>&, void*);
+    void free(const LockHolder&, void*);
 
     // Called after this page is already selected for allocation.
-    FreeList startAllocating(const std::lock_guard<Mutex>&);
+    FreeList startAllocating(const LockHolder&);
     
     // Called after the allocator picks another page to replace this one.
-    void stopAllocating(const std::lock_guard<Mutex>&, FreeList);
+    void stopAllocating(const LockHolder&, FreeList);
 
     IsoDirectoryBase<Config>& directory() { return m_directory; }
     bool isInUseForAllocation() const { return m_isInUseForAllocation; }
     
     template<typename Func>
-    void forEachLiveObject(const std::lock_guard<Mutex>&, const Func&);
+    void forEachLiveObject(const LockHolder&, const Func&);
     
     IsoHeapImpl<Config>& heap();
     
index c5ce871..e39762a 100644 (file)
@@ -65,7 +65,7 @@ IsoPage<Config>* IsoPage<Config>::pageFor(void* ptr)
 }
 
 template<typename Config>
-void IsoPage<Config>::free(const std::lock_guard<Mutex>& locker, void* passedPtr)
+void IsoPage<Config>::free(const LockHolder& locker, void* passedPtr)
 {
     BASSERT(!m_isShared);
     unsigned offset = static_cast<char*>(passedPtr) - reinterpret_cast<char*>(this);
@@ -87,7 +87,7 @@ void IsoPage<Config>::free(const std::lock_guard<Mutex>& locker, void* passedPtr
 }
 
 template<typename Config>
-FreeList IsoPage<Config>::startAllocating(const std::lock_guard<Mutex>&)
+FreeList IsoPage<Config>::startAllocating(const LockHolder&)
 {
     static constexpr bool verbose = false;
     
@@ -208,7 +208,7 @@ FreeList IsoPage<Config>::startAllocating(const std::lock_guard<Mutex>&)
 }
 
 template<typename Config>
-void IsoPage<Config>::stopAllocating(const std::lock_guard<Mutex>& locker, FreeList freeList)
+void IsoPage<Config>::stopAllocating(const LockHolder& locker, FreeList freeList)
 {
     static constexpr bool verbose = false;
     
@@ -229,7 +229,7 @@ void IsoPage<Config>::stopAllocating(const std::lock_guard<Mutex>& locker, FreeL
 
 template<typename Config>
 template<typename Func>
-void IsoPage<Config>::forEachLiveObject(const std::lock_guard<Mutex>&, const Func& func)
+void IsoPage<Config>::forEachLiveObject(const LockHolder&, const Func& func)
 {
     for (unsigned wordIndex = 0; wordIndex < bitsArrayLength(numObjects); ++wordIndex) {
         unsigned word = m_allocBits[wordIndex];
index 5ea51e5..96c414d 100644 (file)
@@ -53,7 +53,7 @@ private:
 
 class IsoSharedHeap : public StaticPerProcess<IsoSharedHeap> {
 public:
-    IsoSharedHeap(const std::lock_guard<Mutex>&)
+    IsoSharedHeap(const LockHolder&)
     {
     }
 
@@ -62,7 +62,7 @@ public:
 
 private:
     template<unsigned>
-    void* allocateSlow(const std::lock_guard<Mutex>&, bool abortOnFailure);
+    void* allocateSlow(const LockHolder&, bool abortOnFailure);
 
     IsoSharedPage* m_currentPage { nullptr };
     VariadicBumpAllocator m_allocator;
index da18e6e..7443043 100644 (file)
@@ -51,7 +51,7 @@ inline constexpr unsigned computeObjectSizeForSharedCell(unsigned objectSize)
 template<unsigned passedObjectSize>
 void* IsoSharedHeap::allocateNew(bool abortOnFailure)
 {
-    std::lock_guard<Mutex> locker(mutex());
+    LockHolder locker(mutex());
     constexpr unsigned objectSize = computeObjectSizeForSharedCell(passedObjectSize);
     return m_allocator.template allocate<objectSize>(
         [&] () -> void* {
@@ -60,7 +60,7 @@ void* IsoSharedHeap::allocateNew(bool abortOnFailure)
 }
 
 template<unsigned passedObjectSize>
-BNO_INLINE void* IsoSharedHeap::allocateSlow(const std::lock_guard<Mutex>& locker, bool abortOnFailure)
+BNO_INLINE void* IsoSharedHeap::allocateSlow(const LockHolder& locker, bool abortOnFailure)
 {
     Scavenger& scavenger = *Scavenger::get();
     scavenger.didStartGrowing();
index bff70c2..ed59481 100644 (file)
@@ -38,9 +38,9 @@ public:
     BEXPORT static IsoSharedPage* tryCreate();
 
     template<typename Config, typename Type>
-    void free(const std::lock_guard<Mutex>&, api::IsoHeap<Type>&, void*);
-    VariadicBumpAllocator startAllocating(const std::lock_guard<Mutex>&);
-    void stopAllocating(const std::lock_guard<Mutex>&);
+    void free(const LockHolder&, api::IsoHeap<Type>&, void*);
+    VariadicBumpAllocator startAllocating(const LockHolder&);
+    void stopAllocating(const LockHolder&);
 
 private:
     IsoSharedPage()
index e4410ba..15b9d0a 100644 (file)
@@ -35,7 +35,7 @@ namespace bmalloc {
 // This is because empty IsoSharedPage is still split into various different objects that should keep some part of virtual memory region dedicated.
 // We cannot set up bump allocation for such a page. Not freeing IsoSharedPages are OK since IsoSharedPage is only used for the lower tier of IsoHeap.
 template<typename Config, typename Type>
-void IsoSharedPage::free(const std::lock_guard<Mutex>&, api::IsoHeap<Type>& handle, void* ptr)
+void IsoSharedPage::free(const LockHolder&, api::IsoHeap<Type>& handle, void* ptr)
 {
     auto& heapImpl = handle.impl();
     uint8_t index = *indexSlotFor<Config>(ptr) & IsoHeapImplBase::maxAllocationFromSharedMask;
@@ -46,7 +46,7 @@ void IsoSharedPage::free(const std::lock_guard<Mutex>&, api::IsoHeap<Type>& hand
     heapImpl.m_availableShared |= (1U << index);
 }
 
-inline VariadicBumpAllocator IsoSharedPage::startAllocating(const std::lock_guard<Mutex>&)
+inline VariadicBumpAllocator IsoSharedPage::startAllocating(const LockHolder&)
 {
     static constexpr bool verbose = false;
 
@@ -61,7 +61,7 @@ inline VariadicBumpAllocator IsoSharedPage::startAllocating(const std::lock_guar
     return VariadicBumpAllocator(payloadEnd, remaining);
 }
 
-inline void IsoSharedPage::stopAllocating(const std::lock_guard<Mutex>&)
+inline void IsoSharedPage::stopAllocating(const LockHolder&)
 {
     static constexpr bool verbose = false;
 
index a0dbc30..658ec4e 100644 (file)
@@ -43,7 +43,7 @@ public:
     Mutex lock;
     
 private:
-    IsoTLSDeallocatorEntry(const std::lock_guard<Mutex>&);
+    IsoTLSDeallocatorEntry(const LockHolder&);
 
     void construct(void* entry) override;
     void scavenge(void* entry) override;
index c953428..5d94ddd 100644 (file)
@@ -28,7 +28,7 @@
 namespace bmalloc {
 
 template<typename Config>
-IsoTLSDeallocatorEntry<Config>::IsoTLSDeallocatorEntry(const std::lock_guard<Mutex>&)
+IsoTLSDeallocatorEntry<Config>::IsoTLSDeallocatorEntry(const LockHolder&)
 {
 }
 
index 0d4b201..65630af 100644 (file)
@@ -184,7 +184,7 @@ template<typename Type>
 void IsoTLS::ensureHeap(api::IsoHeap<Type>& handle)
 {
     if (!handle.isInitialized()) {
-        std::lock_guard<Mutex> locker(handle.m_initializationLock);
+        LockHolder locker(handle.m_initializationLock);
         if (!handle.isInitialized())
             handle.initialize();
     }
index 0bae607..d91b818 100644 (file)
@@ -31,7 +31,7 @@ namespace bmalloc {
 
 DEFINE_STATIC_PER_PROCESS_STORAGE(IsoTLSLayout);
 
-IsoTLSLayout::IsoTLSLayout(const std::lock_guard<Mutex>&)
+IsoTLSLayout::IsoTLSLayout(const LockHolder&)
 {
 }
 
@@ -41,7 +41,7 @@ void IsoTLSLayout::add(IsoTLSEntry* entry)
     RELEASE_BASSERT(!entry->m_next);
     // IsoTLSLayout::head() does not take a lock. So we should emit memory fence to make sure that newly added entry is initialized when it is chained to this linked-list.
     // Emitting memory fence here is OK since this function is not frequently called.
-    std::lock_guard<Mutex> locking(addingMutex);
+    LockHolder locking(addingMutex);
     if (m_head) {
         RELEASE_BASSERT(m_tail);
         size_t offset = roundUpToMultipleOf(entry->alignment(), m_tail->extent());
index 50c5096..1da5ad5 100644 (file)
@@ -35,7 +35,7 @@ class IsoTLSEntry;
 
 class IsoTLSLayout : public StaticPerProcess<IsoTLSLayout> {
 public:
-    BEXPORT IsoTLSLayout(const std::lock_guard<Mutex>&);
+    BEXPORT IsoTLSLayout(const LockHolder&);
     
     BEXPORT void add(IsoTLSEntry*);
     
index e18de84..240c85e 100644 (file)
 
 namespace bmalloc {
 
+class Mutex;
+
+using UniqueLockHolder = std::unique_lock<Mutex>;
+using LockHolder = std::lock_guard<Mutex>;
+
 class Mutex {
 public:
     constexpr Mutex() = default;
@@ -51,7 +56,7 @@ private:
 };
 
 static inline void sleep(
-    std::unique_lock<Mutex>& lock, std::chrono::milliseconds duration)
+    UniqueLockHolder& lock, std::chrono::milliseconds duration)
 {
     if (duration == std::chrono::milliseconds(0))
         return;
@@ -62,7 +67,7 @@ static inline void sleep(
 }
 
 static inline void waitUntilFalse(
-    std::unique_lock<Mutex>& lock, std::chrono::milliseconds sleepDuration,
+    UniqueLockHolder& lock, std::chrono::milliseconds sleepDuration,
     bool& condition)
 {
     while (condition) {
index 1687619..1e2fd53 100644 (file)
@@ -38,7 +38,7 @@ ObjectType objectType(Heap& heap, void* object)
         if (!object)
             return ObjectType::Small;
 
-        std::unique_lock<Mutex> lock(Heap::mutex());
+        UniqueLockHolder lock(Heap::mutex());
         if (heap.isLarge(lock, object))
             return ObjectType::Large;
     }
index 292b9f5..d82f25b 100644 (file)
@@ -60,7 +60,7 @@ static void* allocate(size_t size, size_t alignment)
 
 PerProcessData* getPerProcessData(unsigned hash, const char* disambiguator, size_t size, size_t alignment)
 {
-    std::lock_guard<Mutex> lock(s_mutex);
+    LockHolder lock(s_mutex);
 
     PerProcessData*& bucket = s_table[hash % tableSize];
     
index d263801..1a1f7a9 100644 (file)
@@ -46,7 +46,7 @@ namespace bmalloc {
 // x = object->m_field; // OK
 // if (globalFlag) { ... } // Undefined behavior.
 //
-// std::lock_guard<Mutex> lock(PerProcess<Object>::mutex());
+// LockHolder lock(PerProcess<Object>::mutex());
 // Object* object = PerProcess<Object>::get(lock);
 // if (globalFlag) { ... } // OK.
 
@@ -105,7 +105,7 @@ private:
     
     BNO_INLINE static T* getSlowCase()
     {
-        std::lock_guard<Mutex> lock(mutex());
+        LockHolder lock(mutex());
         if (!s_object.load()) {
             if (s_data->isInitialized)
                 s_object.store(static_cast<T*>(s_data->memory));
index 60f0676..d5757e2 100644 (file)
@@ -68,7 +68,7 @@ struct PrintTime {
 
 DEFINE_STATIC_PER_PROCESS_STORAGE(Scavenger);
 
-Scavenger::Scavenger(const std::lock_guard<Mutex>&)
+Scavenger::Scavenger(const LockHolder&)
 {
     BASSERT(!Environment::get()->isDebugHeapEnabled());
 
@@ -92,7 +92,7 @@ Scavenger::Scavenger(const std::lock_guard<Mutex>&)
 
 void Scavenger::run()
 {
-    std::lock_guard<Mutex> lock(mutex());
+    LockHolder lock(mutex());
     runHoldingLock();
 }
 
@@ -104,7 +104,7 @@ void Scavenger::runHoldingLock()
 
 void Scavenger::runSoon()
 {
-    std::lock_guard<Mutex> lock(mutex());
+    LockHolder lock(mutex());
     runSoonHoldingLock();
 }
 
@@ -124,7 +124,7 @@ void Scavenger::didStartGrowing()
 
 void Scavenger::scheduleIfUnderMemoryPressure(size_t bytes)
 {
-    std::lock_guard<Mutex> lock(mutex());
+    LockHolder lock(mutex());
     scheduleIfUnderMemoryPressureHoldingLock(bytes);
 }
 
@@ -148,7 +148,7 @@ void Scavenger::scheduleIfUnderMemoryPressureHoldingLock(size_t bytes)
 
 void Scavenger::schedule(size_t bytes)
 {
-    std::lock_guard<Mutex> lock(mutex());
+    LockHolder lock(mutex());
     scheduleIfUnderMemoryPressureHoldingLock(bytes);
     
     if (willRunSoon())
@@ -179,14 +179,14 @@ inline void dumpStats()
 
 std::chrono::milliseconds Scavenger::timeSinceLastFullScavenge()
 {
-    std::unique_lock<Mutex> lock(mutex());
+    UniqueLockHolder lock(mutex());
     return std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now() - m_lastFullScavengeTime);
 }
 
 #if BUSE(PARTIAL_SCAVENGE)
 std::chrono::milliseconds Scavenger::timeSinceLastPartialScavenge()
 {
-    std::unique_lock<Mutex> lock(mutex());
+    UniqueLockHolder lock(mutex());
     return std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now() - m_lastPartialScavengeTime);
 }
 #endif
@@ -200,7 +200,7 @@ void Scavenger::enableMiniMode()
 
 void Scavenger::scavenge()
 {
-    std::unique_lock<Mutex> lock(m_scavengingMutex);
+    UniqueLockHolder lock(m_scavengingMutex);
 
     if (verbose) {
         fprintf(stderr, "--------------------------------\n");
@@ -216,7 +216,7 @@ void Scavenger::scavenge()
 #if !BUSE(PARTIAL_SCAVENGE)
             size_t deferredDecommits = 0;
 #endif
-            std::lock_guard<Mutex> lock(Heap::mutex());
+            LockHolder lock(Heap::mutex());
             for (unsigned i = numHeaps; i--;) {
                 if (!isActiveHeapKind(static_cast<HeapKind>(i)))
                     continue;
@@ -241,7 +241,7 @@ void Scavenger::scavenge()
 
         {
             PrintTime printTime("full scavenge mark all as eligible time");
-            std::lock_guard<Mutex> lock(Heap::mutex());
+            LockHolder lock(Heap::mutex());
             for (unsigned i = numHeaps; i--;) {
                 if (!isActiveHeapKind(static_cast<HeapKind>(i)))
                     continue;
@@ -267,7 +267,7 @@ void Scavenger::scavenge()
     }
 
     {
-        std::unique_lock<Mutex> lock(mutex());
+        UniqueLockHolder lock(mutex());
         m_lastFullScavengeTime = std::chrono::steady_clock::now();
     }
 }
@@ -275,7 +275,7 @@ void Scavenger::scavenge()
 #if BUSE(PARTIAL_SCAVENGE)
 void Scavenger::partialScavenge()
 {
-    std::unique_lock<Mutex> lock(m_scavengingMutex);
+    UniqueLockHolder lock(m_scavengingMutex);
 
     if (verbose) {
         fprintf(stderr, "--------------------------------\n");
@@ -287,7 +287,7 @@ void Scavenger::partialScavenge()
         BulkDecommit decommitter;
         {
             PrintTime printTime("\npartialScavenge under lock time");
-            std::lock_guard<Mutex> lock(Heap::mutex());
+            LockHolder lock(Heap::mutex());
             for (unsigned i = numHeaps; i--;) {
                 if (!isActiveHeapKind(static_cast<HeapKind>(i)))
                     continue;
@@ -308,7 +308,7 @@ void Scavenger::partialScavenge()
 
         {
             PrintTime printTime("partialScavenge mark all as eligible time");
-            std::lock_guard<Mutex> lock(Heap::mutex());
+            LockHolder lock(Heap::mutex());
             for (unsigned i = numHeaps; i--;) {
                 if (!isActiveHeapKind(static_cast<HeapKind>(i)))
                     continue;
@@ -335,7 +335,7 @@ void Scavenger::partialScavenge()
     }
 
     {
-        std::unique_lock<Mutex> lock(mutex());
+        UniqueLockHolder lock(mutex());
         m_lastPartialScavengeTime = std::chrono::steady_clock::now();
     }
 }
@@ -345,7 +345,7 @@ size_t Scavenger::freeableMemory()
 {
     size_t result = 0;
     {
-        std::lock_guard<Mutex> lock(Heap::mutex());
+        LockHolder lock(Heap::mutex());
         for (unsigned i = numHeaps; i--;) {
             if (!isActiveHeapKind(static_cast<HeapKind>(i)))
                 continue;
@@ -402,12 +402,12 @@ void Scavenger::threadRunLoop()
     
     while (true) {
         if (m_state == State::Sleep) {
-            std::unique_lock<Mutex> lock(mutex());
+            UniqueLockHolder lock(mutex());
             m_condition.wait(lock, [&]() { return m_state != State::Sleep; });
         }
         
         if (m_state == State::RunSoon) {
-            std::unique_lock<Mutex> lock(mutex());
+            UniqueLockHolder lock(mutex());
             m_condition.wait_for(lock, m_waitTime, [&]() { return m_state != State::RunSoon; });
         }
         
index 728a75e..e897546 100644 (file)
@@ -42,7 +42,7 @@ namespace bmalloc {
 
 class Scavenger : public StaticPerProcess<Scavenger> {
 public:
-    BEXPORT Scavenger(const std::lock_guard<Mutex>&);
+    BEXPORT Scavenger(const LockHolder&);
     
     ~Scavenger() = delete;
     
index 6be85d3..d9b74ab 100644 (file)
@@ -35,9 +35,9 @@ namespace bmalloc {
 
 class SmallLine {
 public:
-    void ref(std::unique_lock<Mutex>&, unsigned char = 1);
-    bool deref(std::unique_lock<Mutex>&);
-    unsigned refCount(std::unique_lock<Mutex>&) { return m_refCount; }
+    void ref(UniqueLockHolder&, unsigned char = 1);
+    bool deref(UniqueLockHolder&);
+    unsigned refCount(UniqueLockHolder&) { return m_refCount; }
     
     char* begin();
     char* end();
@@ -51,13 +51,13 @@ static_assert(
 
 };
 
-inline void SmallLine::ref(std::unique_lock<Mutex>&, unsigned char refCount)
+inline void SmallLine::ref(UniqueLockHolder&, unsigned char refCount)
 {
     BASSERT(!m_refCount);
     m_refCount = refCount;
 }
 
-inline bool SmallLine::deref(std::unique_lock<Mutex>&)
+inline bool SmallLine::deref(UniqueLockHolder&)
 {
     BASSERT(m_refCount);
     --m_refCount;
index 6eab433..435e5f7 100644 (file)
@@ -38,15 +38,15 @@ class SmallLine;
 
 class SmallPage : public ListNode<SmallPage> {
 public:
-    void ref(std::unique_lock<Mutex>&);
-    bool deref(std::unique_lock<Mutex>&);
-    unsigned refCount(std::unique_lock<Mutex>&) { return m_refCount; }
+    void ref(UniqueLockHolder&);
+    bool deref(UniqueLockHolder&);
+    unsigned refCount(UniqueLockHolder&) { return m_refCount; }
     
     size_t sizeClass() { return m_sizeClass; }
     void setSizeClass(size_t sizeClass) { m_sizeClass = sizeClass; }
     
-    bool hasFreeLines(std::unique_lock<Mutex>&) const { return m_hasFreeLines; }
-    void setHasFreeLines(std::unique_lock<Mutex>&, bool hasFreeLines) { m_hasFreeLines = hasFreeLines; }
+    bool hasFreeLines(UniqueLockHolder&) const { return m_hasFreeLines; }
+    void setHasFreeLines(UniqueLockHolder&, bool hasFreeLines) { m_hasFreeLines = hasFreeLines; }
     
     bool hasPhysicalPages() { return m_hasPhysicalPages; }
     void setHasPhysicalPages(bool hasPhysicalPages) { m_hasPhysicalPages = hasPhysicalPages; }
@@ -79,14 +79,14 @@ static_assert(
 
 using LineCache = std::array<List<SmallPage>, sizeClassCount>;
 
-inline void SmallPage::ref(std::unique_lock<Mutex>&)
+inline void SmallPage::ref(UniqueLockHolder&)
 {
     BASSERT(!m_slide);
     ++m_refCount;
     BASSERT(m_refCount);
 }
 
-inline bool SmallPage::deref(std::unique_lock<Mutex>&)
+inline bool SmallPage::deref(UniqueLockHolder&)
 {
     BASSERT(!m_slide);
     BASSERT(m_refCount);
index 794b069..b805a74 100644 (file)
@@ -79,7 +79,7 @@ private:
     BNO_INLINE static T* getSlowCase()
     {
         using Storage = typename StaticPerProcessStorageTraits<T>::Storage;
-        std::lock_guard<Mutex> lock(Storage::s_mutex);
+        LockHolder lock(Storage::s_mutex);
         if (!Storage::s_object.load(std::memory_order_consume)) {
             T* t = new (&Storage::s_memory) T(lock);
             Storage::s_object.store(t, std::memory_order_release);
index adf2167..df605ff 100644 (file)
@@ -31,7 +31,7 @@ namespace bmalloc {
 
 DEFINE_STATIC_PER_PROCESS_STORAGE(VMHeap);
 
-VMHeap::VMHeap(const std::lock_guard<Mutex>&)
+VMHeap::VMHeap(const LockHolder&)
 {
 }
 
index 68f0abe..11f10e3 100644 (file)
@@ -47,7 +47,7 @@ typedef enum { Sync, Async } ScavengeMode;
 
 class VMHeap : public StaticPerProcess<VMHeap> {
 public:
-    VMHeap(const std::lock_guard<Mutex>&);
+    VMHeap(const LockHolder&);
     
     LargeRange tryAllocateLargeChunk(size_t alignment, size_t);
 };
index 0bb8296..37edd24 100644 (file)
@@ -115,7 +115,7 @@ static const malloc_introspection_t zoneIntrospect = {
     .statistics = bmalloc::statistics
 };
 
-Zone::Zone(const std::lock_guard<Mutex>&)
+Zone::Zone(const LockHolder&)
 {
     malloc_zone_t::size = &bmalloc::zoneSize;
     malloc_zone_t::zone_name = "WebKit Malloc";
index f5d6495..65d8eae 100644 (file)
@@ -42,7 +42,7 @@ public:
     // Enough capacity to track a 64GB heap, so probably enough for anything.
     static constexpr size_t capacity = 2048;
 
-    Zone(const std::lock_guard<Mutex>&);
+    Zone(const LockHolder&);
     Zone(task_t, memory_reader_t, vm_address_t);
 
     void addRange(Range);
index 16be358..a120d6e 100644 (file)
@@ -58,7 +58,7 @@ void* tryLargeZeroedMemalignVirtual(size_t requiredAlignment, size_t requestedSi
         kind = mapToActiveHeapKind(kind);
         Heap& heap = PerProcess<PerHeapKind<Heap>>::get()->at(kind);
 
-        std::unique_lock<Mutex> lock(Heap::mutex());
+        UniqueLockHolder lock(Heap::mutex());
         result = heap.allocateLarge(lock, alignment, size, FailureAction::ReturnNull);
         if (result) {
             // Don't track this as dirty memory that dictates how we drive the scavenger.
@@ -82,7 +82,7 @@ void freeLargeVirtual(void* object, size_t size, HeapKind kind)
     }
     kind = mapToActiveHeapKind(kind);
     Heap& heap = PerProcess<PerHeapKind<Heap>>::get()->at(kind);
-    std::unique_lock<Mutex> lock(Heap::mutex());
+    UniqueLockHolder lock(Heap::mutex());
     // Balance out the externalDecommit when we allocated the zeroed virtual memory.
     heap.externalCommit(lock, object, size);
     heap.deallocateLarge(lock, object);
@@ -108,7 +108,7 @@ void setScavengerThreadQOSClass(qos_class_t overrideClass)
 {
     if (DebugHeap::tryGet())
         return;
-    std::unique_lock<Mutex> lock(Heap::mutex());
+    UniqueLockHolder lock(Heap::mutex());
     Scavenger::get()->setScavengerThreadQOSClass(overrideClass);
 }
 #endif