Commit f7a788fa authored by andersca@apple.com's avatar andersca@apple.com

Stop using ThreadCondition in BlockAllocator

https://bugs.webkit.org/show_bug.cgi?id=126313

Reviewed by Sam Weinig.

* heap/BlockAllocator.cpp:
(JSC::BlockAllocator::~BlockAllocator):
(JSC::BlockAllocator::waitForDuration):
(JSC::BlockAllocator::blockFreeingThreadMain):
* heap/BlockAllocator.h:
(JSC::BlockAllocator::deallocate):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@162362 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 679d978c
2014-01-20 Anders Carlsson <andersca@apple.com>
Stop using ThreadCondition in BlockAllocator
https://bugs.webkit.org/show_bug.cgi?id=126313
Reviewed by Sam Weinig.
* heap/BlockAllocator.cpp:
(JSC::BlockAllocator::~BlockAllocator):
(JSC::BlockAllocator::waitForDuration):
(JSC::BlockAllocator::blockFreeingThreadMain):
* heap/BlockAllocator.h:
(JSC::BlockAllocator::deallocate):
2014-01-19 Anders Carlsson <andersca@apple.com>
Convert GCThreadSharedData over to STL threading primitives
......
......@@ -61,9 +61,9 @@ BlockAllocator::~BlockAllocator()
{
releaseFreeRegions();
{
MutexLocker locker(m_emptyRegionConditionLock);
std::lock_guard<std::mutex> lock(m_emptyRegionConditionMutex);
m_blockFreeingThreadShouldQuit = true;
m_emptyRegionCondition.broadcast();
m_emptyRegionCondition.notify_all();
}
if (m_blockFreeingThread)
waitForThreadCompletion(m_blockFreeingThread);
......@@ -101,22 +101,17 @@ void BlockAllocator::releaseFreeRegions()
}
}
void BlockAllocator::waitForRelativeTimeWhileHoldingLock(double relative)
void BlockAllocator::waitForDuration(std::chrono::milliseconds duration)
{
if (m_blockFreeingThreadShouldQuit)
return;
m_emptyRegionCondition.timedWait(m_emptyRegionConditionLock, currentTime() + relative);
}
std::unique_lock<std::mutex> lock(m_emptyRegionConditionMutex);
void BlockAllocator::waitForRelativeTime(double relative)
{
// If this returns early, that's fine, so long as it doesn't do it too
// frequently. It would only be a bug if this function failed to return
// when it was asked to do so.
MutexLocker locker(m_emptyRegionConditionLock);
waitForRelativeTimeWhileHoldingLock(relative);
if (m_blockFreeingThreadShouldQuit)
return;
m_emptyRegionCondition.wait_for(lock, duration);
}
void BlockAllocator::blockFreeingThreadStartFunc(void* blockAllocator)
......@@ -130,7 +125,7 @@ void BlockAllocator::blockFreeingThreadMain()
while (!m_blockFreeingThreadShouldQuit) {
// Generally wait for one second before scavenging free blocks. This
// may return early, particularly when we're being asked to quit.
waitForRelativeTime(1.0);
waitForDuration(std::chrono::seconds(1));
if (m_blockFreeingThreadShouldQuit)
break;
......@@ -141,11 +136,11 @@ void BlockAllocator::blockFreeingThreadMain()
// Sleep until there is actually work to do rather than waking up every second to check.
{
MutexLocker locker(m_emptyRegionConditionLock);
std::unique_lock<std::mutex> lock(m_emptyRegionConditionMutex);
SpinLockHolder regionLocker(&m_regionLock);
while (!m_numberOfEmptyRegions && !m_blockFreeingThreadShouldQuit) {
m_regionLock.Unlock();
m_emptyRegionCondition.wait(m_emptyRegionConditionLock);
m_emptyRegionCondition.wait(lock);
m_regionLock.Lock();
}
currentNumberOfEmptyRegions = m_numberOfEmptyRegions;
......
......@@ -29,6 +29,7 @@
#include "GCActivityCallback.h"
#include "HeapBlock.h"
#include "Region.h"
#include <mutex>
#include <wtf/DoublyLinkedList.h>
#include <wtf/Forward.h>
#include <wtf/PageAllocationAligned.h>
......@@ -60,8 +61,7 @@ public:
template <typename T> void deallocateCustomSize(T*);
private:
void waitForRelativeTimeWhileHoldingLock(double relative);
void waitForRelativeTime(double relative);
void waitForDuration(std::chrono::milliseconds);
friend ThreadIdentifier createBlockFreeingThread(BlockAllocator*);
void blockFreeingThreadMain();
......@@ -105,8 +105,8 @@ private:
bool m_isCurrentlyAllocating;
bool m_blockFreeingThreadShouldQuit;
SpinLock m_regionLock;
Mutex m_emptyRegionConditionLock;
ThreadCondition m_emptyRegionCondition;
std::mutex m_emptyRegionConditionMutex;
std::condition_variable m_emptyRegionCondition;
ThreadIdentifier m_blockFreeingThread;
};
......@@ -199,8 +199,8 @@ inline void BlockAllocator::deallocate(T* block)
}
if (shouldWakeBlockFreeingThread) {
MutexLocker mutexLocker(m_emptyRegionConditionLock);
m_emptyRegionCondition.signal();
std::lock_guard<std::mutex> lock(m_emptyRegionConditionMutex);
m_emptyRegionCondition.notify_one();
}
if (!m_blockFreeingThread)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment