[Libreoffice-commits] core.git: framework/inc framework/source

Stephan Bergmann sbergman at redhat.com
Wed Apr 22 05:10:40 PDT 2015


 framework/inc/helper/statusindicatorfactory.hxx    |    2 
 framework/inc/helper/wakeupthread.hxx              |   61 +++++++--------------
 framework/source/helper/statusindicatorfactory.cxx |   10 +--
 framework/source/helper/wakeupthread.cxx           |   57 +++++++++----------
 4 files changed, 52 insertions(+), 78 deletions(-)

New commits:
commit 017f250764ec7b4ecb82ac19f5b3f68cadf1bf56
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Wed Apr 22 14:06:37 2015 +0200

    Ensure WakeUpThread is joined before exit
    
    Change-Id: If50fe94875b29043c75b581bf39ca9deea59dbe3

diff --git a/framework/inc/helper/statusindicatorfactory.hxx b/framework/inc/helper/statusindicatorfactory.hxx
index 328e713..7e6981f 100644
--- a/framework/inc/helper/statusindicatorfactory.hxx
+++ b/framework/inc/helper/statusindicatorfactory.hxx
@@ -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()
diff --git a/framework/inc/helper/wakeupthread.hxx b/framework/inc/helper/wakeupthread.hxx
index b2f1cb1..cc4947c 100644
--- a/framework/inc/helper/wakeupthread.hxx
+++ b/framework/inc/helper/wakeupthread.hxx
@@ -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: */
diff --git a/framework/source/helper/statusindicatorfactory.cxx b/framework/source/helper/statusindicatorfactory.cxx
index c0ed698..64a5e7d 100644
--- a/framework/source/helper/statusindicatorfactory.cxx
+++ b/framework/source/helper/statusindicatorfactory.cxx
@@ -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();
     }
 }
 
diff --git a/framework/source/helper/wakeupthread.cxx b/framework/source/helper/wakeupthread.cxx
index c048ca5..b136212 100644
--- a/framework/source/helper/wakeupthread.cxx
+++ b/framework/source/helper/wakeupthread.cxx
@@ -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: */


More information about the Libreoffice-commits mailing list