Changeset 167540 in webkit


Ignore:
Timestamp:
Apr 19, 2014 11:36:56 AM (10 years ago)
Author:
ggaren@apple.com
Message:

bmalloc: Mutex should be harder to use wrong
https://bugs.webkit.org/show_bug.cgi?id=131879

Reviewed by Andreas Kling.

Mutex now has a proper constructor, so you can't deadlock by forgetting
to initialize it.

  • bmalloc.xcodeproj/project.pbxproj:
  • bmalloc/Allocator.cpp:

(bmalloc::Allocator::processXSmallAllocatorLog):
(bmalloc::Allocator::processSmallAllocatorLog):
(bmalloc::Allocator::processMediumAllocatorLog):
(bmalloc::Allocator::allocateLarge):
(bmalloc::Allocator::allocateXLarge): Global replace Mutex => StaticMutex,
since the Heap mutex is a static.

  • bmalloc/AsyncTask.h:

(bmalloc::Function>::AsyncTask): Use Mutex, since we're not static. No
need for explicit initialization anymore.

  • bmalloc/Deallocator.cpp:

(bmalloc::Deallocator::scavenge):
(bmalloc::Deallocator::deallocateLarge):
(bmalloc::Deallocator::deallocateXLarge):
(bmalloc::Deallocator::processObjectLog):
(bmalloc::Deallocator::deallocateSmallLine):
(bmalloc::Deallocator::deallocateXSmallLine):
(bmalloc::Deallocator::allocateSmallLine):
(bmalloc::Deallocator::allocateXSmallLine):
(bmalloc::Deallocator::deallocateMediumLine):
(bmalloc::Deallocator::allocateMediumLine):

  • bmalloc/Deallocator.h:
  • bmalloc/Heap.cpp:

(bmalloc::sleep):
(bmalloc::Heap::Heap):
(bmalloc::Heap::concurrentScavenge):
(bmalloc::Heap::scavenge):
(bmalloc::Heap::scavengeSmallPages):
(bmalloc::Heap::scavengeXSmallPages):
(bmalloc::Heap::scavengeMediumPages):
(bmalloc::Heap::scavengeLargeRanges):
(bmalloc::Heap::allocateXSmallLineSlowCase):
(bmalloc::Heap::allocateSmallLineSlowCase):
(bmalloc::Heap::allocateMediumLineSlowCase):
(bmalloc::Heap::allocateXLarge):
(bmalloc::Heap::deallocateXLarge):
(bmalloc::Heap::allocateLarge):
(bmalloc::Heap::deallocateLarge):

  • bmalloc/Heap.h:

(bmalloc::Heap::deallocateXSmallLine):
(bmalloc::Heap::allocateXSmallLine):
(bmalloc::Heap::deallocateSmallLine):
(bmalloc::Heap::allocateSmallLine):
(bmalloc::Heap::deallocateMediumLine):
(bmalloc::Heap::allocateMediumLine):

  • bmalloc/Line.h:

(bmalloc::Line<Traits>::deref):

  • bmalloc/Mutex.cpp: Removed.
  • bmalloc/Mutex.h:

(bmalloc::Mutex::Mutex):
(bmalloc::Mutex::init): Deleted.
(bmalloc::Mutex::try_lock): Deleted.
(bmalloc::Mutex::lock): Deleted.
(bmalloc::Mutex::unlock): Deleted.

  • bmalloc/Page.h:

(bmalloc::Page<Traits>::ref):
(bmalloc::Page<Traits>::deref):
(bmalloc::Page<Traits>::refCount):

  • bmalloc/PerProcess.h:

(bmalloc::PerProcess::mutex):
(bmalloc::PerProcess<T>::getSlowCase):

  • bmalloc/StaticMutex.cpp: Added.

(bmalloc::StaticMutex::lockSlowCase):

  • bmalloc/StaticMutex.h: Added.

(bmalloc::StaticMutex::init):
(bmalloc::StaticMutex::try_lock):
(bmalloc::StaticMutex::lock):
(bmalloc::StaticMutex::unlock):

  • bmalloc/VMHeap.h:

(bmalloc::VMHeap::deallocateXSmallPage):
(bmalloc::VMHeap::deallocateSmallPage):
(bmalloc::VMHeap::deallocateMediumPage):
(bmalloc::VMHeap::deallocateLargeRange):

  • bmalloc/bmalloc.h:

(bmalloc::api::scavenge): Global replace Mutex => StaticMutex,
since the Heap mutex is a static.

