bmalloc StaticMutex's constructor should be constexpr
authorutatane.tea@gmail.com <utatane.tea@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 5 Apr 2018 18:07:28 +0000 (18:07 +0000)
committerutatane.tea@gmail.com <utatane.tea@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 5 Apr 2018 18:07:28 +0000 (18:07 +0000)
https://bugs.webkit.org/show_bug.cgi?id=180600

Reviewed by Mark Lam.

StaticMutex and Mutex can be unified. This patch changes std::atomic_flag in StaticMutex
to std::atomic<bool> to add constexpr constructor to StaticMutex. Then, StaticMutex can
be initialized in static storage without calling any static initializers.
And we also rename StaticMutex to Mutex simply.

* CMakeLists.txt:
* bmalloc.xcodeproj/project.pbxproj:
* bmalloc/AllIsoHeaps.cpp:
(bmalloc::AllIsoHeaps::AllIsoHeaps):
* bmalloc/AllIsoHeaps.h:
* bmalloc/Allocator.cpp:
(bmalloc::Allocator::tryAllocate):
(bmalloc::Allocator::allocateImpl):
(bmalloc::Allocator::reallocate):
(bmalloc::Allocator::refillAllocatorSlowCase):
(bmalloc::Allocator::allocateLarge):
* bmalloc/CryptoRandom.cpp:
(bmalloc::ARC4RandomNumberGenerator::ARC4RandomNumberGenerator):
* 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.h:
* bmalloc/Environment.cpp:
(bmalloc::Environment::Environment):
* bmalloc/Environment.h:
* bmalloc/Gigacage.cpp:
(Gigacage::disablePrimitiveGigacage):
(Gigacage::addPrimitiveDisableCallback):
(Gigacage::removePrimitiveDisableCallback):
* bmalloc/Heap.cpp:
(bmalloc::Heap::Heap):
(bmalloc::Heap::freeableMemory):
(bmalloc::Heap::scavenge):
(bmalloc::Heap::deallocateLineCache):
(bmalloc::Heap::allocateSmallChunk):
(bmalloc::Heap::allocateSmallPage):
(bmalloc::Heap::deallocateSmallLine):
(bmalloc::Heap::allocateSmallBumpRangesByMetadata):
(bmalloc::Heap::allocateSmallBumpRangesByObject):
(bmalloc::Heap::splitAndAllocate):
(bmalloc::Heap::tryAllocateLarge):
(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::mutex):
(bmalloc::Heap::allocateSmallBumpRanges):
(bmalloc::Heap::derefSmallLine):
* bmalloc/IsoDeallocator.h:
* bmalloc/IsoHeap.h:
* 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.cpp: Renamed from Source/bmalloc/bmalloc/StaticMutex.cpp.
(bmalloc::Mutex::lockSlowCase):
* bmalloc/Mutex.h:
(bmalloc::sleep):
(bmalloc::waitUntilFalse):
(bmalloc::Mutex::try_lock):
(bmalloc::Mutex::lock):
(bmalloc::Mutex::unlock):
(bmalloc::Mutex::Mutex): Deleted.
* bmalloc/ObjectType.cpp:
(bmalloc::objectType):
* bmalloc/PerProcess.cpp:
(bmalloc::getPerProcessData):
* bmalloc/PerProcess.h:
(bmalloc::PerProcess::mutex):
(bmalloc::PerProcess::getSlowCase):
* bmalloc/Scavenger.cpp:
(bmalloc::Scavenger::Scavenger):
(bmalloc::Scavenger::scavenge):
(bmalloc::Scavenger::freeableMemory):
* 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/StaticMutex.h: Removed.
* 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::isEnabled):
(bmalloc::api::setScavengerThreadQOSClass):
* bmalloc/bmalloc.h:

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

39 files changed:
Source/bmalloc/CMakeLists.txt
Source/bmalloc/ChangeLog
Source/bmalloc/bmalloc.xcodeproj/project.pbxproj
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/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/IsoDeallocator.h
Source/bmalloc/bmalloc/IsoHeap.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.cpp [moved from Source/bmalloc/bmalloc/StaticMutex.cpp with 89% similarity]
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/StaticMutex.h [deleted file]
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
Source/bmalloc/bmalloc/bmalloc.h

index b81610c..2fef48c 100644 (file)
@@ -24,10 +24,10 @@ set(bmalloc_SOURCES
     bmalloc/IsoTLSLayout.cpp
     bmalloc/LargeMap.cpp
     bmalloc/Logging.cpp
+    bmalloc/Mutex.cpp
     bmalloc/ObjectType.cpp
     bmalloc/PerProcess.cpp
     bmalloc/Scavenger.cpp
-    bmalloc/StaticMutex.cpp
     bmalloc/VMHeap.cpp
     bmalloc/bmalloc.cpp
     bmalloc/mbmalloc.cpp
index 94aa77f..d898957 100644 (file)
@@ -1,3 +1,123 @@
+2018-04-05  Yusuke Suzuki  <utatane.tea@gmail.com>
+
+        bmalloc StaticMutex's constructor should be constexpr
+        https://bugs.webkit.org/show_bug.cgi?id=180600
+
+        Reviewed by Mark Lam.
+
+        StaticMutex and Mutex can be unified. This patch changes std::atomic_flag in StaticMutex
+        to std::atomic<bool> to add constexpr constructor to StaticMutex. Then, StaticMutex can
+        be initialized in static storage without calling any static initializers.
+        And we also rename StaticMutex to Mutex simply.
+
+        * CMakeLists.txt:
+        * bmalloc.xcodeproj/project.pbxproj:
+        * bmalloc/AllIsoHeaps.cpp:
+        (bmalloc::AllIsoHeaps::AllIsoHeaps):
+        * bmalloc/AllIsoHeaps.h:
+        * bmalloc/Allocator.cpp:
+        (bmalloc::Allocator::tryAllocate):
+        (bmalloc::Allocator::allocateImpl):
+        (bmalloc::Allocator::reallocate):
+        (bmalloc::Allocator::refillAllocatorSlowCase):
+        (bmalloc::Allocator::allocateLarge):
+        * bmalloc/CryptoRandom.cpp:
+        (bmalloc::ARC4RandomNumberGenerator::ARC4RandomNumberGenerator):
+        * 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.h:
+        * bmalloc/Environment.cpp:
+        (bmalloc::Environment::Environment):
+        * bmalloc/Environment.h:
+        * bmalloc/Gigacage.cpp:
+        (Gigacage::disablePrimitiveGigacage):
+        (Gigacage::addPrimitiveDisableCallback):
+        (Gigacage::removePrimitiveDisableCallback):
+        * bmalloc/Heap.cpp:
+        (bmalloc::Heap::Heap):
+        (bmalloc::Heap::freeableMemory):
+        (bmalloc::Heap::scavenge):
+        (bmalloc::Heap::deallocateLineCache):
+        (bmalloc::Heap::allocateSmallChunk):
+        (bmalloc::Heap::allocateSmallPage):
+        (bmalloc::Heap::deallocateSmallLine):
+        (bmalloc::Heap::allocateSmallBumpRangesByMetadata):
+        (bmalloc::Heap::allocateSmallBumpRangesByObject):
+        (bmalloc::Heap::splitAndAllocate):
+        (bmalloc::Heap::tryAllocateLarge):
+        (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::mutex):
+        (bmalloc::Heap::allocateSmallBumpRanges):
+        (bmalloc::Heap::derefSmallLine):
+        * bmalloc/IsoDeallocator.h:
+        * bmalloc/IsoHeap.h:
+        * 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.cpp: Renamed from Source/bmalloc/bmalloc/StaticMutex.cpp.
+        (bmalloc::Mutex::lockSlowCase):
+        * bmalloc/Mutex.h:
+        (bmalloc::sleep):
+        (bmalloc::waitUntilFalse):
+        (bmalloc::Mutex::try_lock):
+        (bmalloc::Mutex::lock):
+        (bmalloc::Mutex::unlock):
+        (bmalloc::Mutex::Mutex): Deleted.
+        * bmalloc/ObjectType.cpp:
+        (bmalloc::objectType):
+        * bmalloc/PerProcess.cpp:
+        (bmalloc::getPerProcessData):
+        * bmalloc/PerProcess.h:
+        (bmalloc::PerProcess::mutex):
+        (bmalloc::PerProcess::getSlowCase):
+        * bmalloc/Scavenger.cpp:
+        (bmalloc::Scavenger::Scavenger):
+        (bmalloc::Scavenger::scavenge):
+        (bmalloc::Scavenger::freeableMemory):
+        * 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/StaticMutex.h: Removed.
+        * 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::isEnabled):
+        (bmalloc::api::setScavengerThreadQOSClass):
+        * bmalloc/bmalloc.h:
+
 2018-04-04  Konstantin Tokarev  <annulen@yandex.ru>
 
         Enable Gigacage unconditionally when building JSCOnly on macOS (build fix)
index 3d4e069..bed0fa2 100644 (file)
@@ -86,8 +86,8 @@
                141D9B001C8E51C0000ABBA0 /* List.h in Headers */ = {isa = PBXBuildFile; fileRef = 141D9AFF1C8E51C0000ABBA0 /* List.h */; settings = {ATTRIBUTES = (Private, ); }; };
                142B44361E2839E7001DA6E9 /* DebugHeap.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 142B44341E2839E7001DA6E9 /* DebugHeap.cpp */; };
                142B44371E2839E7001DA6E9 /* DebugHeap.h in Headers */ = {isa = PBXBuildFile; fileRef = 142B44351E2839E7001DA6E9 /* DebugHeap.h */; };
