summaryrefslogtreecommitdiff
path: root/sd/source/ui/slidesorter/cache
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2011-06-01 10:23:59 +0100
committerCaolán McNamara <caolanm@redhat.com>2011-06-01 15:19:24 +0100
commit041fd0b068f670c59bdcf435c0839f349db27d23 (patch)
tree498811db8eb0c960ba497ee2e8835c5574bf991d /sd/source/ui/slidesorter/cache
parent44863c2f2fd78c291092037aaf0d7abfa21f773d (diff)
don't see a reason this needs to be global
Diffstat (limited to 'sd/source/ui/slidesorter/cache')
-rw-r--r--sd/source/ui/slidesorter/cache/SlsCacheConfiguration.cxx29
-rw-r--r--sd/source/ui/slidesorter/cache/SlsCacheConfiguration.hxx1
2 files changed, 18 insertions, 12 deletions
diff --git a/sd/source/ui/slidesorter/cache/SlsCacheConfiguration.cxx b/sd/source/ui/slidesorter/cache/SlsCacheConfiguration.cxx
index 2ea515126c3b..a4d3bc48be46 100644
--- a/sd/source/ui/slidesorter/cache/SlsCacheConfiguration.cxx
+++ b/sd/source/ui/slidesorter/cache/SlsCacheConfiguration.cxx
@@ -31,6 +31,7 @@
#include "SlsCacheConfiguration.hxx"
#include <osl/mutex.hxx>
+#include <rtl/instance.hxx>
#include <vcl/svapp.hxx>
#include <comphelper/processfactory.hxx>
@@ -43,33 +44,38 @@ using namespace ::com::sun::star::uno;
namespace sd { namespace slidesorter { namespace cache {
-::boost::shared_ptr<CacheConfiguration> CacheConfiguration::mpInstance;
+namespace
+{
+ typedef ::boost::shared_ptr<CacheConfiguration> CacheConfigSharedPtr;
+ class theInstance :
+ public rtl::Static<CacheConfigSharedPtr, theInstance> {};
+}
+
::boost::weak_ptr<CacheConfiguration> CacheConfiguration::mpWeakInstance;
Timer CacheConfiguration::maReleaseTimer;
-
-
::boost::shared_ptr<CacheConfiguration> CacheConfiguration::Instance (void)
{
SolarMutexGuard aSolarGuard;
- if (mpInstance.get() == NULL)
+ CacheConfigSharedPtr &rInstancePtr = theInstance::get();
+ if (rInstancePtr.get() == NULL)
{
// Maybe somebody else kept a previously created instance alive.
if ( ! mpWeakInstance.expired())
- mpInstance = ::boost::shared_ptr<CacheConfiguration>(mpWeakInstance);
- if (mpInstance.get() == NULL)
+ rInstancePtr = ::boost::shared_ptr<CacheConfiguration>(mpWeakInstance);
+ if (rInstancePtr.get() == NULL)
{
// We have to create a new instance.
- mpInstance.reset(new CacheConfiguration());
- mpWeakInstance = mpInstance;
+ rInstancePtr.reset(new CacheConfiguration());
+ mpWeakInstance = rInstancePtr;
// Prepare to release this instance in the near future.
maReleaseTimer.SetTimeoutHdl(
- LINK(mpInstance.get(),CacheConfiguration,TimerCallback));
+ LINK(rInstancePtr.get(),CacheConfiguration,TimerCallback));
maReleaseTimer.SetTimeout(5000 /* 5s */);
maReleaseTimer.Start();
}
}
- return mpInstance;
+ return rInstancePtr;
}
@@ -167,8 +173,9 @@ Any CacheConfiguration::GetValue (const ::rtl::OUString& rName)
IMPL_LINK(CacheConfiguration,TimerCallback, Timer*,EMPTYARG)
{
+ CacheConfigSharedPtr &rInstancePtr = theInstance::get();
// Release out reference to the instance.
- mpInstance.reset();
+ rInstancePtr.reset();
return 0;
}
diff --git a/sd/source/ui/slidesorter/cache/SlsCacheConfiguration.hxx b/sd/source/ui/slidesorter/cache/SlsCacheConfiguration.hxx
index 00a7ad71bdca..b6b113140e50 100644
--- a/sd/source/ui/slidesorter/cache/SlsCacheConfiguration.hxx
+++ b/sd/source/ui/slidesorter/cache/SlsCacheConfiguration.hxx
@@ -56,7 +56,6 @@ public:
::com::sun::star::uno::Any GetValue (const ::rtl::OUString& rName);
private:
- static ::boost::shared_ptr<CacheConfiguration> mpInstance;
/** When a caller holds a reference after we have released ours we use
this weak pointer to avoid creating a new instance.
*/