Location:
trunk/Source/bmalloc
Files:
2 added
1 deleted
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/bmalloc/ChangeLog

    r167526 r167540  
     12014-04-19  Geoffrey Garen  <ggaren@apple.com>
     2
     3        bmalloc: Mutex should be harder to use wrong
     4        https://bugs.webkit.org/show_bug.cgi?id=131879
     5
     6        Reviewed by Andreas Kling.
     7
     8        Mutex now has a proper constructor, so you can't deadlock by forgetting
     9        to initialize it.
     10
     11        * bmalloc.xcodeproj/project.pbxproj:
     12        * bmalloc/Allocator.cpp:
     13        (bmalloc::Allocator::processXSmallAllocatorLog):
     14        (bmalloc::Allocator::processSmallAllocatorLog):
     15        (bmalloc::Allocator::processMediumAllocatorLog):
     16        (bmalloc::Allocator::allocateLarge):
     17        (bmalloc::Allocator::allocateXLarge): Global replace Mutex => StaticMutex,
     18        since the Heap mutex is a static.
     19
     20        * bmalloc/AsyncTask.h:
     21        (bmalloc::Function>::AsyncTask): Use Mutex, since we're not static. No
     22        need for explicit initialization anymore.
     23
     24        * bmalloc/Deallocator.cpp:
     25        (bmalloc::Deallocator::scavenge):
     26        (bmalloc::Deallocator::deallocateLarge):
     27        (bmalloc::Deallocator::deallocateXLarge):
     28        (bmalloc::Deallocator::processObjectLog):
     29        (bmalloc::Deallocator::deallocateSmallLine):
     30        (bmalloc::Deallocator::deallocateXSmallLine):
     31        (bmalloc::Deallocator::allocateSmallLine):
     32        (bmalloc::Deallocator::allocateXSmallLine):
     33        (bmalloc::Deallocator::deallocateMediumLine):
     34        (bmalloc::Deallocator::allocateMediumLine):
     35        * bmalloc/Deallocator.h:
     36        * bmalloc/Heap.cpp:
     37        (bmalloc::sleep):
     38        (bmalloc::Heap::Heap):
     39        (bmalloc::Heap::concurrentScavenge):
     40        (bmalloc::Heap::scavenge):
     41        (bmalloc::Heap::scavengeSmallPages):
     42        (bmalloc::Heap::scavengeXSmallPages):
     43        (bmalloc::Heap::scavengeMediumPages):
     44        (bmalloc::Heap::scavengeLargeRanges):
     45        (bmalloc::Heap::allocateXSmallLineSlowCase):
     46        (bmalloc::Heap::allocateSmallLineSlowCase):
     47        (bmalloc::Heap::allocateMediumLineSlowCase):
     48        (bmalloc::Heap::allocateXLarge):
     49        (bmalloc::Heap::deallocateXLarge):
     50        (bmalloc::Heap::allocateLarge):
     51        (bmalloc::Heap::deallocateLarge):
     52        * bmalloc/Heap.h:
     53        (bmalloc::Heap::deallocateXSmallLine):
     54        (bmalloc::Heap::allocateXSmallLine):
     55        (bmalloc::Heap::deallocateSmallLine):
     56        (bmalloc::Heap::allocateSmallLine):
     57        (bmalloc::Heap::deallocateMediumLine):
     58        (bmalloc::Heap::allocateMediumLine):
     59        * bmalloc/Line.h:
     60        (bmalloc::Line<Traits>::deref):
     61        * bmalloc/Mutex.cpp: Removed.
     62        * bmalloc/Mutex.h:
     63        (bmalloc::Mutex::Mutex):
     64        (bmalloc::Mutex::init): Deleted.
     65        (bmalloc::Mutex::try_lock): Deleted.
     66        (bmalloc::Mutex::lock): Deleted.
     67        (bmalloc::Mutex::unlock): Deleted.
     68        * bmalloc/Page.h:
     69        (bmalloc::Page<Traits>::ref):
     70        (bmalloc::Page<Traits>::deref):
     71        (bmalloc::Page<Traits>::refCount):
     72        * bmalloc/PerProcess.h:
     73        (bmalloc::PerProcess::mutex):
     74        (bmalloc::PerProcess<T>::getSlowCase):
     75        * bmalloc/StaticMutex.cpp: Added.
     76        (bmalloc::StaticMutex::lockSlowCase):
     77        * bmalloc/StaticMutex.h: Added.
     78        (bmalloc::StaticMutex::init):
     79        (bmalloc::StaticMutex::try_lock):
     80        (bmalloc::StaticMutex::lock):
     81        (bmalloc::StaticMutex::unlock):
     82        * bmalloc/VMHeap.h:
     83        (bmalloc::VMHeap::deallocateXSmallPage):
     84        (bmalloc::VMHeap::deallocateSmallPage):
     85        (bmalloc::VMHeap::deallocateMediumPage):
     86        (bmalloc::VMHeap::deallocateLargeRange):
     87        * bmalloc/bmalloc.h:
     88        (bmalloc::api::scavenge): Global replace Mutex => StaticMutex,
     89        since the Heap mutex is a static.
     90
    1912014-04-18  Geoffrey Garen  <ggaren@apple.com>
    292
  • trunk/Source/bmalloc/bmalloc.xcodeproj/project.pbxproj

    r167502 r167540  
    1717                142FCC7B190080B8009032D4 /* XSmallTraits.h in Headers */ = {isa = PBXBuildFile; fileRef = 142FCC77190080B8009032D4 /* XSmallTraits.h */; };
    1818                142FCC7D1900815E009032D4 /* XSmallAllocator.h in Headers */ = {isa = PBXBuildFile; fileRef = 142FCC7C1900815E009032D4 /* XSmallAllocator.h */; };
     19                143CB81C19022BC900B16A45 /* StaticMutex.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 143CB81A19022BC900B16A45 /* StaticMutex.cpp */; };
     20                143CB81D19022BC900B16A45 /* StaticMutex.h in Headers */ = {isa = PBXBuildFile; fileRef = 143CB81B19022BC900B16A45 /* StaticMutex.h */; };
    1921                1448C30018F3754600502839 /* mbmalloc.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1448C2FF18F3754300502839 /* mbmalloc.cpp */; };
    2022                1448C30118F3754C00502839 /* bmalloc.h in Headers */ = {isa = PBXBuildFile; fileRef = 1448C2FE18F3754300502839 /* bmalloc.h */; settings = {ATTRIBUTES = (Private, ); }; };
     
    6365                14F271C818EA3990008C152F /* ObjectType.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 14105E8318E14374003A106E /* ObjectType.cpp */; };
    6466                14F271C918EA3990008C152F /* VMHeap.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 144F7BFB18BFC517003537F3 /* VMHeap.cpp */; };
    65                 14F271CA18EA3990008C152F /* Mutex.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 144DCED817A728570093B2F2 /* Mutex.cpp */; };
    6667/* End PBXBuildFile section */
    6768
     
    9394                142FCC77190080B8009032D4 /* XSmallTraits.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = XSmallTraits.h; path = bmalloc/XSmallTraits.h; sourceTree = "<group>"; };
    9495                142FCC7C1900815E009032D4 /* XSmallAllocator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = XSmallAllocator.h; path = bmalloc/XSmallAllocator.h; sourceTree = "<group>"; };
     96                143CB81A19022BC900B16A45 /* StaticMutex.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = StaticMutex.cpp; path = bmalloc/StaticMutex.cpp; sourceTree = "<group>"; };
     97                143CB81B19022BC900B16A45 /* StaticMutex.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = StaticMutex.h; path = bmalloc/StaticMutex.h; sourceTree = "<group>"; };
    9598                143E29E918CAE8BE00FE8A0F /* MediumPage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MediumPage.h; path = bmalloc/MediumPage.h; sourceTree = "<group>"; };
    9699                143E29ED18CAE90500FE8A0F /* SmallPage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SmallPage.h; path = bmalloc/SmallPage.h; sourceTree = "<group>"; };
     
    102105                1448C2FF18F3754300502839 /* mbmalloc.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = mbmalloc.cpp; path = bmalloc/mbmalloc.cpp; sourceTree = "<group>"; };
    103106                144DCED617A649D90093B2F2 /* Mutex.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Mutex.h; path = bmalloc/Mutex.h; sourceTree = "<group>"; };
    104                 144DCED817A728570093B2F2 /* Mutex.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Mutex.cpp; path = bmalloc/Mutex.cpp; sourceTree = "<group>"; };
    105107                144F7BFB18BFC517003537F3 /* VMHeap.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = VMHeap.cpp; path = bmalloc/VMHeap.cpp; sourceTree = "<group>"; };
    106108                144F7BFC18BFC517003537F3 /* VMHeap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = VMHeap.h; path = bmalloc/VMHeap.h; sourceTree = "<group>"; };
     
    280282                                14D9DB4517F2447100EAAB79 /* FixedVector.h */,
    281283                                1413E460189DCE1E00546D68 /* Inline.h */,
    282                                 144DCED817A728570093B2F2 /* Mutex.cpp */,
    283284                                144DCED617A649D90093B2F2 /* Mutex.h */,
    284285                                14446A0717A61FA400F9EA1D /* PerProcess.h */,
    285286                                144469FD17A61F1F00F9EA1D /* PerThread.h */,
    286287                                145F6878179E3A4400D65598 /* Range.h */,
     288                                143CB81A19022BC900B16A45 /* StaticMutex.cpp */,
     289                                143CB81B19022BC900B16A45 /* StaticMutex.h */,
    287290                                1417F64F18B7280C0076FA3F /* Syscall.h */,
    288291                                1479E21217A1A255006D4E9D /* Vector.h */,
     
    316319                                14DD78CA18F48D7500950702 /* Mutex.h in Headers */,
    317320                                142FCC7D1900815E009032D4 /* XSmallAllocator.h in Headers */,
     321                                143CB81D19022BC900B16A45 /* StaticMutex.h in Headers */,
    318322                                14DD78D118F48EC600950702 /* XLargeChunk.h in Headers */,
    319323                                14DD78B918F48D6B00950702 /* MediumTraits.h in Headers */,
     
    433437                        buildActionMask = 2147483647;
    434438                        files = (
    435                                 14F271CA18EA3990008C152F /* Mutex.cpp in Sources */,
     439                                143CB81C19022BC900B16A45 /* StaticMutex.cpp in Sources */,
    436440                                14F271C618EA3983008C152F /* SegregatedFreeList.cpp in Sources */,
    437441                                14F271C318EA3978008C152F /* Allocator.cpp in Sources */,
  • trunk/Source/bmalloc/bmalloc/Allocator.cpp

    r167502 r167540  
    8383void Allocator::processXSmallAllocatorLog()
    8484{
    85     std::lock_guard<Mutex> lock(PerProcess<Heap>::mutex());
     85    std::lock_guard<StaticMutex> lock(PerProcess<Heap>::mutex());
    8686
    8787    for (auto& logEntry : m_xSmallAllocatorLog) {
     
    106106void Allocator::processSmallAllocatorLog()
    107107{
    108     std::lock_guard<Mutex> lock(PerProcess<Heap>::mutex());
     108    std::lock_guard<StaticMutex> lock(PerProcess<Heap>::mutex());
    109109
    110110    for (auto& logEntry : m_smallAllocatorLog) {
     
    129129void Allocator::processMediumAllocatorLog()
    130130{
    131     std::lock_guard<Mutex> lock(PerProcess<Heap>::mutex());
     131    std::lock_guard<StaticMutex> lock(PerProcess<Heap>::mutex());
    132132
    133133    for (auto& logEntry : m_mediumAllocatorLog) {
     
    142142{
    143143    size = roundUpToMultipleOf<largeAlignment>(size);
    144     std::lock_guard<Mutex> lock(PerProcess<Heap>::mutex());
     144    std::lock_guard<StaticMutex> lock(PerProcess<Heap>::mutex());
    145145    return PerProcess<Heap>::getFastCase()->allocateLarge(lock, size);
    146146}
     
    149149{
    150150    size = roundUpToMultipleOf<largeAlignment>(size);
    151     std::lock_guard<Mutex> lock(PerProcess<Heap>::mutex());
     151    std::lock_guard<StaticMutex> lock(PerProcess<Heap>::mutex());
    152152    return PerProcess<Heap>::getFastCase()->allocateXLarge(lock, size);
    153153}
  • trunk/Source/bmalloc/bmalloc/AsyncTask.h

    r167526 r167540  
    7575    , m_function(function)
    7676{
    77     m_conditionMutex.init();
    7877}
    7978
  • trunk/Source/bmalloc/bmalloc/Deallocator.cpp

    r167502 r167540  
    5656    processObjectLog();
    5757   
    58     std::lock_guard<Mutex> lock(PerProcess<Heap>::mutex());
     58    std::lock_guard<StaticMutex> lock(PerProcess<Heap>::mutex());
    5959    Heap* heap = PerProcess<Heap>::getFastCase();
    6060   
     
    6969void Deallocator::deallocateLarge(void* object)
    7070{
    71     std::lock_guard<Mutex> lock(PerProcess<Heap>::mutex());
     71    std::lock_guard<StaticMutex> lock(PerProcess<Heap>::mutex());
    7272    PerProcess<Heap>::getFastCase()->deallocateLarge(lock, object);
    7373}
     
    7575void Deallocator::deallocateXLarge(void* object)
    7676{
    77     std::lock_guard<Mutex> lock(PerProcess<Heap>::mutex());
     77    std::lock_guard<StaticMutex> lock(PerProcess<Heap>::mutex());
    7878    PerProcess<Heap>::getFastCase()->deallocateXLarge(lock, object);
    7979}
     
    8181void Deallocator::processObjectLog()
    8282{
    83     std::lock_guard<Mutex> lock(PerProcess<Heap>::mutex());
     83    std::lock_guard<StaticMutex> lock(PerProcess<Heap>::mutex());
    8484   
    8585    for (auto object : m_objectLog) {
     
    126126}
    127127
    128 void Deallocator::deallocateSmallLine(std::lock_guard<Mutex>& lock, SmallLine* line)
     128void Deallocator::deallocateSmallLine(std::lock_guard<StaticMutex>& lock, SmallLine* line)
    129129{
    130130    if (m_smallLineCache.size() == m_smallLineCache.capacity())
     
    134134}
    135135
    136 void Deallocator::deallocateXSmallLine(std::lock_guard<Mutex>& lock, XSmallLine* line)
     136void Deallocator::deallocateXSmallLine(std::lock_guard<StaticMutex>& lock, XSmallLine* line)
    137137{
    138138    if (m_xSmallLineCache.size() == m_xSmallLineCache.capacity())
     
    145145{
    146146    if (!m_smallLineCache.size()) {
    147         std::lock_guard<Mutex> lock(PerProcess<Heap>::mutex());
     147        std::lock_guard<StaticMutex> lock(PerProcess<Heap>::mutex());
    148148        Heap* heap = PerProcess<Heap>::getFastCase();
    149149
     
    158158{
    159159    if (!m_xSmallLineCache.size()) {
    160         std::lock_guard<Mutex> lock(PerProcess<Heap>::mutex());
     160        std::lock_guard<StaticMutex> lock(PerProcess<Heap>::mutex());
    161161        Heap* heap = PerProcess<Heap>::getFastCase();
    162162
     
    168168}
    169169
    170 void Deallocator::deallocateMediumLine(std::lock_guard<Mutex>& lock, MediumLine* line)
     170void Deallocator::deallocateMediumLine(std::lock_guard<StaticMutex>& lock, MediumLine* line)
    171171{
    172172    if (m_mediumLineCache.size() == m_mediumLineCache.capacity())
     
    179179{
    180180    if (!m_mediumLineCache.size()) {
    181         std::lock_guard<Mutex> lock(PerProcess<Heap>::mutex());
     181        std::lock_guard<StaticMutex> lock(PerProcess<Heap>::mutex());
    182182        Heap* heap = PerProcess<Heap>::getFastCase();
    183183
  • trunk/Source/bmalloc/bmalloc/Deallocator.h

    r167502 r167540  
    4646    void deallocateSlowCase(void*);
    4747
    48     void deallocateXSmallLine(std::lock_guard<Mutex>&, XSmallLine*);
     48    void deallocateXSmallLine(std::lock_guard<StaticMutex>&, XSmallLine*);
    4949    XSmallLine* allocateXSmallLine();
    5050
    51     void deallocateSmallLine(std::lock_guard<Mutex>&, SmallLine*);
     51    void deallocateSmallLine(std::lock_guard<StaticMutex>&, SmallLine*);
    5252    SmallLine* allocateSmallLine();
    5353
    54     void deallocateMediumLine(std::lock_guard<Mutex>&, MediumLine*);
     54    void deallocateMediumLine(std::lock_guard<StaticMutex>&, MediumLine*);
    5555    MediumLine* allocateMediumLine();
    5656   
  • trunk/Source/bmalloc/bmalloc/Heap.cpp

    r167502 r167540  
    3838namespace bmalloc {
    3939
    40 static inline void sleep(std::unique_lock<Mutex>& lock, std::chrono::milliseconds duration)
     40static inline void sleep(std::unique_lock<StaticMutex>& lock, std::chrono::milliseconds duration)
    4141{
    4242    if (duration == std::chrono::milliseconds(0))
     
    4848}
    4949
    50 Heap::Heap(std::lock_guard<Mutex>&)
     50Heap::Heap(std::lock_guard<StaticMutex>&)
    5151    : m_isAllocatingPages(false)
    5252    , m_scavenger(*this, &Heap::concurrentScavenge)
     
    5656void Heap::concurrentScavenge()
    5757{
    58     std::unique_lock<Mutex> lock(PerProcess<Heap>::mutex());
     58    std::unique_lock<StaticMutex> lock(PerProcess<Heap>::mutex());
    5959    scavenge(lock, scavengeSleepDuration);
    6060}
    6161   
    62 void Heap::scavenge(std::unique_lock<Mutex>& lock, std::chrono::milliseconds sleepDuration)
     62void Heap::scavenge(std::unique_lock<StaticMutex>& lock, std::chrono::milliseconds sleepDuration)
    6363{
    6464    scavengeXSmallPages(lock, sleepDuration);
     
    7070}
    7171
    72 void Heap::scavengeSmallPages(std::unique_lock<Mutex>& lock, std::chrono::milliseconds sleepDuration)
     72void Heap::scavengeSmallPages(std::unique_lock<StaticMutex>& lock, std::chrono::milliseconds sleepDuration)
    7373{
    7474    while (1) {
     
    8686}
    8787
    88 void Heap::scavengeXSmallPages(std::unique_lock<Mutex>& lock, std::chrono::milliseconds sleepDuration)
     88void Heap::scavengeXSmallPages(std::unique_lock<StaticMutex>& lock, std::chrono::milliseconds sleepDuration)
    8989{
    9090    while (1) {
     
    102102}
    103103
    104 void Heap::scavengeMediumPages(std::unique_lock<Mutex>& lock, std::chrono::milliseconds sleepDuration)
     104void Heap::scavengeMediumPages(std::unique_lock<StaticMutex>& lock, std::chrono::milliseconds sleepDuration)
    105105{
    106106    while (1) {
     
    118118}
    119119
    120 void Heap::scavengeLargeRanges(std::unique_lock<Mutex>& lock, std::chrono::milliseconds sleepDuration)
     120void Heap::scavengeLargeRanges(std::unique_lock<StaticMutex>& lock, std::chrono::milliseconds sleepDuration)
    121121{
    122122    while (1) {
     
    135135}
    136136
    137 XSmallLine* Heap::allocateXSmallLineSlowCase(std::lock_guard<Mutex>& lock)
     137XSmallLine* Heap::allocateXSmallLineSlowCase(std::lock_guard<StaticMutex>& lock)
    138138{
    139139    m_isAllocatingPages = true;
     
    156156}
    157157
    158 SmallLine* Heap::allocateSmallLineSlowCase(std::lock_guard<Mutex>& lock)
     158SmallLine* Heap::allocateSmallLineSlowCase(std::lock_guard<StaticMutex>& lock)
    159159{
    160160    m_isAllocatingPages = true;
     
    177177}
    178178
    179 MediumLine* Heap::allocateMediumLineSlowCase(std::lock_guard<Mutex>& lock)
     179MediumLine* Heap::allocateMediumLineSlowCase(std::lock_guard<StaticMutex>& lock)
    180180{
    181181    m_isAllocatingPages = true;
     
    198198}
    199199
    200 void* Heap::allocateXLarge(std::lock_guard<Mutex>&, size_t size)
     200void* Heap::allocateXLarge(std::lock_guard<StaticMutex>&, size_t size)
    201201{
    202202    XLargeChunk* chunk = XLargeChunk::create(size);
     
    210210}
    211211
    212 void Heap::deallocateXLarge(std::lock_guard<Mutex>&, void* object)
     212void Heap::deallocateXLarge(std::lock_guard<StaticMutex>&, void* object)
    213213{
    214214    XLargeChunk* chunk = XLargeChunk::get(object);
     
    216216}
    217217
    218 void* Heap::allocateLarge(std::lock_guard<Mutex>&, size_t size)
     218void* Heap::allocateLarge(std::lock_guard<StaticMutex>&, size_t size)
    219219{
    220220    BASSERT(size <= largeMax);
     
    240240}
    241241
    242 void Heap::deallocateLarge(std::lock_guard<Mutex>&, void* object)
     242void Heap::deallocateLarge(std::lock_guard<StaticMutex>&, void* object)
    243243{
    244244    Range range = BoundaryTag::deallocate(object);
  • trunk/Source/bmalloc/bmalloc/Heap.h

    r167502 r167540  
    4545class Heap {
    4646public:
    47     Heap(std::lock_guard<Mutex>&);
     47    Heap(std::lock_guard<StaticMutex>&);
    4848   
    49     XSmallLine* allocateXSmallLine(std::lock_guard<Mutex>&);
    50     void deallocateXSmallLine(std::lock_guard<Mutex>&, XSmallLine*);
     49    XSmallLine* allocateXSmallLine(std::lock_guard<StaticMutex>&);
     50    void deallocateXSmallLine(std::lock_guard<StaticMutex>&, XSmallLine*);
    5151
    52     SmallLine* allocateSmallLine(std::lock_guard<Mutex>&);
    53     void deallocateSmallLine(std::lock_guard<Mutex>&, SmallLine*);
     52    SmallLine* allocateSmallLine(std::lock_guard<StaticMutex>&);
     53    void deallocateSmallLine(std::lock_guard<StaticMutex>&, SmallLine*);
    5454
    55     MediumLine* allocateMediumLine(std::lock_guard<Mutex>&);
    56     void deallocateMediumLine(std::lock_guard<Mutex>&, MediumLine*);
     55    MediumLine* allocateMediumLine(std::lock_guard<StaticMutex>&);
     56    void deallocateMediumLine(std::lock_guard<StaticMutex>&, MediumLine*);
    5757   
    58     void* allocateLarge(std::lock_guard<Mutex>&, size_t);
    59     void deallocateLarge(std::lock_guard<Mutex>&, void*);
     58    void* allocateLarge(std::lock_guard<StaticMutex>&, size_t);
     59    void deallocateLarge(std::lock_guard<StaticMutex>&, void*);
    6060
    61     void* allocateXLarge(std::lock_guard<Mutex>&, size_t);
    62     void deallocateXLarge(std::lock_guard<Mutex>&, void*);
     61    void* allocateXLarge(std::lock_guard<StaticMutex>&, size_t);
     62    void deallocateXLarge(std::lock_guard<StaticMutex>&, void*);
    6363
    64     void scavenge(std::unique_lock<Mutex>&, std::chrono::milliseconds sleepDuration);
     64    void scavenge(std::unique_lock<StaticMutex>&, std::chrono::milliseconds sleepDuration);
    6565   
    6666private:
    6767    ~Heap() = delete;
    6868
    69     XSmallLine* allocateXSmallLineSlowCase(std::lock_guard<Mutex>&);
    70     SmallLine* allocateSmallLineSlowCase(std::lock_guard<Mutex>&);
    71     MediumLine* allocateMediumLineSlowCase(std::lock_guard<Mutex>&);
     69    XSmallLine* allocateXSmallLineSlowCase(std::lock_guard<StaticMutex>&);
     70    SmallLine* allocateSmallLineSlowCase(std::lock_guard<StaticMutex>&);
     71    MediumLine* allocateMediumLineSlowCase(std::lock_guard<StaticMutex>&);
    7272
    7373    void* allocateLarge(Range, size_t);
     
    8080   
    8181    void concurrentScavenge();
    82     void scavengeXSmallPages(std::unique_lock<Mutex>&, std::chrono::milliseconds);
    83     void scavengeSmallPages(std::unique_lock<Mutex>&, std::chrono::milliseconds);
    84     void scavengeMediumPages(std::unique_lock<Mutex>&, std::chrono::milliseconds);
    85     void scavengeLargeRanges(std::unique_lock<Mutex>&, std::chrono::milliseconds);
     82    void scavengeXSmallPages(std::unique_lock<StaticMutex>&, std::chrono::milliseconds);
     83    void scavengeSmallPages(std::unique_lock<StaticMutex>&, std::chrono::milliseconds);
     84    void scavengeMediumPages(std::unique_lock<StaticMutex>&, std::chrono::milliseconds);
     85    void scavengeLargeRanges(std::unique_lock<StaticMutex>&, std::chrono::milliseconds);
    8686
    8787    Vector<XSmallLine*> m_xSmallLines;
     
    101101};
    102102
    103 inline void Heap::deallocateXSmallLine(std::lock_guard<Mutex>& lock, XSmallLine* line)
     103inline void Heap::deallocateXSmallLine(std::lock_guard<StaticMutex>& lock, XSmallLine* line)
    104104{
    105105    XSmallPage* page = XSmallPage::get(line);
     
    112112}
    113113
    114 inline XSmallLine* Heap::allocateXSmallLine(std::lock_guard<Mutex>& lock)
     114inline XSmallLine* Heap::allocateXSmallLine(std::lock_guard<StaticMutex>& lock)
    115115{
    116116    while (m_xSmallLines.size()) {
     
    126126}
    127127
    128 inline void Heap::deallocateSmallLine(std::lock_guard<Mutex>& lock, SmallLine* line)
     128inline void Heap::deallocateSmallLine(std::lock_guard<StaticMutex>& lock, SmallLine* line)
    129129{
    130130    SmallPage* page = SmallPage::get(line);
     
    137137}
    138138
    139 inline SmallLine* Heap::allocateSmallLine(std::lock_guard<Mutex>& lock)
     139inline SmallLine* Heap::allocateSmallLine(std::lock_guard<StaticMutex>& lock)
    140140{
    141141    while (m_smallLines.size()) {
     
    151151}
    152152
    153 inline void Heap::deallocateMediumLine(std::lock_guard<Mutex>& lock, MediumLine* line)
     153inline void Heap::deallocateMediumLine(std::lock_guard<StaticMutex>& lock, MediumLine* line)
    154154{
    155155    MediumPage* page = MediumPage::get(line);
     
    162162}
    163163
    164 inline MediumLine* Heap::allocateMediumLine(std::lock_guard<Mutex>& lock)
     164inline MediumLine* Heap::allocateMediumLine(std::lock_guard<StaticMutex>& lock)
    165165{
    166166    while (m_mediumLines.size()) {
  • trunk/Source/bmalloc/bmalloc/Line.h

    r167502 r167540  
    4747
    4848    void concurrentRef(unsigned char = 1);
    49     bool deref(std::lock_guard<Mutex>&, unsigned char = 1);
     49    bool deref(std::lock_guard<StaticMutex>&, unsigned char = 1);
    5050   
    5151    char* begin();
     
    8989
    9090template<class Traits>
    91 inline bool Line<Traits>::deref(std::lock_guard<Mutex>&, unsigned char count)
     91inline bool Line<Traits>::deref(std::lock_guard<StaticMutex>&, unsigned char count)
    9292{
    9393    BASSERT(count <= m_refCount);
  • trunk/Source/bmalloc/bmalloc/Mutex.h

    r167526 r167540  
    2727#define Mutex_h
    2828
    29 #include "BAssert.h"
    30 #include <atomic>
     29#include "StaticMutex.h"
    3130
    32 // A replacement for std::mutex that does not require an exit-time destructor.
     31// A fast replacement for std::mutex.
    3332
    3433namespace bmalloc {
    3534
    36 struct Mutex {
     35class Mutex : public StaticMutex {
    3736public:
    38     void init();
    39 
    40     void lock();
    41     bool try_lock();
    42     void unlock();
    43    
    44 private:
    45     void lockSlowCase();
    46 
    47     std::atomic_flag m_flag;
     37    Mutex();
    4838};
    4939
    50 inline void Mutex::init()
     40inline Mutex::Mutex()
    5141{
    52     m_flag.clear();
    53 }
    54 
    55 inline bool Mutex::try_lock()
    56 {
    57     return !m_flag.test_and_set(std::memory_order_acquire);
    58 }
    59 
    60 inline void Mutex::lock()
    61 {
    62     if (!try_lock())
    63         lockSlowCase();
    64 }
    65 
    66 inline void Mutex::unlock()
    67 {
    68     m_flag.clear(std::memory_order_release);
     42    init();
    6943}
    7044
  • trunk/Source/bmalloc/bmalloc/Page.h

    r166956 r167540  
    4646    static Page* get(Line*);
    4747
    48     void ref(std::lock_guard<Mutex>&);
    49     bool deref(std::lock_guard<Mutex>&);
    50     unsigned refCount(std::lock_guard<Mutex>&);
     48    void ref(std::lock_guard<StaticMutex>&);
     49    bool deref(std::lock_guard<StaticMutex>&);
     50    unsigned refCount(std::lock_guard<StaticMutex>&);
    5151   
    5252    Line* begin();
     
    5858
    5959template<typename Traits>
    60 inline void Page<Traits>::ref(std::lock_guard<Mutex>&)
     60inline void Page<Traits>::ref(std::lock_guard<StaticMutex>&)
    6161{
    6262    BASSERT(m_refCount < maxRefCount);
     
    6565
    6666template<typename Traits>
    67 inline bool Page<Traits>::deref(std::lock_guard<Mutex>&)
     67inline bool Page<Traits>::deref(std::lock_guard<StaticMutex>&)
    6868{
    6969    BASSERT(m_refCount);
     
    7373
    7474template<typename Traits>
    75 inline unsigned Page<Traits>::refCount(std::lock_guard<Mutex>&)
     75inline unsigned Page<Traits>::refCount(std::lock_guard<StaticMutex>&)
    7676{
    7777    return m_refCount;
  • trunk/Source/bmalloc/bmalloc/PerProcess.h

    r166893 r167540  
    2828
    2929#include "Inline.h"
    30 #include "Mutex.h"
    3130#include "Sizes.h"
     31#include "StaticMutex.h"
    3232#include <mutex>
    3333
     
    4949// if (gobalFlag) { ... } // Undefined behavior.
    5050//
    51 // std::lock_guard<Mutex> lock(PerProcess<Object>::mutex());
     51// std::lock_guard<StaticMutex> lock(PerProcess<Object>::mutex());
    5252// Object* object = PerProcess<Object>::get(lock);
    5353// if (gobalFlag) { ... } // OK.
     
    5959    static T* getFastCase();
    6060   
    61     static Mutex& mutex() { return s_mutex; }
     61    static StaticMutex& mutex() { return s_mutex; }
    6262
    6363private:
     
    6565
    6666    static std::atomic<T*> s_object;
    67     static Mutex s_mutex;
     67    static StaticMutex s_mutex;
    6868
    6969    typedef typename std::aligned_storage<sizeof(T), std::alignment_of<T>::value>::type Memory;
     
    8989NO_INLINE T* PerProcess<T>::getSlowCase()
    9090{
    91     std::lock_guard<Mutex> lock(s_mutex);
     91    std::lock_guard<StaticMutex> lock(s_mutex);
    9292    if (!s_object.load(std::memory_order_consume)) {
    9393        T* t = new (&s_memory) T(lock);
     
    101101
    102102template<typename T>
    103 Mutex PerProcess<T>::s_mutex;
     103StaticMutex PerProcess<T>::s_mutex;
    104104
    105105template<typename T>
  • trunk/Source/bmalloc/bmalloc/VMHeap.h

    r167502 r167540  
    5252    Range allocateLargeRange(size_t);
    5353
    54     void deallocateXSmallPage(std::unique_lock<Mutex>&, XSmallPage*);
    55     void deallocateSmallPage(std::unique_lock<Mutex>&, SmallPage*);
    56     void deallocateMediumPage(std::unique_lock<Mutex>&, MediumPage*);
    57     void deallocateLargeRange(std::unique_lock<Mutex>&, Range);
     54    void deallocateXSmallPage(std::unique_lock<StaticMutex>&, XSmallPage*);
     55    void deallocateSmallPage(std::unique_lock<StaticMutex>&, SmallPage*);
     56    void deallocateMediumPage(std::unique_lock<StaticMutex>&, MediumPage*);
     57    void deallocateLargeRange(std::unique_lock<StaticMutex>&, Range);
    5858
    5959private:
     
    101101}
    102102
    103 inline void VMHeap::deallocateXSmallPage(std::unique_lock<Mutex>& lock, XSmallPage* page)
     103inline void VMHeap::deallocateXSmallPage(std::unique_lock<StaticMutex>& lock, XSmallPage* page)
    104104{
    105105    lock.unlock();
     
    110110}
    111111
    112 inline void VMHeap::deallocateSmallPage(std::unique_lock<Mutex>& lock, SmallPage* page)
     112inline void VMHeap::deallocateSmallPage(std::unique_lock<StaticMutex>& lock, SmallPage* page)
    113113{
    114114    lock.unlock();
     
    119119}
    120120
    121 inline void VMHeap::deallocateMediumPage(std::unique_lock<Mutex>& lock, MediumPage* page)
     121inline void VMHeap::deallocateMediumPage(std::unique_lock<StaticMutex>& lock, MediumPage* page)
    122122{
    123123    lock.unlock();
     
    128128}
    129129
    130 inline void VMHeap::deallocateLargeRange(std::unique_lock<Mutex>& lock, Range range)
     130inline void VMHeap::deallocateLargeRange(std::unique_lock<StaticMutex>& lock, Range range)
    131131{
    132132    BeginTag* beginTag = LargeChunk::beginTag(range.begin());
  • trunk/Source/bmalloc/bmalloc/bmalloc.h

    r167502 r167540  
    9292    PerThread<Cache>::get()->scavenge();
    9393   
    94     std::unique_lock<Mutex> lock(PerProcess<Heap>::mutex());
     94    std::unique_lock<StaticMutex> lock(PerProcess<Heap>::mutex());
    9595    PerProcess<Heap>::get()->scavenge(lock, std::chrono::milliseconds(0));
    9696}
Note: See TracChangeset for help on using the changeset viewer.