-               143CB81C19022BC900B16A45 /* StaticMutex.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 143CB81A19022BC900B16A45 /* StaticMutex.cpp */; };
-               143CB81D19022BC900B16A45 /* StaticMutex.h in Headers */ = {isa = PBXBuildFile; fileRef = 143CB81B19022BC900B16A45 /* StaticMutex.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               143CB81C19022BC900B16A45 /* Mutex.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 143CB81A19022BC900B16A45 /* Mutex.cpp */; };
+               143CB81D19022BC900B16A45 /* Mutex.h in Headers */ = {isa = PBXBuildFile; fileRef = 143CB81B19022BC900B16A45 /* Mutex.h */; settings = {ATTRIBUTES = (Private, ); }; };
                1440AFCB1A95261100837FAA /* Zone.h in Headers */ = {isa = PBXBuildFile; fileRef = 1440AFCA1A95261100837FAA /* Zone.h */; settings = {ATTRIBUTES = (Private, ); }; };
                1440AFCD1A9527AF00837FAA /* Zone.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1440AFCC1A9527AF00837FAA /* Zone.cpp */; };
                1448C30018F3754600502839 /* mbmalloc.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1448C2FF18F3754300502839 /* mbmalloc.cpp */; };
                14DD78C718F48D7500950702 /* BAssert.h in Headers */ = {isa = PBXBuildFile; fileRef = 1413E468189EEDE400546D68 /* BAssert.h */; settings = {ATTRIBUTES = (Private, ); }; };
                14DD78C818F48D7500950702 /* FixedVector.h in Headers */ = {isa = PBXBuildFile; fileRef = 14D9DB4517F2447100EAAB79 /* FixedVector.h */; settings = {ATTRIBUTES = (Private, ); }; };
                14DD78C918F48D7500950702 /* BInline.h in Headers */ = {isa = PBXBuildFile; fileRef = 1413E460189DCE1E00546D68 /* BInline.h */; settings = {ATTRIBUTES = (Private, ); }; };
-               14DD78CA18F48D7500950702 /* Mutex.h in Headers */ = {isa = PBXBuildFile; fileRef = 144DCED617A649D90093B2F2 /* Mutex.h */; settings = {ATTRIBUTES = (Private, ); }; };
                14DD78CB18F48D7500950702 /* PerProcess.h in Headers */ = {isa = PBXBuildFile; fileRef = 14446A0717A61FA400F9EA1D /* PerProcess.h */; settings = {ATTRIBUTES = (Private, ); }; };
                14DD78CC18F48D7500950702 /* PerThread.h in Headers */ = {isa = PBXBuildFile; fileRef = 144469FD17A61F1F00F9EA1D /* PerThread.h */; settings = {ATTRIBUTES = (Private, ); }; };
                14DD78CD18F48D7500950702 /* Range.h in Headers */ = {isa = PBXBuildFile; fileRef = 145F6878179E3A4400D65598 /* Range.h */; settings = {ATTRIBUTES = (Private, ); }; };
                1421A87718EE462A00B4DD68 /* Algorithm.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = Algorithm.h; path = bmalloc/Algorithm.h; sourceTree = "<group>"; };
                142B44341E2839E7001DA6E9 /* DebugHeap.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = DebugHeap.cpp; path = bmalloc/DebugHeap.cpp; sourceTree = "<group>"; };
                142B44351E2839E7001DA6E9 /* DebugHeap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DebugHeap.h; path = bmalloc/DebugHeap.h; sourceTree = "<group>"; };
-               143CB81A19022BC900B16A45 /* StaticMutex.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = StaticMutex.cpp; path = bmalloc/StaticMutex.cpp; sourceTree = "<group>"; };
-               143CB81B19022BC900B16A45 /* StaticMutex.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = StaticMutex.h; path = bmalloc/StaticMutex.h; sourceTree = "<group>"; };
+               143CB81A19022BC900B16A45 /* Mutex.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Mutex.cpp; path = bmalloc/Mutex.cpp; sourceTree = "<group>"; };
+               143CB81B19022BC900B16A45 /* Mutex.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Mutex.h; path = bmalloc/Mutex.h; sourceTree = "<group>"; };
                143E29ED18CAE90500FE8A0F /* SmallPage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SmallPage.h; path = bmalloc/SmallPage.h; sourceTree = "<group>"; };
                1440AFCA1A95261100837FAA /* Zone.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Zone.h; path = bmalloc/Zone.h; sourceTree = "<group>"; };
                1440AFCC1A9527AF00837FAA /* Zone.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Zone.cpp; path = bmalloc/Zone.cpp; sourceTree = "<group>"; };
                144BE11E1CA346520099C8C0 /* Object.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Object.h; path = bmalloc/Object.h; sourceTree = "<group>"; };
                144C07F21C7B70260051BB6A /* LargeMap.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = LargeMap.cpp; path = bmalloc/LargeMap.cpp; sourceTree = "<group>"; };
                144C07F31C7B70260051BB6A /* LargeMap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = LargeMap.h; path = bmalloc/LargeMap.h; sourceTree = "<group>"; };
-               144DCED617A649D90093B2F2 /* Mutex.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Mutex.h; path = bmalloc/Mutex.h; sourceTree = "<group>"; };
                144F7BFB18BFC517003537F3 /* VMHeap.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = VMHeap.cpp; path = bmalloc/VMHeap.cpp; sourceTree = "<group>"; };
                144F7BFC18BFC517003537F3 /* VMHeap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = VMHeap.h; path = bmalloc/VMHeap.h; sourceTree = "<group>"; };
                1452478618BC757C00F80098 /* SmallLine.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SmallLine.h; path = bmalloc/SmallLine.h; sourceTree = "<group>"; };
                                1448C2FD18F3752B00502839 /* api */,
                                14D9DB4D17F2865C00EAAB79 /* cache */,
                                14B650C418F39F4800751968 /* Configurations */,
+                               0F7EB7F91F95414C00F1ABCB /* Frameworks */,
                                14D9DB4E17F2866E00EAAB79 /* heap */,
                                147AAA9C18CE6010002201E4 /* heap: large */,
                                147AAA9A18CE5FD3002201E4 /* heap: small */,
                                0F7EB7FB1F95416900F1ABCB /* iso */,
-                               0F7EB7F01F95285300F1ABCB /* test */,
                                145F6840179DC45F00D65598 /* Products */,
                                14D9DB4F17F2868900EAAB79 /* stdlib */,
-                               0F7EB7F91F95414C00F1ABCB /* Frameworks */,
+                               0F7EB7F01F95285300F1ABCB /* test */,
                        );
                        sourceTree = "<group>";
                };
                145F6840179DC45F00D65598 /* Products */ = {
                        isa = PBXGroup;
                        children = (
+                               0F7EB7EF1F95285300F1ABCB /* testbmalloc */,
                                14F271BE18EA3963008C152F /* libbmalloc.a */,
                                14CC394418EA8743004AFE34 /* libmbmalloc.dylib */,
-                               0F7EB7EF1F95285300F1ABCB /* testbmalloc */,
                        );
                        name = Products;
                        sourceTree = "<group>";
                14D9DB4F17F2868900EAAB79 /* stdlib */ = {
                        isa = PBXGroup;
                        children = (
+                               4408F2961C9896C40012EC64 /* darwin */,
                                1421A87718EE462A00B4DD68 /* Algorithm.h */,
                                6599C5CA1EC3F15900A2F7BB /* AvailableMemory.cpp */,
                                6599C5CB1EC3F15900A2F7BB /* AvailableMemory.h */,
                                14C919C818FCC59F0028DB43 /* BPlatform.h */,
                                0F74B93D1F89713E00B935D3 /* CryptoRandom.cpp */,
                                0F74B93C1F89713E00B935D3 /* CryptoRandom.h */,
-                               4408F2961C9896C40012EC64 /* darwin */,
                                14D9DB4517F2447100EAAB79 /* FixedVector.h */,
                                0FD557321F7EDB7B00B1F0A3 /* HeapKind.cpp */,
                                0F5BF1461F22A8B10029D91D /* HeapKind.h */,
                                4426E27E1C838EE0008EB042 /* Logging.cpp */,
                                4426E27F1C838EE0008EB042 /* Logging.h */,
                                14C8992A1CC485E70027A057 /* Map.h */,
-                               144DCED617A649D90093B2F2 /* Mutex.h */,
-                               0F26A7A42054830D0090A141 /* PerProcess.cpp */,
+                               143CB81A19022BC900B16A45 /* Mutex.cpp */,
+                               143CB81B19022BC900B16A45 /* Mutex.h */,
                                0F5BF1481F22A8D80029D91D /* PerHeapKind.h */,
+                               0F26A7A42054830D0090A141 /* PerProcess.cpp */,
                                14446A0717A61FA400F9EA1D /* PerProcess.h */,
                                144469FD17A61F1F00F9EA1D /* PerThread.h */,
                                145F6878179E3A4400D65598 /* Range.h */,
                                148EFAE61D6B953B008E721E /* ScopeExit.h */,
-                               143CB81A19022BC900B16A45 /* StaticMutex.cpp */,
-                               143CB81B19022BC900B16A45 /* StaticMutex.h */,
                                1417F64F18B7280C0076FA3F /* Syscall.h */,
                                1479E21217A1A255006D4E9D /* Vector.h */,
                                1479E21417A1A63E006D4E9D /* VMAllocate.h */,
                        buildActionMask = 2147483647;
                        files = (
                                14DD78C518F48D7500950702 /* Algorithm.h in Headers */,
+                               0F7EB8341F9541B000F1ABCB /* AllIsoHeaps.h in Headers */,
+                               0F7EB84F1F954D4E00F1ABCB /* AllIsoHeapsInlines.h in Headers */,
                                14DD789818F48D4A00950702 /* Allocator.h in Headers */,
-                               0F5BF1531F22E1570029D91D /* Scavenger.h in Headers */,
-                               0F7EB8291F9541B000F1ABCB /* FreeListInlines.h in Headers */,
-                               0F7EB85A1F955A1100F1ABCB /* DeferredDecommitInlines.h in Headers */,
-                               0F7EB8371F9541B000F1ABCB /* IsoDirectory.h in Headers */,
-                               0F5BF1471F22A8B10029D91D /* HeapKind.h in Headers */,
                                6599C5CD1EC3F15900A2F7BB /* AvailableMemory.h in Headers */,
-                               0F7EB8451F9541B000F1ABCB /* IsoHeapImpl.h in Headers */,
                                14DD78C718F48D7500950702 /* BAssert.h in Headers */,
+                               AD0934331FCF406D00E85EB5 /* BCompiler.h in Headers */,
+                               0F5BF1731F23C5710029D91D /* BExport.h in Headers */,
+                               14DD78C918F48D7500950702 /* BInline.h in Headers */,
+                               0F7EB84C1F9541C700F1ABCB /* Bits.h in Headers */,
                                1448C30118F3754C00502839 /* bmalloc.h in Headers */,
-                               0F7EB8381F9541B000F1ABCB /* EligibilityResultInlines.h in Headers */,
+                               0F7EB84D1F9541C700F1ABCB /* BMalloced.h in Headers */,
                                14C919C918FCC59F0028DB43 /* BPlatform.h in Headers */,
                                4426E2831C839547008EB042 /* BSoftLinking.h in Headers */,
-                               0F7EB8461F9541B000F1ABCB /* IsoTLSInlines.h in Headers */,
-                               0F7EB8421F9541B000F1ABCB /* IsoTLS.h in Headers */,
-                               0F7EB84F1F954D4E00F1ABCB /* AllIsoHeapsInlines.h in Headers */,
                                14DD789C18F48D4A00950702 /* BumpAllocator.h in Headers */,
-                               0F7EB8231F9541B000F1ABCB /* EligibilityResult.h in Headers */,
-                               0F74B93E1F89713E00B935D3 /* CryptoRandom.h in Headers */,
                                140FA00319CE429C00FFD3C8 /* BumpRange.h in Headers */,
                                14DD789918F48D4A00950702 /* Cache.h in Headers */,
                                147DC6E31CA5B70B00724E8D /* Chunk.h in Headers */,
-                               0F7EB82C1F9541B000F1ABCB /* IsoHeap.h in Headers */,
-                               0F5BF1731F23C5710029D91D /* BExport.h in Headers */,
-                               0F7EB83C1F9541B000F1ABCB /* IsoAllocator.h in Headers */,
-                               0F7EB8431F9541B000F1ABCB /* IsoTLSAllocatorEntry.h in Headers */,
+                               0F74B93E1F89713E00B935D3 /* CryptoRandom.h in Headers */,
                                14DD789A18F48D4A00950702 /* Deallocator.h in Headers */,
-                               0F7EB8491F9541B000F1ABCB /* IsoDirectoryPage.h in Headers */,
-                               0F7EB8281F9541B000F1ABCB /* IsoDirectoryInlines.h in Headers */,
-                               0F7EB8251F9541B000F1ABCB /* DeferredTriggerInlines.h in Headers */,
                                142B44371E2839E7001DA6E9 /* DebugHeap.h in Headers */,
-                               0F7EB84C1F9541C700F1ABCB /* Bits.h in Headers */,
+                               0F7EB83D1F9541B000F1ABCB /* DeferredDecommit.h in Headers */,
+                               0F7EB85A1F955A1100F1ABCB /* DeferredDecommitInlines.h in Headers */,
+                               0F7EB8391F9541B000F1ABCB /* DeferredTrigger.h in Headers */,
+                               0F7EB8251F9541B000F1ABCB /* DeferredTriggerInlines.h in Headers */,
+                               0F7EB8231F9541B000F1ABCB /* EligibilityResult.h in Headers */,
+                               0F7EB8381F9541B000F1ABCB /* EligibilityResultInlines.h in Headers */,
                                14895D921A3A319C0006235D /* Environment.h in Headers */,
                                14DD78C818F48D7500950702 /* FixedVector.h in Headers */,
+                               0F7EB8441F9541B000F1ABCB /* FreeList.h in Headers */,
+                               0F7EB8291F9541B000F1ABCB /* FreeListInlines.h in Headers */,
+                               0F5BF14D1F22B0C30029D91D /* Gigacage.h in Headers */,
                                1400274918F89C1300115C97 /* Heap.h in Headers */,
-                               0F7EB8481F9541B000F1ABCB /* IsoTLSAllocatorEntryInlines.h in Headers */,
-                               0F7EB84D1F9541C700F1ABCB /* BMalloced.h in Headers */,
-                               0F7EB82A1F9541B000F1ABCB /* IsoDirectoryPageInlines.h in Headers */,
-                               0F5BF1491F22A8D80029D91D /* PerHeapKind.h in Headers */,
-                               0F7EB82D1F9541B000F1ABCB /* IsoTLSEntry.h in Headers */,
-                               14DD78C918F48D7500950702 /* BInline.h in Headers */,
+                               0F5BF1471F22A8B10029D91D /* HeapKind.h in Headers */,
+                               0F7EB83C1F9541B000F1ABCB /* IsoAllocator.h in Headers */,
+                               0F7EB8261F9541B000F1ABCB /* IsoAllocatorInlines.h in Headers */,
+                               0F7EB8411F9541B000F1ABCB /* IsoConfig.h in Headers */,
                                0F7EB8471F9541B000F1ABCB /* IsoDeallocator.h in Headers */,
+                               0F7EB83A1F9541B000F1ABCB /* IsoDeallocatorInlines.h in Headers */,
+                               0F7EB8371F9541B000F1ABCB /* IsoDirectory.h in Headers */,
+                               0F7EB8281F9541B000F1ABCB /* IsoDirectoryInlines.h in Headers */,
+                               0F7EB8491F9541B000F1ABCB /* IsoDirectoryPage.h in Headers */,
+                               0F7EB82A1F9541B000F1ABCB /* IsoDirectoryPageInlines.h in Headers */,
+                               0F7EB82C1F9541B000F1ABCB /* IsoHeap.h in Headers */,
+                               0F7EB8451F9541B000F1ABCB /* IsoHeapImpl.h in Headers */,
                                0F7EB8241F9541B000F1ABCB /* IsoHeapImplInlines.h in Headers */,
-                               795AB3C7206E0D340074FE76 /* PhysicalPageMap.h in Headers */,
+                               0F7EB8301F9541B000F1ABCB /* IsoHeapInlines.h in Headers */,
+                               0F7EB82E1F9541B000F1ABCB /* IsoPage.h in Headers */,
+                               0F7EB8311F9541B000F1ABCB /* IsoPageInlines.h in Headers */,
+                               0F7EB82B1F9541B000F1ABCB /* IsoPageTrigger.h in Headers */,
+                               0F7EB8421F9541B000F1ABCB /* IsoTLS.h in Headers */,
+                               0F7EB8431F9541B000F1ABCB /* IsoTLSAllocatorEntry.h in Headers */,
+                               0F7EB8481F9541B000F1ABCB /* IsoTLSAllocatorEntryInlines.h in Headers */,
+                               0F7EB8331F9541B000F1ABCB /* IsoTLSDeallocatorEntry.h in Headers */,
+                               0F7EB8271F9541B000F1ABCB /* IsoTLSDeallocatorEntryInlines.h in Headers */,
+                               0F7EB82D1F9541B000F1ABCB /* IsoTLSEntry.h in Headers */,
+                               0F7EB8351F9541B000F1ABCB /* IsoTLSEntryInlines.h in Headers */,
+                               0F7EB8461F9541B000F1ABCB /* IsoTLSInlines.h in Headers */,
+                               0F7EB8401F9541B000F1ABCB /* IsoTLSLayout.h in Headers */,
                                144C07F51C7B70260051BB6A /* LargeMap.h in Headers */,
                                14C8992D1CC578330027A057 /* LargeRange.h in Headers */,
                                140FA00519CE4B6800FFD3C8 /* LineMetadata.h in Headers */,
-                               0F7EB8331F9541B000F1ABCB /* IsoTLSDeallocatorEntry.h in Headers */,
                                141D9B001C8E51C0000ABBA0 /* List.h in Headers */,
                                4426E2811C838EE0008EB042 /* Logging.h in Headers */,
-                               0F7EB82E1F9541B000F1ABCB /* IsoPage.h in Headers */,
-                               0F7EB83D1F9541B000F1ABCB /* DeferredDecommit.h in Headers */,
-                               0F7EB8351F9541B000F1ABCB /* IsoTLSEntryInlines.h in Headers */,
-                               0F7EB8301F9541B000F1ABCB /* IsoHeapInlines.h in Headers */,
                                14C8992B1CC485E70027A057 /* Map.h in Headers */,
-                               14DD78CA18F48D7500950702 /* Mutex.h in Headers */,
+                               143CB81D19022BC900B16A45 /* Mutex.h in Headers */,
                                144BE11F1CA346520099C8C0 /* Object.h in Headers */,
                                14DD789318F48D0F00950702 /* ObjectType.h in Headers */,
+                               0F5BF1491F22A8D80029D91D /* PerHeapKind.h in Headers */,
                                14DD78CB18F48D7500950702 /* PerProcess.h in Headers */,
-                               0F7EB8261F9541B000F1ABCB /* IsoAllocatorInlines.h in Headers */,
                                14DD78CC18F48D7500950702 /* PerThread.h in Headers */,
+                               795AB3C7206E0D340074FE76 /* PhysicalPageMap.h in Headers */,
+                               AD14AD29202529C400890E3B /* ProcessCheck.h in Headers */,
                                14DD78CD18F48D7500950702 /* Range.h in Headers */,
-                               0F7EB8441F9541B000F1ABCB /* FreeList.h in Headers */,
+                               0F5BF1531F22E1570029D91D /* Scavenger.h in Headers */,
                                148EFAE81D6B953B008E721E /* ScopeExit.h in Headers */,
-                               0F7EB8341F9541B000F1ABCB /* AllIsoHeaps.h in Headers */,
-                               0F7EB8401F9541B000F1ABCB /* IsoTLSLayout.h in Headers */,
-                               0F7EB8391F9541B000F1ABCB /* DeferredTrigger.h in Headers */,
                                14DD789018F48CEB00950702 /* Sizes.h in Headers */,
-                               0F7EB8411F9541B000F1ABCB /* IsoConfig.h in Headers */,
-                               AD0934331FCF406D00E85EB5 /* BCompiler.h in Headers */,
-                               0F7EB8311F9541B000F1ABCB /* IsoPageInlines.h in Headers */,
                                14DD78BC18F48D6B00950702 /* SmallLine.h in Headers */,
-                               0F7EB82B1F9541B000F1ABCB /* IsoPageTrigger.h in Headers */,
                                14DD78BD18F48D6B00950702 /* SmallPage.h in Headers */,
-                               143CB81D19022BC900B16A45 /* StaticMutex.h in Headers */,
-                               0F7EB8271F9541B000F1ABCB /* IsoTLSDeallocatorEntryInlines.h in Headers */,
                                14DD78CE18F48D7500950702 /* Syscall.h in Headers */,
-                               0F5BF14D1F22B0C30029D91D /* Gigacage.h in Headers */,
                                14DD78CF18F48D7500950702 /* Vector.h in Headers */,
                                14DD78D018F48D7500950702 /* VMAllocate.h in Headers */,
-                               0F7EB83A1F9541B000F1ABCB /* IsoDeallocatorInlines.h in Headers */,
-                               AD14AD29202529C400890E3B /* ProcessCheck.h in Headers */,
                                1400274A18F89C2300115C97 /* VMHeap.h in Headers */,
                                1440AFCB1A95261100837FAA /* Zone.h in Headers */,
                        );
                        isa = PBXSourcesBuildPhase;
                        buildActionMask = 2147483647;
                        files = (
-                               0F5BF1521F22E1570029D91D /* Scavenger.cpp in Sources */,
-                               0F7EB8361F9541B000F1ABCB /* IsoTLS.cpp in Sources */,
-                               0FD557331F7EDB7B00B1F0A3 /* HeapKind.cpp in Sources */,
-                               0F7EB83B1F9541B000F1ABCB /* IsoHeapImpl.cpp in Sources */,
-                               0F5549EF1FB54704007FF75A /* IsoPage.cpp in Sources */,
+                               0F7EB82F1F9541B000F1ABCB /* AllIsoHeaps.cpp in Sources */,
                                14F271C318EA3978008C152F /* Allocator.cpp in Sources */,
                                6599C5CC1EC3F15900A2F7BB /* AvailableMemory.cpp in Sources */,
+                               0F5167741FAD685C008236A8 /* bmalloc.cpp in Sources */,
                                14F271C418EA397B008C152F /* Cache.cpp in Sources */,
-                               0F26A7A5205483130090A141 /* PerProcess.cpp in Sources */,
+                               0F74B93F1F89713E00B935D3 /* CryptoRandom.cpp in Sources */,
                                14F271C518EA397E008C152F /* Deallocator.cpp in Sources */,
                                142B44361E2839E7001DA6E9 /* DebugHeap.cpp in Sources */,
                                14895D911A3A319C0006235D /* Environment.cpp in Sources */,
-                               0F7EB83F1F9541B000F1ABCB /* IsoTLSLayout.cpp in Sources */,
-                               AD14AD2A202529C700890E3B /* ProcessCheck.mm in Sources */,
+                               0F7EB83E1F9541B000F1ABCB /* FreeList.cpp in Sources */,
+                               0F5BF14F1F22DEAF0029D91D /* Gigacage.cpp in Sources */,
                                14F271C718EA3990008C152F /* Heap.cpp in Sources */,
+                               0FD557331F7EDB7B00B1F0A3 /* HeapKind.cpp in Sources */,
+                               0F7EB83B1F9541B000F1ABCB /* IsoHeapImpl.cpp in Sources */,
+                               0F5549EF1FB54704007FF75A /* IsoPage.cpp in Sources */,
+                               0F7EB8361F9541B000F1ABCB /* IsoTLS.cpp in Sources */,
                                0F7EB8321F9541B000F1ABCB /* IsoTLSEntry.cpp in Sources */,
-                               0F74B93F1F89713E00B935D3 /* CryptoRandom.cpp in Sources */,
-                               0F5BF14F1F22DEAF0029D91D /* Gigacage.cpp in Sources */,
+                               0F7EB83F1F9541B000F1ABCB /* IsoTLSLayout.cpp in Sources */,
                                144C07F41C7B70260051BB6A /* LargeMap.cpp in Sources */,
-                               0F7EB83E1F9541B000F1ABCB /* FreeList.cpp in Sources */,
                                4426E2801C838EE0008EB042 /* Logging.cpp in Sources */,
-                               0F7EB82F1F9541B000F1ABCB /* AllIsoHeaps.cpp in Sources */,
+                               143CB81C19022BC900B16A45 /* Mutex.cpp in Sources */,
                                14F271C818EA3990008C152F /* ObjectType.cpp in Sources */,
-                               143CB81C19022BC900B16A45 /* StaticMutex.cpp in Sources */,
+                               0F26A7A5205483130090A141 /* PerProcess.cpp in Sources */,
+                               AD14AD2A202529C700890E3B /* ProcessCheck.mm in Sources */,
+                               0F5BF1521F22E1570029D91D /* Scavenger.cpp in Sources */,
                                14F271C918EA3990008C152F /* VMHeap.cpp in Sources */,
-                               0F5167741FAD685C008236A8 /* bmalloc.cpp in Sources */,
                                1440AFCD1A9527AF00837FAA /* Zone.cpp in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
index 609fc55..a0709c8 100644 (file)
@@ -27,7 +27,7 @@
 
 namespace bmalloc {
 
-AllIsoHeaps::AllIsoHeaps(const std::lock_guard<StaticMutex>&)
+AllIsoHeaps::AllIsoHeaps(const std::lock_guard<Mutex>&)
 {
 }
 
index c7e067a..78eae34 100644 (file)
@@ -32,7 +32,7 @@ namespace bmalloc {
 
 class AllIsoHeaps {
 public:
-    AllIsoHeaps(const std::lock_guard<StaticMutex>&);
+    AllIsoHeaps(const std::lock_guard<Mutex>&);
     
     void add(IsoHeapImplBase*);
     IsoHeapImplBase* head();
index b442def..cda8d8a 100644 (file)
@@ -60,7 +60,7 @@ void* Allocator::tryAllocate(size_t size)
     if (size <= smallMax)
         return allocate(size);
 
-    std::lock_guard<StaticMutex> lock(Heap::mutex());
+    std::lock_guard<Mutex> lock(Heap::mutex());
     return m_heap.tryAllocateLarge(lock, alignment, size);
 }
 
@@ -89,7 +89,7 @@ void* Allocator::allocateImpl(size_t alignment, size_t size, bool crashOnFailure
     if (size <= smallMax && alignment <= smallMax)
         return allocate(roundUpToMultipleOf(alignment, size));
 
-    std::lock_guard<StaticMutex> lock(Heap::mutex());
+    std::lock_guard<Mutex> lock(Heap::mutex());
     if (crashOnFailure)
         return m_heap.allocateLarge(lock, alignment, size);
     return m_heap.tryAllocateLarge(lock, alignment, size);
@@ -112,7 +112,7 @@ void* Allocator::reallocate(void* object, size_t newSize)
         break;
     }
     case ObjectType::Large: {
-        std::lock_guard<StaticMutex> lock(Heap::mutex());
+        std::lock_guard<Mutex> lock(Heap::mutex());
         oldSize = m_heap.largeSize(lock, object);
 
         if (newSize < oldSize && newSize > smallMax) {
@@ -153,7 +153,7 @@ BNO_INLINE void Allocator::refillAllocatorSlowCase(BumpAllocator& allocator, siz
 {
     BumpRangeCache& bumpRangeCache = m_bumpRangeCaches[sizeClass];
 
-    std::lock_guard<StaticMutex> lock(Heap::mutex());
+    std::lock_guard<Mutex> lock(Heap::mutex());
     m_deallocator.processObjectLog(lock);
     m_heap.allocateSmallBumpRanges(lock, sizeClass, allocator, bumpRangeCache, m_deallocator.lineCache(lock));
 }
@@ -168,7 +168,7 @@ BINLINE void Allocator::refillAllocator(BumpAllocator& allocator, size_t sizeCla
 
 BNO_INLINE void* Allocator::allocateLarge(size_t size)
 {
-    std::lock_guard<StaticMutex> lock(Heap::mutex());
+    std::lock_guard<Mutex> lock(Heap::mutex());
     return m_heap.allocateLarge(lock, alignment, size);
 }
 
index 19a565d..4fef713 100644 (file)
@@ -65,7 +65,7 @@ public:
 
 class ARC4RandomNumberGenerator {
 public:
-    ARC4RandomNumberGenerator(const std::lock_guard<StaticMutex>&);
+    ARC4RandomNumberGenerator(const std::lock_guard<Mutex>&);
 
     uint32_t randomNumber();
     void randomValues(void* buffer, size_t length);
@@ -89,7 +89,7 @@ ARC4Stream::ARC4Stream()
     j = 0;
 }
 
-ARC4RandomNumberGenerator::ARC4RandomNumberGenerator(const std::lock_guard<StaticMutex>&)
+ARC4RandomNumberGenerator::ARC4RandomNumberGenerator(const std::lock_guard<Mutex>&)
     : m_count(0)
 {
 }
index 44c7263..6095682 100644 (file)
@@ -60,13 +60,13 @@ void Deallocator::scavenge()
     if (m_debugHeap)
         return;
 
-    std::lock_guard<StaticMutex> lock(Heap::mutex());
+    std::lock_guard<Mutex> lock(Heap::mutex());
 
     processObjectLog(lock);
     m_heap.deallocateLineCache(lock, lineCache(lock));
 }
 
-void Deallocator::processObjectLog(std::lock_guard<StaticMutex>& lock)
+void Deallocator::processObjectLog(std::lock_guard<Mutex>& lock)
 {
     for (Object object : m_objectLog)
         m_heap.derefSmallLine(lock, object, lineCache(lock));
@@ -81,7 +81,7 @@ void Deallocator::deallocateSlowCase(void* object)
     if (!object)
         return;
 
-    std::lock_guard<StaticMutex> lock(Heap::mutex());
+    std::lock_guard<Mutex> lock(Heap::mutex());
     if (m_heap.isLarge(lock, object)) {
         m_heap.deallocateLarge(lock, object);
         return;
index 383a999..6c33524 100644 (file)
@@ -35,7 +35,7 @@ namespace bmalloc {
 
 class DebugHeap;
 class Heap;
-class StaticMutex;
+class Mutex;
 
 // Per-cache object deallocator.
 
@@ -47,9 +47,9 @@ public:
     void deallocate(void*);
     void scavenge();
     
-    void processObjectLog(std::lock_guard<StaticMutex>&);
+    void processObjectLog(std::lock_guard<Mutex>&);
     
-    LineCache& lineCache(std::lock_guard<StaticMutex>&) { return m_lineCache; }
+    LineCache& lineCache(std::lock_guard<Mutex>&) { return m_lineCache; }
 
 private:
     bool deallocateFastCase(void*);
index b3c9ed9..f0a37e8 100644 (file)
@@ -36,7 +36,7 @@ namespace bmalloc {
     
 #if BOS(DARWIN)
 
-DebugHeap::DebugHeap(std::lock_guard<StaticMutex>&)
+DebugHeap::DebugHeap(std::lock_guard<Mutex>&)
     : m_zone(malloc_create_zone(0, 0))
     , m_pageSize(vmPageSize())
 {
@@ -74,7 +74,7 @@ void DebugHeap::free(void* object)
 
 #else
 
-DebugHeap::DebugHeap(std::lock_guard<StaticMutex>&)
+DebugHeap::DebugHeap(std::lock_guard<Mutex>&)
 {
 }
 
index 7f0609d..314b9c3 100644 (file)
@@ -25,7 +25,7 @@
 
 #pragma once
 
-#include "StaticMutex.h"
+#include "Mutex.h"
 #include <mutex>
 #include <unordered_map>
 
@@ -37,7 +37,7 @@ namespace bmalloc {
     
 class DebugHeap {
 public:
-    DebugHeap(std::lock_guard<StaticMutex>&);
+    DebugHeap(std::lock_guard<Mutex>&);
     
     void* malloc(size_t);
     void* memalign(size_t alignment, size_t, bool crashOnFailure);
index c78089f..0bd833f 100644 (file)
@@ -107,7 +107,7 @@ static bool isSanitizerEnabled()
 #endif
 }
 
-Environment::Environment(std::lock_guard<StaticMutex>&)
+Environment::Environment(std::lock_guard<Mutex>&)
     : m_isDebugHeapEnabled(computeIsDebugHeapEnabled())
 {
 }
index 16b26cd..7b5f778 100644 (file)
 #ifndef Environment_h
 #define Environment_h
 
-#include "StaticMutex.h"
+#include "Mutex.h"
 
 namespace bmalloc {
 
 class Environment {
 public:
-    Environment(std::lock_guard<StaticMutex>&);
+    Environment(std::lock_guard<Mutex>&);
     
     bool isDebugHeapEnabled() { return m_isDebugHeapEnabled; }
 
index 5e56e2a..aba100a 100644 (file)
@@ -94,7 +94,7 @@ struct Callback {
 };
 
 struct PrimitiveDisableCallbacks {
-    PrimitiveDisableCallbacks(std::lock_guard<StaticMutex>&) { }
+    PrimitiveDisableCallbacks(std::lock_guard<Mutex>&) { }
     
     Vector<Callback> callbacks;
 };
@@ -186,7 +186,7 @@ void disablePrimitiveGigacage()
     }
     
     PrimitiveDisableCallbacks& callbacks = *PerProcess<PrimitiveDisableCallbacks>::get();
-    std::unique_lock<StaticMutex> lock(PerProcess<PrimitiveDisableCallbacks>::mutex());
+    std::unique_lock<Mutex> lock(PerProcess<PrimitiveDisableCallbacks>::mutex());
     for (Callback& callback : callbacks.callbacks)
         callback.function(callback.argument);
     callbacks.callbacks.shrink(0);
@@ -204,14 +204,14 @@ void addPrimitiveDisableCallback(void (*function)(void*), void* argument)
     }
     
     PrimitiveDisableCallbacks& callbacks = *PerProcess<PrimitiveDisableCallbacks>::get();
-    std::unique_lock<StaticMutex> lock(PerProcess<PrimitiveDisableCallbacks>::mutex());
+    std::unique_lock<Mutex> lock(PerProcess<PrimitiveDisableCallbacks>::mutex());
     callbacks.callbacks.push(Callback(function, argument));
 }
 
 void removePrimitiveDisableCallback(void (*function)(void*), void* argument)
 {
     PrimitiveDisableCallbacks& callbacks = *PerProcess<PrimitiveDisableCallbacks>::get();
-    std::unique_lock<StaticMutex> lock(PerProcess<PrimitiveDisableCallbacks>::mutex());
+    std::unique_lock<Mutex> lock(PerProcess<PrimitiveDisableCallbacks>::mutex());
     for (size_t i = 0; i < callbacks.callbacks.size(); ++i) {
         if (callbacks.callbacks[i].function == function
             && callbacks.callbacks[i].argument == argument) {
index 1801445..5d5d19f 100644 (file)
@@ -41,7 +41,7 @@
 
 namespace bmalloc {
 
-Heap::Heap(HeapKind kind, std::lock_guard<StaticMutex>&)
+Heap::Heap(HeapKind kind, std::lock_guard<Mutex>&)
     : m_kind(kind)
     , m_vmPageSizePhysical(vmPageSizePhysical())
     , m_debugHeap(nullptr)
@@ -138,7 +138,7 @@ void Heap::initializePageMetadata()
         m_pageClasses[i] = (computePageSize(i) - 1) / smallPageSize;
 }
 
-size_t Heap::freeableMemory(std::lock_guard<StaticMutex>&)
+size_t Heap::freeableMemory(std::lock_guard<Mutex>&)
 {
     size_t result = 0;
     for (auto& list : m_freePages) {
@@ -162,7 +162,7 @@ size_t Heap::footprint()
     return m_footprint;
 }
 
-void Heap::scavenge(std::lock_guard<StaticMutex>&)
+void Heap::scavenge(std::lock_guard<Mutex>&)
 {
     for (auto& list : m_freePages) {
         for (auto* chunk : list) {
@@ -197,7 +197,7 @@ void Heap::scavenge(std::lock_guard<StaticMutex>&)
     }
 }
 
-void Heap::deallocateLineCache(std::lock_guard<StaticMutex>&, LineCache& lineCache)
+void Heap::deallocateLineCache(std::lock_guard<Mutex>&, LineCache& lineCache)
 {
     for (auto& list : lineCache) {
         while (!list.isEmpty()) {
@@ -207,7 +207,7 @@ void Heap::deallocateLineCache(std::lock_guard<StaticMutex>&, LineCache& lineCac
     }
 }
 
-void Heap::allocateSmallChunk(std::lock_guard<StaticMutex>& lock, size_t pageClass)
+void Heap::allocateSmallChunk(std::lock_guard<Mutex>& lock, size_t pageClass)
 {
     RELEASE_BASSERT(isActiveHeapKind(m_kind));
     
@@ -256,7 +256,7 @@ void Heap::deallocateSmallChunk(Chunk* chunk, size_t pageClass)
     m_largeFree.add(LargeRange(chunk, size, startPhysicalSize, totalPhysicalSize));
 }
 
-SmallPage* Heap::allocateSmallPage(std::lock_guard<StaticMutex>& lock, size_t sizeClass, LineCache& lineCache)
+SmallPage* Heap::allocateSmallPage(std::lock_guard<Mutex>& lock, size_t sizeClass, LineCache& lineCache)
 {
     RELEASE_BASSERT(isActiveHeapKind(m_kind));
 
@@ -300,7 +300,7 @@ SmallPage* Heap::allocateSmallPage(std::lock_guard<StaticMutex>& lock, size_t si
     return page;
 }
 
-void Heap::deallocateSmallLine(std::lock_guard<StaticMutex>& lock, Object object, LineCache& lineCache)
+void Heap::deallocateSmallLine(std::lock_guard<Mutex>& lock, Object object, LineCache& lineCache)
 {
     BASSERT(!object.line()->refCount(lock));
     SmallPage* page = object.page();
@@ -339,7 +339,7 @@ void Heap::deallocateSmallLine(std::lock_guard<StaticMutex>& lock, Object object
 }
 
 void Heap::allocateSmallBumpRangesByMetadata(
-    std::lock_guard<StaticMutex>& lock, size_t sizeClass,
+    std::lock_guard<Mutex>& lock, size_t sizeClass,
     BumpAllocator& allocator, BumpRangeCache& rangeCache,
     LineCache& lineCache)
 {
@@ -403,7 +403,7 @@ void Heap::allocateSmallBumpRangesByMetadata(
 }
 
 void Heap::allocateSmallBumpRangesByObject(
-    std::lock_guard<StaticMutex>& lock, size_t sizeClass,
+    std::lock_guard<Mutex>& lock, size_t sizeClass,
     BumpAllocator& allocator, BumpRangeCache& rangeCache,
     LineCache& lineCache)
 {
@@ -459,7 +459,7 @@ void Heap::allocateSmallBumpRangesByObject(
     }
 }
 
-LargeRange Heap::splitAndAllocate(std::lock_guard<StaticMutex>&, LargeRange& range, size_t alignment, size_t size)
+LargeRange Heap::splitAndAllocate(std::lock_guard<Mutex>&, LargeRange& range, size_t alignment, size_t size)
 {
     RELEASE_BASSERT(isActiveHeapKind(m_kind));
 
@@ -503,7 +503,7 @@ LargeRange Heap::splitAndAllocate(std::lock_guard<StaticMutex>&, LargeRange& ran
     return range;
 }
 
-void* Heap::tryAllocateLarge(std::lock_guard<StaticMutex>& lock, size_t alignment, size_t size)
+void* Heap::tryAllocateLarge(std::lock_guard<Mutex>& lock, size_t alignment, size_t size)
 {
     RELEASE_BASSERT(isActiveHeapKind(m_kind));
 
@@ -541,24 +541,24 @@ void* Heap::tryAllocateLarge(std::lock_guard<StaticMutex>& lock, size_t alignmen
     return splitAndAllocate(lock, range, alignment, size).begin();
 }
 
-void* Heap::allocateLarge(std::lock_guard<StaticMutex>& lock, size_t alignment, size_t size)
+void* Heap::allocateLarge(std::lock_guard<Mutex>& lock, size_t alignment, size_t size)
 {
     void* result = tryAllocateLarge(lock, alignment, size);
     RELEASE_BASSERT(result);
     return result;
 }
 
-bool Heap::isLarge(std::lock_guard<StaticMutex>&, void* object)
+bool Heap::isLarge(std::lock_guard<Mutex>&, void* object)
 {
     return m_objectTypes.get(Object(object).chunk()) == ObjectType::Large;
 }
 
-size_t Heap::largeSize(std::lock_guard<StaticMutex>&, void* object)
+size_t Heap::largeSize(std::lock_guard<Mutex>&, void* object)
 {
     return m_largeAllocated.get(object);
 }
 
-void Heap::shrinkLarge(std::lock_guard<StaticMutex>& lock, const Range& object, size_t newSize)
+void Heap::shrinkLarge(std::lock_guard<Mutex>& lock, const Range& object, size_t newSize)
 {
     BASSERT(object.size() > newSize);
 
@@ -569,7 +569,7 @@ void Heap::shrinkLarge(std::lock_guard<StaticMutex>& lock, const Range& object,
     m_scavenger->schedule(size);
 }
 
-void Heap::deallocateLarge(std::lock_guard<StaticMutex>&, void* object)
+void Heap::deallocateLarge(std::lock_guard<Mutex>&, void* object)
 {
     if (m_debugHeap)
         return m_debugHeap->freeLarge(object);
@@ -581,11 +581,11 @@ void Heap::deallocateLarge(std::lock_guard<StaticMutex>&, void* object)
 
 void Heap::externalCommit(void* ptr, size_t size)
 {
-    std::lock_guard<StaticMutex> lock(Heap::mutex());
+    std::lock_guard<Mutex> lock(Heap::mutex());
     externalCommit(lock, ptr, size);
 }
 
-void Heap::externalCommit(std::lock_guard<StaticMutex>&, void* ptr, size_t size)
+void Heap::externalCommit(std::lock_guard<Mutex>&, void* ptr, size_t size)
 {
     BUNUSED_PARAM(ptr);
 
@@ -597,11 +597,11 @@ void Heap::externalCommit(std::lock_guard<StaticMutex>&, void* ptr, size_t size)
 
 void Heap::externalDecommit(void* ptr, size_t size)
 {
-    std::lock_guard<StaticMutex> lock(Heap::mutex());
+    std::lock_guard<Mutex> lock(Heap::mutex());
     externalDecommit(lock, ptr, size);
 }
 
-void Heap::externalDecommit(std::lock_guard<StaticMutex>&, void* ptr, size_t size)
+void Heap::externalDecommit(std::lock_guard<Mutex>&, void* ptr, size_t size)
 {
     BUNUSED_PARAM(ptr);
 
index 583e76b..e16d2a0 100644 (file)
@@ -54,36 +54,36 @@ class Scavenger;
 
 class Heap {
 public:
-    Heap(HeapKind, std::lock_guard<StaticMutex>&);
+    Heap(HeapKind, std::lock_guard<Mutex>&);
     
-    static StaticMutex& mutex() { return PerProcess<PerHeapKind<Heap>>::mutex(); }
+    static Mutex& mutex() { return PerProcess<PerHeapKind<Heap>>::mutex(); }
     
     HeapKind kind() const { return m_kind; }
     
     DebugHeap* debugHeap() { return m_debugHeap; }
 
-    void allocateSmallBumpRanges(std::lock_guard<StaticMutex>&, size_t sizeClass,
+    void allocateSmallBumpRanges(std::lock_guard<Mutex>&, size_t sizeClass,
         BumpAllocator&, BumpRangeCache&, LineCache&);
-    void derefSmallLine(std::lock_guard<StaticMutex>&, Object, LineCache&);
-    void deallocateLineCache(std::lock_guard<StaticMutex>&, LineCache&);
+    void derefSmallLine(std::lock_guard<Mutex>&, Object, LineCache&);
+    void deallocateLineCache(std::lock_guard<Mutex>&, LineCache&);
 
-    void* allocateLarge(std::lock_guard<StaticMutex>&, size_t alignment, size_t);
-    void* tryAllocateLarge(std::lock_guard<StaticMutex>&, size_t alignment, size_t);
-    void deallocateLarge(std::lock_guard<StaticMutex>&, void*);
+    void* allocateLarge(std::lock_guard<Mutex>&, size_t alignment, size_t);
+    void* tryAllocateLarge(std::lock_guard<Mutex>&, size_t alignment, size_t);
+    void deallocateLarge(std::lock_guard<Mutex>&, void*);
 
-    bool isLarge(std::lock_guard<StaticMutex>&, void*);
-    size_t largeSize(std::lock_guard<StaticMutex>&, void*);
-    void shrinkLarge(std::lock_guard<StaticMutex>&, const Range&, size_t);
+    bool isLarge(std::lock_guard<Mutex>&, void*);
+    size_t largeSize(std::lock_guard<Mutex>&, void*);
+    void shrinkLarge(std::lock_guard<Mutex>&, const Range&, size_t);
 
-    void scavenge(std::lock_guard<StaticMutex>&);
+    void scavenge(std::lock_guard<Mutex>&);
 
-    size_t freeableMemory(std::lock_guard<StaticMutex>&);
+    size_t freeableMemory(std::lock_guard<Mutex>&);
     size_t footprint();
 
     void externalDecommit(void* ptr, size_t);
-    void externalDecommit(std::lock_guard<StaticMutex>&, void* ptr, size_t);
+    void externalDecommit(std::lock_guard<Mutex>&, void* ptr, size_t);
     void externalCommit(void* ptr, size_t);
-    void externalCommit(std::lock_guard<StaticMutex>&, void* ptr, size_t);
+    void externalCommit(std::lock_guard<Mutex>&, void* ptr, size_t);
 
 private:
     struct LargeObjectHash {
@@ -103,22 +103,22 @@ private:
     void initializeLineMetadata();
     void initializePageMetadata();
 
-    void allocateSmallBumpRangesByMetadata(std::lock_guard<StaticMutex>&,
+    void allocateSmallBumpRangesByMetadata(std::lock_guard<Mutex>&,
         size_t sizeClass, BumpAllocator&, BumpRangeCache&, LineCache&);
-    void allocateSmallBumpRangesByObject(std::lock_guard<StaticMutex>&,
+    void allocateSmallBumpRangesByObject(std::lock_guard<Mutex>&,
         size_t sizeClass, BumpAllocator&, BumpRangeCache&, LineCache&);
 
-    SmallPage* allocateSmallPage(std::lock_guard<StaticMutex>&, size_t sizeClass, LineCache&);
-    void deallocateSmallLine(std::lock_guard<StaticMutex>&, Object, LineCache&);
+    SmallPage* allocateSmallPage(std::lock_guard<Mutex>&, size_t sizeClass, LineCache&);
+    void deallocateSmallLine(std::lock_guard<Mutex>&, Object, LineCache&);
 
-    void allocateSmallChunk(std::lock_guard<StaticMutex>&, size_t pageClass);
+    void allocateSmallChunk(std::lock_guard<Mutex>&, size_t pageClass);
     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::lock_guard<StaticMutex>&, LargeRange&, size_t alignment, size_t);
+    LargeRange splitAndAllocate(std::lock_guard<Mutex>&, LargeRange&, size_t alignment, size_t);
 
     HeapKind m_kind;
     
@@ -146,7 +146,7 @@ private:
 };
 
 inline void Heap::allocateSmallBumpRanges(
-    std::lock_guard<StaticMutex>& lock, size_t sizeClass,
+    std::lock_guard<Mutex>& lock, size_t sizeClass,
     BumpAllocator& allocator, BumpRangeCache& rangeCache,
     LineCache& lineCache)
 {
@@ -155,7 +155,7 @@ inline void Heap::allocateSmallBumpRanges(
     return allocateSmallBumpRangesByObject(lock, sizeClass, allocator, rangeCache, lineCache);
 }
 
-inline void Heap::derefSmallLine(std::lock_guard<StaticMutex>& lock, Object object, LineCache& lineCache)
+inline void Heap::derefSmallLine(std::lock_guard<Mutex>& lock, Object object, LineCache& lineCache)
 {
     if (!object.line()->deref(lock))
         return;
index 145f42b..a92c45d 100644 (file)
 
 #include "FixedVector.h"
 #include "IsoPage.h"
+#include "Mutex.h"
 
 namespace bmalloc {
 
-class Mutex;
-
 template<typename Config>
 class IsoDeallocator {
 public:
index 99012ee..0cd3764 100644 (file)
@@ -26,7 +26,7 @@
 #pragma once
 
 #include "IsoConfig.h"
-#include "StaticMutex.h"
+#include "Mutex.h"
 
 namespace bmalloc {
 
@@ -60,7 +60,7 @@ struct IsoHeap {
     
     IsoHeapImpl<Config>& impl();
     
-    StaticMutex m_initializationLock;
+    Mutex m_initializationLock;
     unsigned m_allocatorOffsetPlusOne;
     unsigned m_deallocatorOffsetPlusOne;
     IsoHeapImpl<Config>* m_impl;
index c013317..2d5585e 100644 (file)
@@ -27,7 +27,7 @@
 
 #include "IsoDeallocator.h"
 #include "IsoTLSEntry.h"
-#include "StaticMutex.h"
+#include "Mutex.h"
 #include <mutex>
 
 namespace bmalloc {
@@ -35,7 +35,7 @@ namespace bmalloc {
 template<typename Config>
 class IsoTLSDeallocatorEntry : public DefaultIsoTLSEntry<IsoDeallocator<Config>> {
 public:
-    IsoTLSDeallocatorEntry(const std::lock_guard<StaticMutex>&);
+    IsoTLSDeallocatorEntry(const std::lock_guard<Mutex>&);
     ~IsoTLSDeallocatorEntry();
     
     // This is used as the heap lock, since heaps in the same size class share the same deallocator
index 2603432..cbd5f9d 100644 (file)
@@ -28,7 +28,7 @@
 namespace bmalloc {
 
 template<typename Config>
-IsoTLSDeallocatorEntry<Config>::IsoTLSDeallocatorEntry(const std::lock_guard<StaticMutex>&)
+IsoTLSDeallocatorEntry<Config>::IsoTLSDeallocatorEntry(const std::lock_guard<Mutex>&)
 {
 }
 
index 7558df8..20f6afe 100644 (file)
@@ -172,7 +172,7 @@ template<typename Type>
 void IsoTLS::ensureHeap(api::IsoHeap<Type>& handle)
 {
     if (!handle.isInitialized()) {
-        std::lock_guard<StaticMutex> locker(handle.m_initializationLock);
+        std::lock_guard<Mutex> locker(handle.m_initializationLock);
         if (!handle.isInitialized()) {
             auto* heap = new IsoHeapImpl<typename api::IsoHeap<Type>::Config>();
             std::atomic_thread_fence(std::memory_order_seq_cst);
index b0d15cf..fdd9a17 100644 (file)
 
 namespace bmalloc {
 
-IsoTLSLayout::IsoTLSLayout(const std::lock_guard<StaticMutex>&)
+IsoTLSLayout::IsoTLSLayout(const std::lock_guard<Mutex>&)
 {
 }
 
 void IsoTLSLayout::add(IsoTLSEntry* entry)
 {
-    static StaticMutex addingMutex;
+    static Mutex addingMutex;
     RELEASE_BASSERT(!entry->m_next);
-    std::lock_guard<StaticMutex> locking(addingMutex);
+    std::lock_guard<Mutex> locking(addingMutex);
     if (m_head) {
         RELEASE_BASSERT(m_tail);
         entry->m_offset = roundUpToMultipleOf(entry->alignment(), m_tail->extent());
index 1e5c93a..cebaa29 100644 (file)
@@ -25,7 +25,7 @@
 
 #pragma once
 
-#include "StaticMutex.h"
+#include "Mutex.h"
 #include <mutex>
 
 namespace bmalloc {
@@ -34,7 +34,7 @@ class IsoTLSEntry;
 
 class IsoTLSLayout {
 public:
-    IsoTLSLayout(const std::lock_guard<StaticMutex>&);
+    IsoTLSLayout(const std::lock_guard<Mutex>&);
     
     void add(IsoTLSEntry*);
     
similarity index 89%
rename from Source/bmalloc/bmalloc/StaticMutex.cpp
rename to Source/bmalloc/bmalloc/Mutex.cpp
index 1e2e1c3..6b16df0 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2014 Apple Inc. All rights reserved.
+ * Copyright (C) 2018 Yusuke Suzuki <utatane.tea@gmail.com>.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
  */
 
+#include "Mutex.h"
+
 #include "ScopeExit.h"
-#include "StaticMutex.h"
 #include <thread>
 
 namespace bmalloc {
 
-void StaticMutex::lockSlowCase()
+void Mutex::lockSlowCase()
 {
     // The longest critical section in bmalloc is much shorter than the
     // time it takes to make a system call to yield to the OS scheduler.
     // So, we try again a lot before we yield.
     static const size_t aLot = 256;
     
-    if (!m_isSpinning.test_and_set()) {
-        auto clear = makeScopeExit([&] { m_isSpinning.clear(); });
+    if (!m_isSpinning.exchange(true)) {
+        auto clear = makeScopeExit([&] { m_isSpinning.store(false); });
 
         for (size_t i = 0; i < aLot; ++i) {
             if (try_lock())
index f0e5998..a8c5ee6 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2014 Apple Inc. All rights reserved.
+ * Copyright (C) 2018 Yusuke Suzuki <utatane.tea@gmail.com>.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
  */
 
-#ifndef Mutex_h
-#define Mutex_h
+#pragma once
 
-#include "StaticMutex.h"
+#include "BAssert.h"
+#include <atomic>
+#include <mutex>
+#include <thread>
 
-// A fast replacement for std::mutex, for use in standard storage.
+// A fast replacement for std::mutex.
 
 namespace bmalloc {
 
-class Mutex : public StaticMutex {
+class Mutex {
 public:
-    Mutex();
+    Mutex() = default;
+
+    void lock();
+    bool try_lock();
+    void unlock();
+
+private:
+    BEXPORT void lockSlowCase();
+
+    std::atomic<bool> m_flag { false };
+    std::atomic<bool> m_isSpinning { false };
 };
 
-inline Mutex::Mutex()
+static inline void sleep(
+    std::unique_lock<Mutex>& lock, std::chrono::milliseconds duration)
 {
-    // StaticMutex requires explicit initialization when used in non-static storage.
-    init();
+    if (duration == std::chrono::milliseconds(0))
+        return;
+    
+    lock.unlock();
+    std::this_thread::sleep_for(duration);
+    lock.lock();
 }
 
-} // namespace bmalloc
+static inline void waitUntilFalse(
+    std::unique_lock<Mutex>& lock, std::chrono::milliseconds sleepDuration,
+    bool& condition)
+{
+    while (condition) {
+        condition = false;
+        sleep(lock, sleepDuration);
+    }
+}
+
+inline bool Mutex::try_lock()
+{
+    return !m_flag.exchange(true, std::memory_order_acquire);
+}
+
+inline void Mutex::lock()
+{
+    if (!try_lock())
+        lockSlowCase();
+}
 
-#endif // Mutex_h
+inline void Mutex::unlock()
+{
+    m_flag.store(false, std::memory_order_release);
+}
+
+} // namespace bmalloc
index 8aeab00..360c2af 100644 (file)
@@ -38,7 +38,7 @@ ObjectType objectType(HeapKind kind, void* object)
         if (!object)
             return ObjectType::Small;
 
-        std::lock_guard<StaticMutex> lock(Heap::mutex());
+        std::lock_guard<Mutex> lock(Heap::mutex());
         if (PerProcess<PerHeapKind<Heap>>::getFastCase()->at(kind).isLarge(lock, object))
             return ObjectType::Large;
     }
index ed6f04f..67add7d 100644 (file)
@@ -32,7 +32,7 @@ namespace bmalloc {
 static constexpr unsigned tableSize = 100;
 static constexpr bool verbose = false;
 
-static StaticMutex s_mutex;
+static Mutex s_mutex;
 
 static char* s_bumpBase;
 static size_t s_bumpOffset;
@@ -59,7 +59,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<StaticMutex> lock(s_mutex);
+    std::lock_guard<Mutex> lock(s_mutex);
 
     PerProcessData*& bucket = s_table[hash % tableSize];
     
index 2616525..5a4d49f 100644 (file)
@@ -26,9 +26,8 @@
 #pragma once
 
 #include "BInline.h"
+#include "Mutex.h"
 #include "Sizes.h"
-#include "StaticMutex.h"
-#include <mutex>
 
 namespace bmalloc {
 
@@ -47,7 +46,7 @@ namespace bmalloc {
 // x = object->m_field; // OK
 // if (globalFlag) { ... } // Undefined behavior.
 //
-// std::lock_guard<StaticMutex> lock(PerProcess<Object>::mutex());
+// std::lock_guard<Mutex> lock(PerProcess<Object>::mutex());
 // Object* object = PerProcess<Object>::get(lock);
 // if (globalFlag) { ... } // OK.
 
@@ -56,7 +55,7 @@ struct PerProcessData {
     void* memory;
     size_t size;
     size_t alignment;
-    StaticMutex mutex;
+    Mutex mutex;
     bool isInitialized;
     PerProcessData* next;
 };
@@ -87,7 +86,7 @@ public:
         return s_object.load(std::memory_order_relaxed);
     }
     
-    static StaticMutex& mutex()
+    static Mutex& mutex()
     {
         if (!s_data)
             coalesce();
@@ -106,7 +105,7 @@ private:
     
     BNO_INLINE static T* getSlowCase()
     {
-        std::lock_guard<StaticMutex> lock(mutex());
+        std::lock_guard<Mutex> lock(mutex());
         if (!s_object.load()) {
             if (s_data->isInitialized)
                 s_object.store(static_cast<T*>(s_data->memory));
index 670725b..8f7576f 100644 (file)
@@ -41,7 +41,7 @@ namespace bmalloc {
 
 static constexpr bool verbose = false;
 
-Scavenger::Scavenger(std::lock_guard<StaticMutex>&)
+Scavenger::Scavenger(std::lock_guard<Mutex>&)
 {
 #if BOS(DARWIN)
     auto queue = dispatch_queue_create("WebKit Malloc Memory Pressure Handler", DISPATCH_QUEUE_SERIAL);
@@ -152,7 +152,7 @@ void Scavenger::scavenge()
     }
 
     {
-        std::lock_guard<StaticMutex> lock(Heap::mutex());
+        std::lock_guard<Mutex> lock(Heap::mutex());
         for (unsigned i = numHeaps; i--;) {
             if (!isActiveHeapKind(static_cast<HeapKind>(i)))
                 continue;
@@ -182,7 +182,7 @@ size_t Scavenger::freeableMemory()
 {
     size_t result = 0;
     {
-        std::lock_guard<StaticMutex> lock(Heap::mutex());
+        std::lock_guard<Mutex> lock(Heap::mutex());
         for (unsigned i = numHeaps; i--;) {
             if (!isActiveHeapKind(static_cast<HeapKind>(i)))
                 continue;
index dd2422b..881c3be 100644 (file)
@@ -41,7 +41,7 @@ namespace bmalloc {
 
 class Scavenger {
 public:
-    BEXPORT Scavenger(std::lock_guard<StaticMutex>&);
+    BEXPORT Scavenger(std::lock_guard<Mutex>&);
     
     ~Scavenger() = delete;
     
index 188930e..c3199c5 100644 (file)
@@ -35,9 +35,9 @@ namespace bmalloc {
 
 class SmallLine {
 public:
-    void ref(std::lock_guard<StaticMutex>&, unsigned char = 1);
-    bool deref(std::lock_guard<StaticMutex>&);
-    unsigned refCount(std::lock_guard<StaticMutex>&) { return m_refCount; }
+    void ref(std::lock_guard<Mutex>&, unsigned char = 1);
+    bool deref(std::lock_guard<Mutex>&);
+    unsigned refCount(std::lock_guard<Mutex>&) { return m_refCount; }
     
     char* begin();
     char* end();
@@ -51,13 +51,13 @@ static_assert(
 
 };
 
-inline void SmallLine::ref(std::lock_guard<StaticMutex>&, unsigned char refCount)
+inline void SmallLine::ref(std::lock_guard<Mutex>&, unsigned char refCount)
 {
     BASSERT(!m_refCount);
     m_refCount = refCount;
 }
 
-inline bool SmallLine::deref(std::lock_guard<StaticMutex>&)
+inline bool SmallLine::deref(std::lock_guard<Mutex>&)
 {
     BASSERT(m_refCount);
     --m_refCount;
index b6c29de..919d142 100644 (file)
@@ -38,15 +38,15 @@ class SmallLine;
 
 class SmallPage : public ListNode<SmallPage> {
 public:
-    void ref(std::lock_guard<StaticMutex>&);
-    bool deref(std::lock_guard<StaticMutex>&);
-    unsigned refCount(std::lock_guard<StaticMutex>&) { return m_refCount; }
+    void ref(std::lock_guard<Mutex>&);
+    bool deref(std::lock_guard<Mutex>&);
+    unsigned refCount(std::lock_guard<Mutex>&) { return m_refCount; }
     
     size_t sizeClass() { return m_sizeClass; }
     void setSizeClass(size_t sizeClass) { m_sizeClass = sizeClass; }
     
-    bool hasFreeLines(std::lock_guard<StaticMutex>&) const { return m_hasFreeLines; }
-    void setHasFreeLines(std::lock_guard<StaticMutex>&, bool hasFreeLines) { m_hasFreeLines = hasFreeLines; }
+    bool hasFreeLines(std::lock_guard<Mutex>&) const { return m_hasFreeLines; }
+    void setHasFreeLines(std::lock_guard<Mutex>&, bool hasFreeLines) { m_hasFreeLines = hasFreeLines; }
     
     bool hasPhysicalPages() { return m_hasPhysicalPages; }
     void setHasPhysicalPages(bool hasPhysicalPages) { m_hasPhysicalPages = hasPhysicalPages; }
@@ -70,14 +70,14 @@ static_assert(
 
 using LineCache = std::array<List<SmallPage>, sizeClassCount>;
 
-inline void SmallPage::ref(std::lock_guard<StaticMutex>&)
+inline void SmallPage::ref(std::lock_guard<Mutex>&)
 {
     BASSERT(!m_slide);
     ++m_refCount;
     BASSERT(m_refCount);
 }
 
-inline bool SmallPage::deref(std::lock_guard<StaticMutex>&)
+inline bool SmallPage::deref(std::lock_guard<Mutex>&)
 {
     BASSERT(!m_slide);
     BASSERT(m_refCount);
diff --git a/Source/bmalloc/bmalloc/StaticMutex.h b/Source/bmalloc/bmalloc/StaticMutex.h
deleted file mode 100644 (file)
index 4598e6e..0000000
+++ /dev/null
@@ -1,103 +0,0 @@
-/*
- * Copyright (C) 2014 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
- */
-
-#ifndef StaticMutex_h
-#define StaticMutex_h
-
-#include "BAssert.h"
-#include <atomic>
-#include <mutex>
-#include <thread>
-
-// A fast replacement for std::mutex, for use in static storage.
-
-// Use StaticMutex in static storage, where global constructors and exit-time
-// destructors are prohibited, but all memory is zero-initialized automatically.
-
-namespace bmalloc {
-
-class StaticMutex {
-protected:
-    // Subclasses that support non-static storage must use explicit initialization.
-    void init();
-
-public:
-    void lock();
-    bool try_lock();
-    void unlock();
-
-private:
-    BEXPORT void lockSlowCase();
-
-    std::atomic_flag m_flag;
-    std::atomic_flag m_isSpinning;
-};
-
-static inline void sleep(
-    std::unique_lock<StaticMutex>& lock, std::chrono::milliseconds duration)
-{
-    if (duration == std::chrono::milliseconds(0))
-        return;
-    
-    lock.unlock();
-    std::this_thread::sleep_for(duration);
-    lock.lock();
-}
-
-static inline void waitUntilFalse(
-    std::unique_lock<StaticMutex>& lock, std::chrono::milliseconds sleepDuration,
-    bool& condition)
-{
-    while (condition) {
-        condition = false;
-        sleep(lock, sleepDuration);
-    }
-}
-
-inline void StaticMutex::init()
-{
-    m_flag.clear();
-    m_isSpinning.clear();
-}
-
-inline bool StaticMutex::try_lock()
-{
-    return !m_flag.test_and_set(std::memory_order_acquire);
-}
-
-inline void StaticMutex::lock()
-{
-    if (!try_lock())
-        lockSlowCase();
-}
-
-inline void StaticMutex::unlock()
-{
-    m_flag.clear(std::memory_order_release);
-}
-
-} // namespace bmalloc
-
-#endif // StaticMutex_h
index 24f6f49..af966a6 100644 (file)
@@ -29,7 +29,7 @@
 
 namespace bmalloc {
 
-VMHeap::VMHeap(std::lock_guard<StaticMutex>&)
+VMHeap::VMHeap(std::lock_guard<Mutex>&)
 {
 }
 
index add005f..41a173b 100644 (file)
@@ -46,7 +46,7 @@ typedef enum { Sync, Async } ScavengeMode;
 
 class VMHeap {
 public:
-    VMHeap(std::lock_guard<StaticMutex>&);
+    VMHeap(std::lock_guard<Mutex>&);
     
     LargeRange tryAllocateLargeChunk(size_t alignment, size_t);
 };
index 7b35b0f..f11b517 100644 (file)
@@ -115,7 +115,7 @@ static const malloc_introspection_t zoneIntrospect = {
     .statistics = bmalloc::statistics
 };
 
-Zone::Zone(std::lock_guard<StaticMutex>&)
+Zone::Zone(std::lock_guard<Mutex>&)
 {
     malloc_zone_t::size = &bmalloc::zoneSize;
     malloc_zone_t::zone_name = "WebKit Malloc";
index 7a00d17..b2f0fa1 100644 (file)
@@ -27,8 +27,8 @@
 #define Zone_h
 
 #include "FixedVector.h"
+#include "Mutex.h"
 #include "Range.h"
-#include "StaticMutex.h"
 #include <malloc/malloc.h>
 #include <mutex>
 
@@ -41,7 +41,7 @@ public:
     // Enough capacity to track a 64GB heap, so probably enough for anything.
     static const size_t capacity = 2048;
 
-    Zone(std::lock_guard<StaticMutex>&);
+    Zone(std::lock_guard<Mutex>&);
     Zone(task_t, memory_reader_t, vm_address_t);
 
     void addRange(Range);
index 92ea3b4..9147439 100644 (file)
@@ -52,7 +52,7 @@ void* tryLargeZeroedMemalignVirtual(size_t alignment, size_t size, HeapKind kind
 
     void* result;
     {
-        std::lock_guard<StaticMutex> lock(Heap::mutex());
+        std::lock_guard<Mutex> lock(Heap::mutex());
         result = heap.tryAllocateLarge(lock, alignment, size);
     }
 
@@ -65,7 +65,7 @@ void freeLargeVirtual(void* object, HeapKind kind)
 {
     kind = mapToActiveHeapKind(kind);
     Heap& heap = PerProcess<PerHeapKind<Heap>>::get()->at(kind);
-    std::lock_guard<StaticMutex> lock(Heap::mutex());
+    std::lock_guard<Mutex> lock(Heap::mutex());
     heap.deallocateLarge(lock, object);
 }
 
@@ -79,14 +79,14 @@ void scavenge()
 bool isEnabled(HeapKind kind)
 {
     kind = mapToActiveHeapKind(kind);
-    std::unique_lock<StaticMutex> lock(Heap::mutex());
+    std::unique_lock<Mutex> lock(Heap::mutex());
     return !PerProcess<PerHeapKind<Heap>>::getFastCase()->at(kind).debugHeap();
 }
 
 #if BOS(DARWIN)
 void setScavengerThreadQOSClass(qos_class_t overrideClass)
 {
-    std::unique_lock<StaticMutex> lock(Heap::mutex());
+    std::unique_lock<Mutex> lock(Heap::mutex());
     PerProcess<Scavenger>::get()->setScavengerThreadQOSClass(overrideClass);
 }
 #endif
index 8bf7fa9..796b24e 100644 (file)
@@ -30,9 +30,9 @@
 #include "Gigacage.h"
 #include "Heap.h"
 #include "IsoTLS.h"
+#include "Mutex.h"
 #include "PerHeapKind.h"
 #include "Scavenger.h"
-#include "StaticMutex.h"
 
 namespace bmalloc {
 namespace api {