diff --git a/Source/bmalloc/bmalloc/Scavenger.cpp b/Source/bmalloc/bmalloc/Scavenger.cpp index 86dbb864ea77..c5a4ecd7290c 100644 --- a/Source/bmalloc/bmalloc/Scavenger.cpp +++ b/Source/bmalloc/bmalloc/Scavenger.cpp @@ -312,7 +312,7 @@ void Scavenger::threadRunLoop() // We require any state change while we are sleeping to signal to our // condition variable and wake us up. - while (true) { + while (!m_exiting) { if (m_state == State::Sleep) { UniqueLockHolder lock(mutex()); m_condition.wait(lock, [&]() { return m_state != State::Sleep; }); @@ -323,6 +323,9 @@ void Scavenger::threadRunLoop() m_condition.wait_for(lock, m_waitTime, [&]() { return m_state != State::RunSoon; }); } + if (m_exiting) + return; + m_state = State::Sleep; setSelfQOSClass(); @@ -379,6 +382,13 @@ void Scavenger::setSelfQOSClass() #endif } +Scavenger::~Scavenger() +{ + m_exiting = true; + run(); + m_thread.join(); +} + } // namespace bmalloc #endif diff --git a/Source/bmalloc/bmalloc/Scavenger.h b/Source/bmalloc/bmalloc/Scavenger.h index 5ed2d3f1803b..faaf112d7aca 100644 --- a/Source/bmalloc/bmalloc/Scavenger.h +++ b/Source/bmalloc/bmalloc/Scavenger.h @@ -46,7 +46,7 @@ class Scavenger : public StaticPerProcess { public: BEXPORT Scavenger(const LockHolder&); - ~Scavenger() = delete; + ~Scavenger(); void scavenge(); @@ -86,8 +86,8 @@ private: void scheduleIfUnderMemoryPressure(const LockHolder&, size_t bytes); - BNO_RETURN static void threadEntryPoint(Scavenger*); - BNO_RETURN void threadRunLoop(); + static void threadEntryPoint(Scavenger*); + void threadRunLoop(); void setSelfQOSClass(); void setThreadName(const char*); @@ -95,6 +95,7 @@ private: std::chrono::milliseconds timeSinceLastFullScavenge(); std::atomic m_state { State::Sleep }; + bool m_exiting { false }; size_t m_scavengerBytes { 0 }; std::chrono::milliseconds m_waitTime; bool m_isInMiniMode { false };