diff options
-rw-r--r-- | vcl/inc/graphic/Manager.hxx | 2 | ||||
-rw-r--r-- | vcl/source/graphic/Manager.cxx | 15 |
2 files changed, 17 insertions, 0 deletions
diff --git a/vcl/inc/graphic/Manager.hxx b/vcl/inc/graphic/Manager.hxx index f6f24b47db6f..1f897ecf7146 100644 --- a/vcl/inc/graphic/Manager.hxx +++ b/vcl/inc/graphic/Manager.hxx @@ -23,6 +23,7 @@ #include <unotools/configmgr.hxx> #include <memory> +#include <mutex> #include <chrono> #include <unordered_set> @@ -35,6 +36,7 @@ namespace graphic class Manager final { private: + std::recursive_mutex maMutex; // instead of SolarMutex because graphics can live past vcl main std::unordered_set<ImpGraphic*> m_pImpGraphicList; std::chrono::seconds mnAllowedIdleTime; sal_Int64 mnMemoryLimit; diff --git a/vcl/source/graphic/Manager.cxx b/vcl/source/graphic/Manager.cxx index 405aa8928649..fe80fdf5aaa4 100644 --- a/vcl/source/graphic/Manager.cxx +++ b/vcl/source/graphic/Manager.cxx @@ -20,6 +20,7 @@ #include <graphic/Manager.hxx> #include <impgraph.hxx> #include <vcl/lazydelete.hxx> +#include <vcl/svapp.hxx> #include <sal/log.hxx> using namespace css; @@ -72,6 +73,8 @@ Manager::Manager() void Manager::reduceGraphicMemory() { + std::lock_guard<std::recursive_mutex> aGuard(maMutex); + for (ImpGraphic* pEachImpGraphic : m_pImpGraphicList) { if (mnUsedSize < mnMemoryLimit * 0.7) @@ -102,6 +105,8 @@ sal_Int64 Manager::getGraphicSizeBytes(const ImpGraphic* pImpGraphic) IMPL_LINK(Manager, SwapOutTimerHandler, Timer*, pTimer, void) { + std::lock_guard<std::recursive_mutex> aGuard(maMutex); + pTimer->Stop(); reduceGraphicMemory(); pTimer->Start(); @@ -110,6 +115,8 @@ IMPL_LINK(Manager, SwapOutTimerHandler, Timer*, pTimer, void) void Manager::registerGraphic(const std::shared_ptr<ImpGraphic>& pImpGraphic, OUString const& /*rsContext*/) { + std::lock_guard<std::recursive_mutex> aGuard(maMutex); + // make some space first if (mnUsedSize > mnMemoryLimit) reduceGraphicMemory(); @@ -139,6 +146,8 @@ void Manager::registerGraphic(const std::shared_ptr<ImpGraphic>& pImpGraphic, void Manager::unregisterGraphic(ImpGraphic* pImpGraphic) { + std::lock_guard<std::recursive_mutex> aGuard(maMutex); + mnUsedSize -= getGraphicSizeBytes(pImpGraphic); m_pImpGraphicList.erase(pImpGraphic); } @@ -201,16 +210,22 @@ std::shared_ptr<ImpGraphic> Manager::newInstance(const GraphicExternalLink& rGra void Manager::swappedIn(const ImpGraphic* pImpGraphic) { + std::lock_guard<std::recursive_mutex> aGuard(maMutex); + mnUsedSize += getGraphicSizeBytes(pImpGraphic); } void Manager::swappedOut(const ImpGraphic* pImpGraphic) { + std::lock_guard<std::recursive_mutex> aGuard(maMutex); + mnUsedSize -= getGraphicSizeBytes(pImpGraphic); } void Manager::changeExisting(const ImpGraphic* pImpGraphic, sal_Int64 nOldSizeBytes) { + std::lock_guard<std::recursive_mutex> aGuard(maMutex); + mnUsedSize -= nOldSizeBytes; mnUsedSize += getGraphicSizeBytes(pImpGraphic); } |