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