Kaydet (Commit) 017f2507 authored tarafından Stephan Bergmann's avatar Stephan Bergmann

Ensure WakeUpThread is joined before exit

Change-Id: If50fe94875b29043c75b581bf39ca9deea59dbe3
üst deaed8af
......@@ -173,7 +173,7 @@ class StatusIndicatorFactory : public ::cppu::WeakImplHelper4<
/** Notify us if a fix time is over. We use it to implement an
intelligent "Reschedule" ... */
WakeUpThread* m_pWakeUp;
rtl::Reference<WakeUpThread> m_pWakeUp;
/** Our WakeUpThread calls us in our interface method "XUpdatable::update().
There we set this member m_bAllowReschedule to sal_True. Next time if our impl_reschedule()
......
......@@ -20,57 +20,38 @@
#ifndef INCLUDED_FRAMEWORK_INC_HELPER_WAKEUPTHREAD_HXX
#define INCLUDED_FRAMEWORK_INC_HELPER_WAKEUPTHREAD_HXX
// include files of own module
#include <sal/config.h>
#include <macros/generic.hxx>
#include <general.h>
// include UNO interfaces
#include <com/sun/star/util/XUpdatable.hpp>
// include all others
#include <com/sun/star/uno/Reference.hxx>
#include <cppuhelper/weakref.hxx>
#include <osl/thread.hxx>
#include <osl/conditn.hxx>
#include <osl/mutex.hxx>
#include <sal/types.h>
#include <salhelper/thread.hxx>
namespace framework{
/** @short implements a "sleeping" thread, which try to sleep
without a using cpu consumption :-) */
class WakeUpThread : public ::osl::Thread
{
namespace com { namespace sun { namespace star { namespace util {
class XUpdatable;
} } } }
// member
private:
/** @short this listener will be notified if this thread
waked up. */
css::uno::WeakReference< css::util::XUpdatable > m_xListener;
namespace framework{
// interface
public:
class WakeUpThread: public salhelper::Thread {
css::uno::WeakReference<css::util::XUpdatable> updatable_;
osl::Condition condition_;
/** @short Register a new listener on this thread.
osl::Mutex mutex_;
bool terminate_;
@descr The listener is holded as a weak reference.
If the thread detects, that no listener exists ...
he will terminate itself.
*/
WakeUpThread(const css::uno::Reference< css::util::XUpdatable >& xListener);
void execute() SAL_OVERRIDE;
/** @descr The thread waits on a condition using a fix timeout value.
If the thread wakes up he notify the internal set listener.
The listener can use this "timeout" info for it's own purpose.
The thread itself will wait on the condition again.
*/
virtual void SAL_CALL run() SAL_OVERRIDE;
public:
WakeUpThread(css::uno::Reference<css::util::XUpdatable> const & updatable);
virtual void SAL_CALL onTerminated() SAL_OVERRIDE;
void stop();
};
} // namespace framework
}
#endif // INCLUDED_FRAMEWORK_INC_HELPER_WAKEUPTHREAD_HXX
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -55,7 +55,6 @@ const char PROGRESS_RESOURCE[] = "private:resource/progressbar/progressbar";
StatusIndicatorFactory::StatusIndicatorFactory(const css::uno::Reference< css::uno::XComponentContext >& xContext)
: m_xContext (xContext )
, m_pWakeUp (0 )
, m_bAllowReschedule (false)
, m_bAllowParentShow (false)
, m_bDisableReschedule(false)
......@@ -542,21 +541,18 @@ void StatusIndicatorFactory::impl_startWakeUpThread()
if (m_bDisableReschedule)
return;
if (!m_pWakeUp)
if (!m_pWakeUp.is())
{
m_pWakeUp = new WakeUpThread(this);
m_pWakeUp->create();
}
}
void StatusIndicatorFactory::impl_stopWakeUpThread()
{
osl::MutexGuard g(m_mutex);
if (m_pWakeUp)
if (m_pWakeUp.is())
{
// Thread kill itself after terminate()!
m_pWakeUp->terminate();
m_pWakeUp = 0;
m_pWakeUp->stop();
}
}
......
......@@ -19,44 +19,41 @@
#include <sal/config.h>
#include <osl/conditn.hxx>
#include <com/sun/star/uno/Reference.hxx>
#include <com/sun/star/util/XUpdatable.hpp>
#include <osl/mutex.hxx>
#include <osl/time.h>
// include files of own module
#include <helper/wakeupthread.hxx>
namespace framework{
WakeUpThread::WakeUpThread(const css::uno::Reference< css::util::XUpdatable >& xListener)
: m_xListener (xListener)
{
void framework::WakeUpThread::execute() {
for (;;) {
TimeValue t{0, 25000000}; // 25 msec
condition_.wait(&t);
{
osl::MutexGuard g(mutex_);
if (terminate_) {
break;
}
}
css::uno::Reference<css::util::XUpdatable> up(updatable_);
if (up.is()) {
up->update();
}
}
}
void SAL_CALL WakeUpThread::run()
{
osl_setThreadName("framework::WakeUpThread");
::osl::Condition aSleeper;
TimeValue aTime;
aTime.Seconds = 0;
aTime.Nanosec = 25000000; // 25 msec
framework::WakeUpThread::WakeUpThread(
css::uno::Reference<css::util::XUpdatable> const & updatable):
Thread("WakeUpThread"), updatable_(updatable), terminate_(false)
{}
while(schedule())
void framework::WakeUpThread::stop() {
{
aSleeper.reset();
aSleeper.wait(&aTime);
css::uno::Reference< css::util::XUpdatable > xListener(m_xListener);
if (xListener.is())
xListener->update();
osl::MutexGuard g(mutex_);
terminate_ = true;
}
join();
}
void SAL_CALL WakeUpThread::onTerminated()
{
delete this;
}
} // namespace framework
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
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