f325b2
From de66d2e73cf44d2691d7e2e4ca8df98b46b26c10 Mon Sep 17 00:00:00 2001
f325b2
From: Michael Meeks <michael.meeks@collabora.com>
f325b2
Date: Fri, 13 Nov 2015 09:56:53 +0000
f325b2
Subject: [PATCH] backport 5-1 idle/timers loop to 5-0
f325b2
f325b2
slideshow: cleanup main-loop usage, post-yield listeners, etc.
f325b2
f325b2
    This removes several attempts at reducing jitter in slideshow
f325b2
animations. Now we have high-resolution (ie. not clamped to 10ms)
f325b2
timers on Windows and a cleaner and simpler main-loop, we should
f325b2
be able to use generic timer code-paths for all of this.
f325b2
f325b2
    This also allows us to further cleanup and simplify the main-loop
f325b2
removing the now redundent post-yield handler concept. If there is a
f325b2
short enough timeout, we will take just 1ms of delay before executing
f325b2
a short timer anyway.
f325b2
f325b2
    Also removed some lingering comments from an old attempt to boost
f325b2
priorities which broken audio playback.
f325b2
f325b2
    Tested: tdf#32861 - still works, audio still plays, no new jitter
f325b2
            in animations that I tested.
f325b2
f325b2
Reviewed-on: https://gerrit.libreoffice.org/19947
f325b2
Tested-by: Jenkins <ci@libreoffice.org>
f325b2
Reviewed-by: Michael Meeks <michael.meeks@collabora.com>
f325b2
(cherry picked from commit 12dcf5e6e770b1933252a1f919663ba45ded4cdf)
f325b2
f325b2
Change-Id: Iadc5e2a48828a18a599a86a8df14cb2b75dd425e
f325b2
---
f325b2
 .../source/primitive2d/textlayoutdevice.cxx        |   5 +-
f325b2
 framework/source/services/autorecovery.cxx         |   1 +
f325b2
 include/sal/log-areas.dox                          |   1 +
f325b2
 include/vcl/idle.hxx                               |   5 +-
f325b2
 include/vcl/scheduler.hxx                          |  48 +++---
f325b2
 include/vcl/svapp.hxx                              |  74 +---------
f325b2
 include/vcl/timer.hxx                              |   9 +-
f325b2
 sd/source/ui/slideshow/slideshowimpl.cxx           |  47 +-----
f325b2
 sd/source/ui/slideshow/slideshowimpl.hxx           |   3 +-
f325b2
 toolkit/source/awt/vclxtoolkit.cxx                 |   2 +-
f325b2
 vcl/headless/svpinst.cxx                           |   7 +-
f325b2
 vcl/inc/headless/svpinst.hxx                       |   2 +-
f325b2
 vcl/inc/osx/salinst.h                              |   2 +-
f325b2
 vcl/inc/salinst.hxx                                |  13 +-
f325b2
 vcl/inc/saltimer.hxx                               |  17 +++
f325b2
 vcl/inc/svdata.hxx                                 |   4 -
f325b2
 vcl/inc/unx/gtk/gtkdata.hxx                        |   2 +-
f325b2
 vcl/inc/unx/gtk/gtkinst.hxx                        |   2 +-
f325b2
 vcl/inc/unx/saldisp.hxx                            |   4 +-
f325b2
 vcl/inc/unx/salinst.h                              |   2 +-
f325b2
 vcl/inc/win/salinst.h                              |   2 +-
f325b2
 vcl/osx/salinst.cxx                                |  13 +-
f325b2
 vcl/qa/cppunit/timer.cxx                           |   2 +-
f325b2
 vcl/source/app/idle.cxx                            |  26 ++--
f325b2
 vcl/source/app/scheduler.cxx                       | 164 +++++++++++++++------
f325b2
 vcl/source/app/svapp.cxx                           |  99 +++++++------
f325b2
 vcl/source/app/svmain.cxx                          |   5 -
f325b2
 vcl/source/app/timer.cxx                           |  84 ++++-------
f325b2
 vcl/unx/generic/app/saldata.cxx                    |  13 +-
f325b2
 vcl/unx/generic/app/saldisp.cxx                    |   9 +-
f325b2
 vcl/unx/generic/app/salinst.cxx                    |   6 +-
f325b2
 vcl/unx/gtk/a11y/atkwrapper.cxx                    |   2 +-
f325b2
 vcl/unx/gtk/app/gtkdata.cxx                        |  14 +-
f325b2
 vcl/unx/gtk/app/gtkinst.cxx                        |   6 +-
f325b2
 vcl/unx/kde4/KDESalDisplay.cxx                     |   9 +-
f325b2
 vcl/unx/kde4/KDESalDisplay.hxx                     |   2 +-
f325b2
 vcl/unx/kde4/KDEXLib.cxx                           |  16 +-
f325b2
 vcl/unx/kde4/KDEXLib.hxx                           |   4 +-
f325b2
 vcl/win/source/app/salinst.cxx                     |  19 ++-
f325b2
 39 files changed, 390 insertions(+), 355 deletions(-)
f325b2
f325b2
diff --git a/drawinglayer/source/primitive2d/textlayoutdevice.cxx b/drawinglayer/source/primitive2d/textlayoutdevice.cxx
f325b2
index 2eefc3f..99dad74 100644
f325b2
--- a/drawinglayer/source/primitive2d/textlayoutdevice.cxx
f325b2
+++ b/drawinglayer/source/primitive2d/textlayoutdevice.cxx
f325b2
@@ -72,8 +72,9 @@ namespace
f325b2
     };
f325b2
 
f325b2
     ImpTimedRefDev::ImpTimedRefDev(scoped_timed_RefDev& rOwnerOfMe)
f325b2
-    :   mrOwnerOfMe(rOwnerOfMe),
f325b2
-        mpVirDev(0L),
f325b2
+    :   Timer( "Timer to destroy drawinglayer reference device" ),
f325b2
+        mrOwnerOfMe(rOwnerOfMe),
f325b2
+        mpVirDev(nullptr),
f325b2
         mnUseCount(0L)
f325b2
     {
f325b2
         SetTimeout(3L * 60L * 1000L); // three minutes
f325b2
diff --git a/framework/source/services/autorecovery.cxx b/framework/source/services/autorecovery.cxx
f325b2
index 8b75271..36adb9b 100644
f325b2
--- a/framework/source/services/autorecovery.cxx
f325b2
+++ b/framework/source/services/autorecovery.cxx
f325b2
@@ -1261,6 +1261,7 @@ AutoRecovery::AutoRecovery(const css::uno::Reference< css::uno::XComponentContex
f325b2
     , m_bListenForConfigChanges (false                                          )
f325b2
     , m_nAutoSaveTimeIntervall  (0                                                  )
f325b2
     , m_eJob                    (AutoRecovery::E_NO_JOB                             )
f325b2
+    , m_aTimer                  ( "Auto save timer" )
f325b2
     , m_aAsyncDispatcher        ( LINK( this, AutoRecovery, implts_asyncDispatch )  )
f325b2
     , m_eTimerType              (E_DONT_START_TIMER                                 )
f325b2
     , m_nIdPool                 (0                                                  )
f325b2
diff --git a/include/sal/log-areas.dox b/include/sal/log-areas.dox
f325b2
index d734876..6cb1348 100644
f325b2
--- a/include/sal/log-areas.dox
f325b2
+++ b/include/sal/log-areas.dox
f325b2
@@ -403,6 +403,7 @@ certain functionality.
f325b2
 @li @c vcl.osx
f325b2
 @li @c vcl.osx.print
f325b2
 @li @c vcl.quartz
f325b2
+@li @c vcl.schedule - scheduler / main-loop information
f325b2
 @li @c vcl.scrollbar - Scroll Bars
f325b2
 @li @c vcl.sm - Session Manager
f325b2
 @li @c vcl.unity
f325b2
diff --git a/include/vcl/idle.hxx b/include/vcl/idle.hxx
f325b2
index 2e853b7..ba892a9 100644
f325b2
--- a/include/vcl/idle.hxx
f325b2
+++ b/include/vcl/idle.hxx
f325b2
@@ -39,8 +39,9 @@ public:
f325b2
     void            SetIdleHdl( const Link<Idle *, void>& rLink ) { maIdleHdl = rLink; }
f325b2
     const Link<Idle *, void>& GetIdleHdl() const { return maIdleHdl; }
f325b2
     virtual void Invoke() SAL_OVERRIDE;
f325b2
-    virtual bool ReadyForSchedule( bool bTimer ) SAL_OVERRIDE;
f325b2
-    virtual sal_uInt64 UpdateMinPeriod( sal_uInt64 nMinPeriod, sal_uInt64 nTime ) SAL_OVERRIDE;
f325b2
+    virtual bool ReadyForSchedule( bool bTimerOnly, sal_uInt64 nTimeNow ) const SAL_OVERRIDE;
f325b2
+    virtual bool IsIdle() const SAL_OVERRIDE;
f325b2
+    virtual sal_uInt64 UpdateMinPeriod( sal_uInt64 nMinPeriod, sal_uInt64 nTime ) const SAL_OVERRIDE;
f325b2
     Idle&           operator=( const Idle& rIdle );
f325b2
 };
f325b2
 
f325b2
diff --git a/include/vcl/scheduler.hxx b/include/vcl/scheduler.hxx
f325b2
index 973565b..d9a8678 100644
f325b2
--- a/include/vcl/scheduler.hxx
f325b2
+++ b/include/vcl/scheduler.hxx
f325b2
@@ -22,21 +22,9 @@
f325b2
 
f325b2
 #include <vcl/dllapi.h>
f325b2
 
f325b2
-struct ImplSVData;
f325b2
 class Scheduler;
f325b2
-struct ImplSchedulerData
f325b2
-{
f325b2
-    ImplSchedulerData*  mpNext;      // Pointer to the next element in list
f325b2
-    Scheduler*          mpScheduler;      // Pointer to VCL Scheduler instance
f325b2
-    bool                mbDelete;    // Destroy this scheduler?
f325b2
-    bool                mbInScheduler;    // Scheduler currently processed?
f325b2
-    sal_uInt64          mnUpdateTime;   // Last Update Time
f325b2
-    sal_uInt32          mnUpdateStack;  // Update Stack
f325b2
-
f325b2
-    void Invoke();
f325b2
-
f325b2
-    static ImplSchedulerData *GetMostImportantTask( bool bTimer );
f325b2
-};
f325b2
+struct ImplSVData;
f325b2
+struct ImplSchedulerData;
f325b2
 
f325b2
 enum class SchedulerPriority {
f325b2
     HIGHEST   = 0,
f325b2
@@ -51,23 +39,39 @@ enum class SchedulerPriority {
f325b2
 
f325b2
 class VCL_DLLPUBLIC Scheduler
f325b2
 {
f325b2
+private:
f325b2
+    static void InitSystemTimer(ImplSVData* pSVData);
f325b2
+
f325b2
 protected:
f325b2
     ImplSchedulerData*  mpSchedulerData;    /// Pointer to element in scheduler list
f325b2
     const sal_Char     *mpDebugName;        /// Useful for debugging
f325b2
     SchedulerPriority   mePriority;         /// Scheduler priority
f325b2
     bool                mbActive;           /// Currently in the scheduler
f325b2
 
f325b2
+    // These should be constexpr static, when supported.
f325b2
+    static const sal_uInt64 ImmediateTimeoutMs = 1;
f325b2
+    static const sal_uInt64 MaximumTimeoutMs = 1000 * 60; // 1 minute
f325b2
+
f325b2
+    static void ImplStartTimer(sal_uInt64 nMS, bool bForce = false);
f325b2
+
f325b2
     friend struct ImplSchedulerData;
f325b2
     virtual void SetDeletionFlags();
f325b2
-    virtual bool ReadyForSchedule( bool bTimer ) = 0;
f325b2
-    virtual sal_uInt64 UpdateMinPeriod( sal_uInt64 nMinPeriod, sal_uInt64 nTime ) = 0;
f325b2
+    /// Is this item ready to be dispatched at @nTimeNow
f325b2
+    virtual bool ReadyForSchedule( bool bTimerOnly, sal_uInt64 nTimeNow ) const = 0;
f325b2
+    /// Schedule only when other timers and events are processed
f325b2
+    virtual bool IsIdle() const = 0;
f325b2
+    /**
f325b2
+     * Adjust @nMinPeriod downwards if we want to be notified before
f325b2
+     * then, @nTimeNow is the current time.
f325b2
+     */
f325b2
+    virtual sal_uInt64 UpdateMinPeriod( sal_uInt64 nMinPeriod, sal_uInt64 nTimeNow ) const = 0;
f325b2
 
f325b2
 public:
f325b2
     Scheduler( const sal_Char *pDebugName = NULL );
f325b2
     Scheduler( const Scheduler& rScheduler );
f325b2
     virtual ~Scheduler();
f325b2
 
f325b2
-    void SetPriority( SchedulerPriority ePriority );
f325b2
+    void SetPriority(SchedulerPriority ePriority) { mePriority = ePriority; }
f325b2
     SchedulerPriority GetPriority() const { return mePriority; }
f325b2
 
f325b2
     void            SetDebugName( const sal_Char *pDebugName ) { mpDebugName = pDebugName; }
f325b2
@@ -82,13 +86,17 @@ public:
f325b2
     bool            IsActive() const { return mbActive; }
f325b2
     void            SetInActive() { mbActive = false; }
f325b2
 
f325b2
-    Scheduler&          operator=( const Scheduler& rScheduler );
f325b2
+    Scheduler&      operator=( const Scheduler& rScheduler );
f325b2
     static void ImplDeInitScheduler();
f325b2
 
f325b2
     // Process one pending Timer with highhest priority
f325b2
     static void CallbackTaskScheduling( bool ignore );
f325b2
-    /// Process one pending task ahead of time with highhest priority.
f325b2
-    static void ProcessTaskScheduling( bool bTimer );
f325b2
+    /// Calculate minimum timeout - and return its value.
f325b2
+    static sal_uInt64 CalculateMinimumTimeout( bool &bHasActiveIdles );
f325b2
+    /// Process one pending task ahead of time with highest priority.
f325b2
+    static bool       ProcessTaskScheduling( bool bTimerOnly );
f325b2
+    /// Process all events until we are idle
f325b2
+    static void       ProcessEventsToIdle();
f325b2
 };
f325b2
 
f325b2
 #endif // INCLUDED_VCL_SCHEDULER_HXX
f325b2
diff --git a/include/vcl/svapp.hxx b/include/vcl/svapp.hxx
f325b2
index 78f758c..716a987 100644
f325b2
--- a/include/vcl/svapp.hxx
f325b2
+++ b/include/vcl/svapp.hxx
f325b2
@@ -459,8 +459,6 @@ public:
f325b2
 
f325b2
      @see Quit, Reschedule, Yield, EndYield, GetSolarMutex,
f325b2
           GetMainThreadIdentifier, ReleaseSolarMutex, AcquireSolarMutex,
f325b2
-          EnableNoYieldMode, DisableNoYieldMode, AddPostYieldListener,
f325b2
-          RemovePostYieldListener
f325b2
     */
f325b2
     static void                 Execute();
f325b2
 
f325b2
@@ -468,8 +466,6 @@ public:
f325b2
 
f325b2
      @see Execute, Reschedule, Yield, EndYield, GetSolarMutex,
f325b2
           GetMainThreadIdentifier, ReleaseSolarMutex, AcquireSolarMutex,
f325b2
-          EnableNoYieldMode, DisableNoYieldMode, AddPostYieldListener,
f325b2
-          RemovePostYieldListener
f325b2
     */
f325b2
     static void                 Quit();
f325b2
 
f325b2
@@ -481,8 +477,6 @@ public:
f325b2
 
f325b2
      @see Execute, Quit, Yield, EndYield, GetSolarMutex,
f325b2
           GetMainThreadIdentifier, ReleaseSolarMutex, AcquireSolarMutex,
f325b2
-          EnableNoYieldMode, DisableNoYieldMode, AddPostYieldListener,
f325b2
-          RemovePostYieldListener
f325b2
      */
f325b2
     static void                 Reschedule( bool bAllEvents = false );
f325b2
 
f325b2
@@ -490,8 +484,6 @@ public:
f325b2
 
f325b2
      @see Execute, Quit, Reschedule, EndYield, GetSolarMutex,
f325b2
           GetMainThreadIdentifier, ReleaseSolarMutex, AcquireSolarMutex,
f325b2
-          EnableNoYieldMode, DisableNoYieldMode, AddPostYieldListener,
f325b2
-          RemovePostYieldListener
f325b2
     */
f325b2
     static void                 Yield();
f325b2
 
f325b2
@@ -499,11 +491,15 @@ public:
f325b2
 
f325b2
      @see Execute, Quit, Reschedule, Yield, GetSolarMutex,
f325b2
           GetMainThreadIdentifier, ReleaseSolarMutex, AcquireSolarMutex,
f325b2
-          EnableNoYieldMode, DisableNoYieldMode, AddPostYieldListener,
f325b2
-          RemovePostYieldListener
f325b2
     */
f325b2
     static void                 EndYield();
f325b2
 
f325b2
+    /** Acquire SolarMutex after it has been temporarily dropped completely.
f325b2
+
f325b2
+        This will Reschedule() on WNT and just acquire on other platforms.
f325b2
+    */
f325b2
+    static void                 ReAcquireSolarMutex(sal_uLong nReleased);
f325b2
+
f325b2
     /** @brief Get the Solar Mutex for this thread.
f325b2
 
f325b2
      Get the Solar Mutex that prevents other threads from accessing VCL
f325b2
@@ -513,8 +509,6 @@ public:
f325b2
 
f325b2
      @see Execute, Quit, Reschedule, Yield, EndYield,
f325b2
           GetMainThreadIdentifier, ReleaseSolarMutex, AcquireSolarMutex,
f325b2
-          EnableNoYieldMode, DisableNoYieldMode, AddPostYieldListener,
f325b2
-          RemovePostYieldListener
f325b2
     */
f325b2
     static comphelper::SolarMutex& GetSolarMutex();
f325b2
 
f325b2
@@ -524,8 +518,6 @@ public:
f325b2
 
f325b2
      @see Execute, Quit, Reschedule, Yield, EndYield, GetSolarMutex,
f325b2
           ReleaseSolarMutex, AcquireSolarMutex,
f325b2
-          EnableNoYieldMode, DisableNoYieldMode, AddPostYieldListener,
f325b2
-          RemovePostYieldListener
f325b2
     */
f325b2
     static oslThreadIdentifier  GetMainThreadIdentifier();
f325b2
 
f325b2
@@ -538,8 +530,6 @@ public:
f325b2
 
f325b2
      @see Execute, Quit, Reschedule, Yield, EndYield, GetSolarMutex,
f325b2
           GetMainThreadIdentifier, AcquireSolarMutex,
f325b2
-          EnableNoYieldMode, DisableNoYieldMode, AddPostYieldListener,
f325b2
-          RemovePostYieldListener
f325b2
     */
f325b2
     static sal_uLong            ReleaseSolarMutex();
f325b2
 
f325b2
@@ -550,59 +540,9 @@ public:
f325b2
 
f325b2
      @see Execute, Quit, Reschedule, Yield, EndYield, GetSolarMutex,
f325b2
           GetMainThreadIdentifier, ReleaseSolarMutex,
f325b2
-          EnableNoYieldMode, DisableNoYieldMode, AddPostYieldListener,
f325b2
-          RemovePostYieldListener
f325b2
     */
f325b2
     static void                 AcquireSolarMutex( sal_uLong nCount );
f325b2
 
f325b2
-    /** @brief Enables "no yield" mode
f325b2
-
f325b2
-     "No yield" mode prevents Yield() from waiting for events.
f325b2
-
f325b2
-     @remarks This was originally implemented in OOo bug 98792 to improve
f325b2
-        Impress slideshows.
f325b2
-
f325b2
-     @see DisableNoYieldMode, Execute, Quit, Reschedule, Yield, EndYield, GetSolarMutex,
f325b2
-          GetMainThreadIdentifier, ReleaseSolarMutex, AcquireSolarMutex,
f325b2
-          DisableNoYield, AddPostYieldListener, RemovePostYieldListener
f325b2
-    */
f325b2
-    static void                 EnableNoYieldMode();
f325b2
-
f325b2
-    /** @brief Disables "no yield" mode
f325b2
-
f325b2
-     "No yield" mode prevents Yield() from waiting for events.
f325b2
-
f325b2
-     @remarks This was originally implemented in OOo bug 98792 to improve
f325b2
-        Impress slideshows.
f325b2
-
f325b2
-     @see EnableNoYieldMode, Execute, Quit, Reschedule, Yield, EndYield, GetSolarMutex,
f325b2
-          GetMainThreadIdentifier, ReleaseSolarMutex, AcquireSolarMutex,
f325b2
-          EnableNoYield, AddPostYieldListener, RemovePostYieldListener
f325b2
-    */
f325b2
-
f325b2
-    static void                 DisableNoYieldMode();
f325b2
-
f325b2
-    /** Add a listener for yield events
f325b2
-
f325b2
-     @param  i_rListener     Listener to add
f325b2
-
f325b2
-     @see Execute, Quit, Reschedule, Yield, EndYield, GetSolarMutex,
f325b2
-          GetMainThreadIdentifier, ReleaseSolarMutex, AcquireSolarMutex,
f325b2
-          EnableNoYieldMode, DisableNoYieldMode, RemovePostYieldListener
f325b2
-    */
f325b2
-    static void                 AddPostYieldListener( const Link<>& i_rListener );
f325b2
-
f325b2
-    /** Remove listener for yield events
f325b2
-
f325b2
-     @param  i_rListener     Listener to remove
f325b2
-
f325b2
-     @see Execute, Quit, Reschedule, Yield, EndYield, GetSolarMutex,
f325b2
-          GetMainThreadIdentifier, ReleaseSolarMutex, AcquireSolarMutex,
f325b2
-          AddPostYieldListener, EnableNoYieldMode, DisableNoYieldMode
f325b2
-    */
f325b2
-    static void                 RemovePostYieldListener( const Link<>& i_rListener );
f325b2
-
f325b2
-
f325b2
     /** Queries whether the application is in "main", i.e. not yet in
f325b2
         the event loop
f325b2
 
f325b2
@@ -1687,7 +1627,7 @@ public:
f325b2
 
f325b2
     ~SolarMutexReleaser()
f325b2
     {
f325b2
-        Application::AcquireSolarMutex( mnReleased );
f325b2
+        Application::ReAcquireSolarMutex(mnReleased);
f325b2
     }
f325b2
 };
f325b2
 
f325b2
diff --git a/include/vcl/timer.hxx b/include/vcl/timer.hxx
f325b2
index 8835291..d3abf1f 100644
f325b2
--- a/include/vcl/timer.hxx
f325b2
+++ b/include/vcl/timer.hxx
f325b2
@@ -31,11 +31,9 @@ protected:
f325b2
     bool            mbAuto;
f325b2
 
f325b2
     virtual void SetDeletionFlags() SAL_OVERRIDE;
f325b2
-    virtual bool ReadyForSchedule( bool bTimer ) SAL_OVERRIDE;
f325b2
-    virtual sal_uInt64 UpdateMinPeriod( sal_uInt64 nMinPeriod, sal_uInt64 nTime ) SAL_OVERRIDE;
f325b2
-
f325b2
-private:
f325b2
-    static void InitSystemTimer();
f325b2
+    virtual bool ReadyForSchedule( bool bTimerOnly, sal_uInt64 nTimeNow ) const SAL_OVERRIDE;
f325b2
+    virtual bool IsIdle() const SAL_OVERRIDE;
f325b2
+    virtual sal_uInt64 UpdateMinPeriod( sal_uInt64 nMinPeriod, sal_uInt64 nTime ) const SAL_OVERRIDE;
f325b2
 
f325b2
 public:
f325b2
     Timer( const sal_Char *pDebugName = NULL );
f325b2
@@ -51,7 +49,6 @@ public:
f325b2
     void            Timeout() { Invoke(); }
f325b2
     Timer&          operator=( const Timer& rTimer );
f325b2
     virtual void    Start() SAL_OVERRIDE;
f325b2
-    static void     ImplStartTimer( ImplSVData* pSVData, sal_uInt64 nMS );
f325b2
 };
f325b2
 
f325b2
 /// An auto-timer is a multi-shot timer re-emitting itself at
f325b2
diff --git a/sd/source/ui/slideshow/slideshowimpl.cxx b/sd/source/ui/slideshow/slideshowimpl.cxx
f325b2
index bf61d37..c1e1064 100644
f325b2
--- a/sd/source/ui/slideshow/slideshowimpl.cxx
f325b2
+++ b/sd/source/ui/slideshow/slideshowimpl.cxx
f325b2
@@ -538,6 +538,8 @@ SlideshowImpl::SlideshowImpl( const Reference< XPresentation2 >& xPresentation,
f325b2
         mpOldActiveWindow = mpViewShell->GetActiveWindow();
f325b2
 
f325b2
     maUpdateTimer.SetTimeoutHdl(LINK(this, SlideshowImpl, updateHdl));
f325b2
+    // Priority must not be too high or we'll starve input handling etc.
f325b2
+    maUpdateTimer.SetPriority(SchedulerPriority::REPAINT);
f325b2
 
f325b2
     maDeactivateTimer.SetTimeoutHdl(LINK(this, SlideshowImpl, deactivateHdl));
f325b2
     maDeactivateTimer.SetTimeout( 20 );
f325b2
@@ -746,9 +748,6 @@ void SAL_CALL SlideshowImpl::disposing()
f325b2
 
f325b2
     setActiveXToolbarsVisible( true );
f325b2
 
f325b2
-    Application::DisableNoYieldMode();
f325b2
-    Application::RemovePostYieldListener(LINK(this, SlideshowImpl, PostYieldListener));
f325b2
-
f325b2
     mbDisposed = true;
f325b2
 }
f325b2
 
f325b2
@@ -1789,22 +1788,6 @@ IMPL_LINK_NOARG_TYPED(SlideshowImpl, updateHdl, Timer *, void)
f325b2
     updateSlideShow();
f325b2
 }
f325b2
 
f325b2
-IMPL_LINK_NOARG(SlideshowImpl, PostYieldListener)
f325b2
-{
f325b2
-    // prevent me from deletion when recursing (App::Reschedule does)
f325b2
-    const rtl::Reference<SlideshowImpl> this_(this);
f325b2
-
f325b2
-    Application::DisableNoYieldMode();
f325b2
-    Application::RemovePostYieldListener(LINK(this, SlideshowImpl, PostYieldListener));
f325b2
-    Application::Reschedule(true); // fix for fdo#32861 - process
f325b2
-                                   // *all* outstanding events after
f325b2
-                                   // yield is done.
f325b2
-    if (mbDisposed)
f325b2
-        return 0;
f325b2
-    Application::Reschedule(true);
f325b2
-    return updateSlideShow();
f325b2
-}
f325b2
-
f325b2
 sal_Int32 SlideshowImpl::updateSlideShow()
f325b2
 {
f325b2
     // prevent me from deletion when recursing (App::EnableYieldMode does)
f325b2
@@ -1816,26 +1799,13 @@ sal_Int32 SlideshowImpl::updateSlideShow()
f325b2
 
f325b2
     try
f325b2
     {
f325b2
-        // TODO(Q3): Evaluate under various systems and setups,
f325b2
-        // whether this is really necessary. Under WinXP and Matrox
f325b2
-        // G550, the frame rates were much more steadier with this
f325b2
-        // tweak, although.
f325b2
-
f325b2
-        // currently no solution, because this kills sound (at least on Windows)
f325b2
-
f325b2
         double fUpdate = 0.0;
f325b2
         if( !xShow->update(fUpdate) )
f325b2
             fUpdate = -1.0;
f325b2
 
f325b2
         if (mxShow.is() && (fUpdate >= 0.0))
f325b2
         {
f325b2
-            if (::basegfx::fTools::equalZero(fUpdate))
f325b2
-            {
f325b2
-                // Use post yield listener for short update intervalls.
f325b2
-                Application::EnableNoYieldMode();
f325b2
-                Application::AddPostYieldListener(LINK(this, SlideshowImpl, PostYieldListener));
f325b2
-            }
f325b2
-            else
f325b2
+            if (!::basegfx::fTools::equalZero(fUpdate))
f325b2
             {
f325b2
                 // Avoid busy loop when the previous call to update()
f325b2
                 // returns a small positive number but not 0 (which is
f325b2
@@ -1852,14 +1822,11 @@ sal_Int32 SlideshowImpl::updateSlideShow()
f325b2
                 // too high (only then conversion to milliseconds and long
f325b2
                 // integer may lead to zero value.)
f325b2
                 OSL_ASSERT(static_cast<sal_uLong>(fUpdate * 1000.0) > 0);
f325b2
-
f325b2
-                Application::DisableNoYieldMode();
f325b2
-                Application::RemovePostYieldListener(LINK(this, SlideshowImpl, PostYieldListener));
f325b2
-
f325b2
-                // Use a timer for the asynchronous callback.
f325b2
-                maUpdateTimer.SetTimeout(static_cast<sal_uLong>(fUpdate * 1000.0));
f325b2
-                maUpdateTimer.Start();
f325b2
             }
f325b2
+
f325b2
+            // Use our high resolution timers for the asynchronous callback.
f325b2
+            maUpdateTimer.SetTimeout(static_cast<sal_uLong>(fUpdate * 1000.0));
f325b2
+            maUpdateTimer.Start();
f325b2
         }
f325b2
     }
f325b2
     catch( Exception& )
f325b2
diff --git a/sd/source/ui/slideshow/slideshowimpl.hxx b/sd/source/ui/slideshow/slideshowimpl.hxx
f325b2
index 3e8f00f..f75b1b7 100644
f325b2
--- a/sd/source/ui/slideshow/slideshowimpl.hxx
f325b2
+++ b/sd/source/ui/slideshow/slideshowimpl.hxx
f325b2
@@ -275,7 +275,6 @@ private:
f325b2
     void setActiveXToolbarsVisible( bool bVisible );
f325b2
 
f325b2
     DECL_LINK_TYPED(updateHdl, Timer *, void);
f325b2
-    DECL_LINK( PostYieldListener, void* );
f325b2
     DECL_LINK_TYPED(ReadyForNextInputHdl, Timer *, void);
f325b2
     DECL_LINK( endPresentationHdl, void* );
f325b2
     DECL_LINK( ContextMenuSelectHdl, Menu * );
f325b2
@@ -311,7 +310,7 @@ private:
f325b2
     static void setAutoSaveState( bool bOn );
f325b2
     void gotoPreviousSlide (const bool bSkipAllMainSequenceEffects);
f325b2
 
f325b2
-    /** Called by PostYieldListener and updateHdl handlers this method is
f325b2
+    /** Called by our maUpdateTimer's updateHdl handler this method is
f325b2
         responsible to call the slideshow update() method and, depending on
f325b2
         its return value, wait for a certain amount of time before another
f325b2
         call to update() is scheduled.
f325b2
diff --git a/toolkit/source/awt/vclxtoolkit.cxx b/toolkit/source/awt/vclxtoolkit.cxx
f325b2
index ee1f9b8..f11e167 100644
f325b2
--- a/toolkit/source/awt/vclxtoolkit.cxx
f325b2
+++ b/toolkit/source/awt/vclxtoolkit.cxx
f325b2
@@ -1892,7 +1892,7 @@ void SAL_CALL VCLXToolkit::processEventsToIdle()
f325b2
     throw (::com::sun::star::uno::RuntimeException, std::exception)
f325b2
 {
f325b2
     SolarMutexGuard aSolarGuard;
f325b2
-    Scheduler::ProcessTaskScheduling(false);
f325b2
+    Scheduler::ProcessEventsToIdle();
f325b2
 }
f325b2
 
f325b2
 }
f325b2
diff --git a/vcl/headless/svpinst.cxx b/vcl/headless/svpinst.cxx
f325b2
index 7c94f66..39dfe25 100644
f325b2
--- a/vcl/headless/svpinst.cxx
f325b2
+++ b/vcl/headless/svpinst.cxx
f325b2
@@ -259,8 +259,10 @@ SalBitmap* SvpSalInstance::CreateSalBitmap()
f325b2
 #endif
f325b2
 }
f325b2
 
f325b2
-void SvpSalInstance::Yield( bool bWait, bool bHandleAllCurrentEvents )
f325b2
+SalYieldResult SvpSalInstance::DoYield(bool bWait, bool bHandleAllCurrentEvents, sal_uLong const nReleased)
f325b2
 {
f325b2
+    (void) nReleased;
f325b2
+    assert(nReleased == 0); // not implemented
f325b2
     // first, check for already queued events.
f325b2
 
f325b2
     // release yield mutex
f325b2
@@ -324,6 +326,9 @@ void SvpSalInstance::Yield( bool bWait, bool bHandleAllCurrentEvents )
f325b2
 
f325b2
         DoReleaseYield(nTimeoutMS);
f325b2
     }
f325b2
+
f325b2
+    return bEvent ? SalYieldResult::EVENT :
f325b2
+                    SalYieldResult::TIMEOUT;
f325b2
 }
f325b2
 
f325b2
 void SvpSalInstance::DoReleaseYield( int nTimeoutMS )
f325b2
diff --git a/vcl/inc/headless/svpinst.hxx b/vcl/inc/headless/svpinst.hxx
f325b2
index 44795d5..0d11b1d 100644
f325b2
--- a/vcl/inc/headless/svpinst.hxx
f325b2
+++ b/vcl/inc/headless/svpinst.hxx
f325b2
@@ -157,7 +157,7 @@ public:
f325b2
     // wait next event and dispatch
f325b2
     // must returned by UserEvent (SalFrame::PostEvent)
f325b2
     // and timer
f325b2
-    virtual void            Yield( bool bWait, bool bHandleAllCurrentEvents ) SAL_OVERRIDE;
f325b2
+    virtual SalYieldResult  DoYield(bool bWait, bool bHandleAllCurrentEvents, sal_uLong nReleased) SAL_OVERRIDE;
f325b2
     virtual bool            AnyInput( VclInputFlags nType ) SAL_OVERRIDE;
f325b2
 
f325b2
     // may return NULL to disable session management
f325b2
diff --git a/vcl/inc/osx/salinst.h b/vcl/inc/osx/salinst.h
f325b2
index b2d6133..9df7d02 100644
f325b2
--- a/vcl/inc/osx/salinst.h
f325b2
+++ b/vcl/inc/osx/salinst.h
f325b2
@@ -109,7 +109,7 @@ public:
f325b2
     virtual sal_uLong       ReleaseYieldMutex() SAL_OVERRIDE;
f325b2
     virtual void            AcquireYieldMutex( sal_uLong nCount ) SAL_OVERRIDE;
f325b2
     virtual bool            CheckYieldMutex() SAL_OVERRIDE;
f325b2
-    virtual void            Yield( bool bWait, bool bHandleAllCurrentEvents ) SAL_OVERRIDE;
f325b2
+    virtual +SalYieldResult DoYield(bool bWait, bool bHandleAllCurrentEvents, sal_uLong nReleased) SAL_OVERRIDE;
f325b2
     virtual bool            AnyInput( VclInputFlags nType ) SAL_OVERRIDE;
f325b2
     virtual SalMenu*        CreateMenu( bool bMenuBar, Menu* pVCLMenu ) SAL_OVERRIDE;
f325b2
     virtual void            DestroyMenu( SalMenu* ) SAL_OVERRIDE;
f325b2
diff --git a/vcl/inc/salinst.hxx b/vcl/inc/salinst.hxx
f325b2
index eb53177..f49bb4c 100644
f325b2
--- a/vcl/inc/salinst.hxx
f325b2
+++ b/vcl/inc/salinst.hxx
f325b2
@@ -58,6 +58,8 @@ struct SystemWindowData;
f325b2
 class Menu;
f325b2
 enum class VclInputFlags;
f325b2
 
f325b2
+enum SalYieldResult { EVENT, TIMEOUT };
f325b2
+
f325b2
 class VCL_PLUGIN_PUBLIC SalInstance
f325b2
 {
f325b2
 private:
f325b2
@@ -124,10 +126,13 @@ public:
f325b2
     // return true, if yield mutex is owned by this thread, else false
f325b2
     virtual bool            CheckYieldMutex() = 0;
f325b2
 
f325b2
-    // wait next event and dispatch
f325b2
-    // must returned by UserEvent (SalFrame::PostEvent)
f325b2
-    // and timer
f325b2
-    virtual void            Yield( bool bWait, bool bHandleAllCurrentEvents ) = 0;
f325b2
+    /**
f325b2
+     * Wait for the next event (if @bWait) and dispatch it,
f325b2
+     * includes posted events, and timers.
f325b2
+     * If @bHandleAllCurrentEvents - dispatch multiple posted
f325b2
+     * user events. Returns true if events needed processing.
f325b2
+     */
f325b2
+    virtual SalYieldResult  DoYield(bool bWait, bool bHandleAllCurrentEvents, sal_uLong nReleased) = 0;
f325b2
     virtual bool            AnyInput( VclInputFlags nType ) = 0;
f325b2
 
f325b2
     // menus
f325b2
diff --git a/vcl/inc/saltimer.hxx b/vcl/inc/saltimer.hxx
f325b2
index 1e1a941..3907ec1 100644
f325b2
--- a/vcl/inc/saltimer.hxx
f325b2
+++ b/vcl/inc/saltimer.hxx
f325b2
@@ -54,6 +54,23 @@ public:
f325b2
     }
f325b2
 };
f325b2
 
f325b2
+class Scheduler;
f325b2
+
f325b2
+// Internal scheduler record holding intrusive linked list pieces
f325b2
+struct ImplSchedulerData
f325b2
+{
f325b2
+    ImplSchedulerData*  mpNext;        // Pointer to the next element in list
f325b2
+    Scheduler*          mpScheduler;   // Pointer to VCL Scheduler instance
f325b2
+    bool                mbDelete;      // Destroy this scheduler?
f325b2
+    bool                mbInScheduler; // Scheduler currently processed?
f325b2
+    sal_uInt64          mnUpdateTime;  // Last Update Time
f325b2
+
f325b2
+    void Invoke();
f325b2
+
f325b2
+    const char *GetDebugName() const;
f325b2
+    static ImplSchedulerData *GetMostImportantTask( bool bTimer );
f325b2
+};
f325b2
+
f325b2
 #endif // INCLUDED_VCL_INC_SALTIMER_HXX
f325b2
 
f325b2
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
f325b2
diff --git a/vcl/inc/svdata.hxx b/vcl/inc/svdata.hxx
f325b2
index 5e3282a..99cb2e3 100644
f325b2
--- a/vcl/inc/svdata.hxx
f325b2
+++ b/vcl/inc/svdata.hxx
f325b2
@@ -125,7 +125,6 @@ struct ImplSVAppData
f325b2
     VclPtr<ImplWheelWindow> mpWheelWindow;                  // WheelWindow
f325b2
     ImplHotKey*             mpFirstHotKey;                  // HotKey-Verwaltung
f325b2
     ImplEventHook*          mpFirstEventHook;               // Event-Hooks
f325b2
-    VclEventListeners2*     mpPostYieldListeners;           // post yield listeners
f325b2
     sal_uInt64              mnLastInputTime;                // GetLastInputTime()
f325b2
     sal_uInt16              mnDispatchLevel;                // DispatchLevel
f325b2
     sal_uInt16              mnModalMode;                    // ModalMode Count
f325b2
@@ -137,8 +136,6 @@ struct ImplSVAppData
f325b2
     bool                    mbInAppExecute;                 // is Application::Execute() on stack
f325b2
     bool                    mbAppQuit;                      // is Application::Quit() called
f325b2
     bool                    mbSettingsInit;                 // true: Settings are initialized
f325b2
-    bool                    mbNoYield;                      // Application::Yield will not wait for events if the queue is empty
f325b2
-                                                            // essentially that makes it the same as Application::Reschedule
f325b2
     Application::DialogCancelMode meDialogCancel;           // true: All Dialog::Execute() calls will be terminated immediately with return false
f325b2
 
f325b2
     /** Controls whether showing any IME status window is toggled on or off.
f325b2
@@ -321,7 +318,6 @@ struct ImplSVData
f325b2
     SalSystem*              mpSalSystem;                    // SalSystem interface
f325b2
     ResMgr*                 mpResMgr;                       // SV-Resource-Manager
f325b2
     sal_uInt64              mnTimerPeriod;                  // current timer period
f325b2
-    sal_uInt32              mnUpdateStack;                  // Scheduler on stack
f325b2
     ImplSVAppData           maAppData;                      // indepen data for class Application
f325b2
     ImplSVGDIData           maGDIData;                      // indepen data for Output classes
f325b2
     ImplSVWinData           maWinData;                      // indepen data for Windows classes
f325b2
diff --git a/vcl/inc/unx/gtk/gtkdata.hxx b/vcl/inc/unx/gtk/gtkdata.hxx
f325b2
index 697fece..3a800b3 100644
f325b2
--- a/vcl/inc/unx/gtk/gtkdata.hxx
f325b2
+++ b/vcl/inc/unx/gtk/gtkdata.hxx
f325b2
@@ -115,7 +115,7 @@ public:
f325b2
     static gboolean userEventFn( gpointer data );
f325b2
 
f325b2
     void PostUserEvent();
f325b2
-    void Yield( bool bWait, bool bHandleAllCurrentEvents );
f325b2
+    SalYieldResult Yield( bool bWait, bool bHandleAllCurrentEvents );
f325b2
     inline GdkDisplay *GetGdkDisplay();
f325b2
 
f325b2
     virtual void ErrorTrapPush() SAL_OVERRIDE;
f325b2
diff --git a/vcl/inc/unx/gtk/gtkinst.hxx b/vcl/inc/unx/gtk/gtkinst.hxx
f325b2
index 28bca36..189b6900 100644
f325b2
--- a/vcl/inc/unx/gtk/gtkinst.hxx
f325b2
+++ b/vcl/inc/unx/gtk/gtkinst.hxx
f325b2
@@ -80,7 +80,7 @@ public:
f325b2
                                                      const SystemGraphicsData* ) SAL_OVERRIDE;
f325b2
     virtual SalBitmap*          CreateSalBitmap() SAL_OVERRIDE;
f325b2
 
f325b2
-    virtual void                Yield( bool bWait, bool bHandleAllCurrentEvents ) SAL_OVERRIDE;
f325b2
+    virtual SalYieldResult                DoYield(bool bWait, bool bHandleAllCurrentEvents, sal_uLong nReleased) SAL_OVERRIDE;
f325b2
     virtual bool                AnyInput( VclInputFlags nType ) SAL_OVERRIDE;
f325b2
 
f325b2
     virtual GenPspGraphics     *CreatePrintGraphics() SAL_OVERRIDE;
f325b2
diff --git a/vcl/inc/unx/saldisp.hxx b/vcl/inc/unx/saldisp.hxx
f325b2
index a304a4b..776cb64 100644
f325b2
--- a/vcl/inc/unx/saldisp.hxx
f325b2
+++ b/vcl/inc/unx/saldisp.hxx
f325b2
@@ -155,7 +155,7 @@ public:
f325b2
     virtual         ~SalXLib();
f325b2
     virtual void    Init();
f325b2
 
f325b2
-    virtual void    Yield( bool bWait, bool bHandleAllCurrentEvents );
f325b2
+    virtual SalYieldResult Yield( bool bWait, bool bHandleAllCurrentEvents );
f325b2
     virtual void    Wakeup();
f325b2
     virtual void    PostUserEvent();
f325b2
 
f325b2
@@ -382,7 +382,7 @@ public:
f325b2
     virtual ~SalX11Display();
f325b2
 
f325b2
     virtual bool        Dispatch( XEvent *pEvent ) SAL_OVERRIDE;
f325b2
-    virtual void        Yield();
f325b2
+    virtual bool        Yield();
f325b2
     virtual void        PostUserEvent() SAL_OVERRIDE;
f325b2
 
f325b2
     bool                IsEvent();
f325b2
diff --git a/vcl/inc/unx/salinst.h b/vcl/inc/unx/salinst.h
f325b2
index 381ddda..72939e8 100644
f325b2
--- a/vcl/inc/unx/salinst.h
f325b2
+++ b/vcl/inc/unx/salinst.h
f325b2
@@ -71,7 +71,7 @@ public:
f325b2
     virtual SalBitmap*          CreateSalBitmap() SAL_OVERRIDE;
f325b2
     virtual SalSession*         CreateSalSession() SAL_OVERRIDE;
f325b2
 
f325b2
-    virtual void                Yield( bool bWait, bool bHandleAllCurrentEvents ) SAL_OVERRIDE;
f325b2
+    virtual SalYieldResult                DoYield(bool bWait, bool bHandleAllCurrentEvents, sal_uLong nReleased) SAL_OVERRIDE;
f325b2
     virtual bool                AnyInput( VclInputFlags nType ) SAL_OVERRIDE;
f325b2
 
f325b2
     virtual void*               GetConnectionIdentifier( ConnectionIdentifierType& rReturnedType, int& rReturnedBytes ) SAL_OVERRIDE;
f325b2
diff --git a/vcl/inc/win/salinst.h b/vcl/inc/win/salinst.h
f325b2
index 450d07c..0c9c759 100644
f325b2
--- a/vcl/inc/win/salinst.h
f325b2
+++ b/vcl/inc/win/salinst.h
f325b2
@@ -62,7 +62,7 @@ public:
f325b2
     virtual void                AcquireYieldMutex( sal_uIntPtr nCount ) SAL_OVERRIDE;
f325b2
     virtual bool                CheckYieldMutex() SAL_OVERRIDE;
f325b2
 
f325b2
-    virtual void                Yield( bool bWait, bool bHandleAllCurrentEvents ) SAL_OVERRIDE;
f325b2
+    virtual SalYieldResult      DoYield(bool bWait, bool bHandleAllCurrentEvents, sal_uLong nReleased) SAL_OVERRIDE;
f325b2
     virtual bool                AnyInput( VclInputFlags nType ) SAL_OVERRIDE;
f325b2
     virtual SalMenu*            CreateMenu( bool bMenuBar, Menu* ) SAL_OVERRIDE;
f325b2
     virtual void                DestroyMenu( SalMenu* ) SAL_OVERRIDE;
f325b2
diff --git a/vcl/osx/salinst.cxx b/vcl/osx/salinst.cxx
f325b2
index 58a52d5..e20bbdd 100644
f325b2
--- a/vcl/osx/salinst.cxx
f325b2
+++ b/vcl/osx/salinst.cxx
f325b2
@@ -554,8 +554,11 @@ class ReleasePoolHolder
f325b2
     ~ReleasePoolHolder() { [mpPool release]; }
f325b2
 };
f325b2
 
f325b2
-void AquaSalInstance::Yield( bool bWait, bool bHandleAllCurrentEvents )
f325b2
+SalYieldResult AquaSalInstance::DoYield(bool bWait, bool bHandleAllCurrentEvents, sal_uLong const nReleased)
f325b2
 {
f325b2
+    (void) nReleased;
f325b2
+    assert(nReleased == 0); // not implemented
f325b2
+
f325b2
     // ensure that the per thread autorelease pool is top level and
f325b2
     // will therefore not be destroyed by cocoa implicitly
f325b2
     SalData::ensureThreadAutoreleasePool();
f325b2
@@ -592,12 +595,13 @@ void AquaSalInstance::Yield( bool bWait, bool bHandleAllCurrentEvents )
f325b2
             osl_setCondition( maWaitingYieldCond );
f325b2
             // return if only one event is asked for
f325b2
             if( ! bHandleAllCurrentEvents )
f325b2
-                return;
f325b2
+                return SalYieldResult::EVENT;
f325b2
         }
f325b2
     }
f325b2
 
f325b2
     // handle cocoa event queue
f325b2
-    // cocoa events mye be only handled in the thread the NSApp was created
f325b2
+    // cocoa events may be only handled in the thread the NSApp was created
f325b2
+    bool bHadEvent = false;
f325b2
     if( isNSAppThread() && mnActivePrintJobs == 0 )
f325b2
     {
f325b2
         // we need to be woken up by a cocoa-event
f325b2
@@ -607,7 +611,6 @@ void AquaSalInstance::Yield( bool bWait, bool bHandleAllCurrentEvents )
f325b2
 
f325b2
         // handle available events
f325b2
         NSEvent* pEvent = nil;
f325b2
-        bool bHadEvent = false;
f325b2
         do
f325b2
         {
f325b2
             sal_uLong nCount = ReleaseYieldMutex();
f325b2
@@ -702,6 +705,8 @@ void AquaSalInstance::Yield( bool bWait, bool bHandleAllCurrentEvents )
f325b2
             bInAppEvent = false;
f325b2
         }
f325b2
     }
f325b2
+
f325b2
+    return bHadEvent ? SalYieldResult::EVENT : SalYieldResult::TIMEOUT;
f325b2
 }
f325b2
 
f325b2
 bool AquaSalInstance::AnyInput( VclInputFlags nType )
f325b2
diff --git a/vcl/qa/cppunit/timer.cxx b/vcl/qa/cppunit/timer.cxx
f325b2
index 144d626..bac8a62 100644
f325b2
--- a/vcl/qa/cppunit/timer.cxx
f325b2
+++ b/vcl/qa/cppunit/timer.cxx
f325b2
@@ -126,7 +126,7 @@ void TimerTest::testIdleMainloop()
f325b2
         // can't test this via Application::Yield since this
f325b2
         // also processes all tasks directly via the scheduler.
f325b2
         pSVData->maAppData.mnDispatchLevel++;
f325b2
-        pSVData->mpDefInst->Yield( true, false );
f325b2
+        pSVData->mpDefInst->DoYield(true, false, 0);
f325b2
         pSVData->maAppData.mnDispatchLevel--;
f325b2
     }
f325b2
     CPPUNIT_ASSERT_MESSAGE("mainloop idle triggered", bTriggered);
f325b2
diff --git a/vcl/source/app/idle.cxx b/vcl/source/app/idle.cxx
f325b2
index 901c44e..8f475de 100644
f325b2
--- a/vcl/source/app/idle.cxx
f325b2
+++ b/vcl/source/app/idle.cxx
f325b2
@@ -18,8 +18,7 @@
f325b2
  */
f325b2
 
f325b2
 #include <vcl/idle.hxx>
f325b2
-#include <vcl/timer.hxx>
f325b2
-#include "svdata.hxx"
f325b2
+#include "saltimer.hxx"
f325b2
 
f325b2
 void Idle::Invoke()
f325b2
 {
f325b2
@@ -45,35 +44,36 @@ Idle::Idle( const Idle& rIdle ) : Scheduler(rIdle)
f325b2
 void Idle::Start()
f325b2
 {
f325b2
     Scheduler::Start();
f325b2
-    ImplSVData* pSVData = ImplGetSVData();
f325b2
-    Timer::ImplStartTimer( pSVData, 0 );
f325b2
+    Scheduler::ImplStartTimer(Scheduler::ImmediateTimeoutMs);
f325b2
 }
f325b2
 
f325b2
-bool Idle::ReadyForSchedule( bool bTimer )
f325b2
+bool Idle::ReadyForSchedule( bool bTimerOnly, sal_uInt64 /* nTimeNow */ ) const
f325b2
 {
f325b2
-    // tdf#91727 - We need to re-work this to allow only UI idle handlers
f325b2
-    //             and not timeouts to be processed in some limited scenarios
f325b2
-    (void)bTimer;
f325b2
-    return true; // !bTimer
f325b2
+    // always ready if not only looking for timers.
f325b2
+    return !bTimerOnly;
f325b2
 }
f325b2
 
f325b2
-sal_uInt64 Idle::UpdateMinPeriod( sal_uInt64 nMinPeriod, sal_uInt64 /* nTime */ )
f325b2
+bool Idle::IsIdle() const
f325b2
+{
f325b2
+    return true;
f325b2
+}
f325b2
+
f325b2
+sal_uInt64 Idle::UpdateMinPeriod( sal_uInt64 nMinPeriod, sal_uInt64 /* nTime */ ) const
f325b2
 {
f325b2
     switch (mePriority) {
f325b2
     case SchedulerPriority::HIGHEST:
f325b2
     case SchedulerPriority::HIGH:
f325b2
     case SchedulerPriority::RESIZE:
f325b2
     case SchedulerPriority::REPAINT:
f325b2
-        nMinPeriod = 1; // don't wait.
f325b2
+        nMinPeriod = ImmediateTimeoutMs; // don't wait.
f325b2
         break;
f325b2
     default:
f325b2
         // FIXME: tdf#92036 workaround, I should be 1 too - wait 5ms
f325b2
-        if (nMinPeriod > 5)
f325b2
+        if (nMinPeriod < 5)
f325b2
             nMinPeriod = 5;
f325b2
         break;
f325b2
     }
f325b2
     return nMinPeriod;
f325b2
 }
f325b2
 
f325b2
-
f325b2
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
f325b2
diff --git a/vcl/source/app/scheduler.cxx b/vcl/source/app/scheduler.cxx
f325b2
index c3cea78..dd004fb 100644
f325b2
--- a/vcl/source/app/scheduler.cxx
f325b2
+++ b/vcl/source/app/scheduler.cxx
f325b2
@@ -20,10 +20,9 @@
f325b2
 #include <svdata.hxx>
f325b2
 #include <tools/time.hxx>
f325b2
 #include <vcl/scheduler.hxx>
f325b2
-#include <vcl/timer.hxx>
f325b2
 #include <saltimer.hxx>
f325b2
-
f325b2
-#define MAX_TIMER_PERIOD    SAL_MAX_UINT64
f325b2
+#include <svdata.hxx>
f325b2
+#include <salinst.hxx>
f325b2
 
f325b2
 void ImplSchedulerData::Invoke()
f325b2
 {
f325b2
@@ -39,15 +38,17 @@ void ImplSchedulerData::Invoke()
f325b2
     mbInScheduler = false;
f325b2
 }
f325b2
 
f325b2
-ImplSchedulerData *ImplSchedulerData::GetMostImportantTask( bool bTimer )
f325b2
+ImplSchedulerData *ImplSchedulerData::GetMostImportantTask( bool bTimerOnly )
f325b2
 {
f325b2
     ImplSVData*     pSVData = ImplGetSVData();
f325b2
     ImplSchedulerData *pMostUrgent = NULL;
f325b2
 
f325b2
+    sal_uInt64 nTimeNow = tools::Time::GetSystemTicks();
f325b2
     for ( ImplSchedulerData *pSchedulerData = pSVData->mpFirstSchedulerData; pSchedulerData; pSchedulerData = pSchedulerData->mpNext )
f325b2
     {
f325b2
-        if ( !pSchedulerData->mpScheduler || pSchedulerData->mbDelete || pSchedulerData->mnUpdateStack >= pSVData->mnUpdateStack
f325b2
-            || !pSchedulerData->mpScheduler->ReadyForSchedule( bTimer ) || !pSchedulerData->mpScheduler->IsActive())
f325b2
+        if ( !pSchedulerData->mpScheduler || pSchedulerData->mbDelete ||
f325b2
+             !pSchedulerData->mpScheduler->ReadyForSchedule( bTimerOnly, nTimeNow ) ||
f325b2
+             !pSchedulerData->mpScheduler->IsActive())
f325b2
             continue;
f325b2
         if (!pMostUrgent)
f325b2
             pMostUrgent = pSchedulerData;
f325b2
@@ -94,22 +95,88 @@ void Scheduler::ImplDeInitScheduler()
f325b2
         }
f325b2
         while ( pSchedulerData );
f325b2
 
f325b2
-        pSVData->mpFirstSchedulerData   = NULL;
f325b2
-        pSVData->mnTimerPeriod      = 0;
f325b2
+        pSVData->mpFirstSchedulerData = NULL;
f325b2
+        pSVData->mnTimerPeriod = 0;
f325b2
     }
f325b2
 
f325b2
     delete pSVData->mpSalTimer;
f325b2
     pSVData->mpSalTimer = 0;
f325b2
 }
f325b2
 
f325b2
+/**
f325b2
+ * Start a new timer if we need to for @nMS duration.
f325b2
+ *
f325b2
+ * if this is longer than the existing duration we're
f325b2
+ * waiting for, do nothing - unless @bForce - which means
f325b2
+ * to reset the minimum period; used by the scheduled itself.
f325b2
+ */
f325b2
+void Scheduler::ImplStartTimer(sal_uInt64 nMS, bool bForce)
f325b2
+{
f325b2
+    ImplSVData* pSVData = ImplGetSVData();
f325b2
+    InitSystemTimer(pSVData);
f325b2
+
f325b2
+    // only if smaller timeout, to avoid skipping.
f325b2
+    if (bForce || nMS < pSVData->mnTimerPeriod)
f325b2
+    {
f325b2
+        pSVData->mnTimerPeriod = nMS;
f325b2
+        pSVData->mpSalTimer->Start(nMS);
f325b2
+    }
f325b2
+}
f325b2
+
f325b2
+/**
f325b2
+* Initialize the platform specific timer on which all the
f325b2
+* platform independent timers are built
f325b2
+*/
f325b2
+void Scheduler::InitSystemTimer(ImplSVData* pSVData)
f325b2
+{
f325b2
+    assert(pSVData != nullptr);
f325b2
+    if (!pSVData->mpSalTimer)
f325b2
+    {
f325b2
+        pSVData->mnTimerPeriod = MaximumTimeoutMs;
f325b2
+        pSVData->mpSalTimer = pSVData->mpDefInst->CreateSalTimer();
f325b2
+        pSVData->mpSalTimer->SetCallback(CallbackTaskScheduling);
f325b2
+    }
f325b2
+}
f325b2
+
f325b2
 void Scheduler::CallbackTaskScheduling(bool ignore)
f325b2
 {
f325b2
     // this function is for the saltimer callback
f325b2
     (void)ignore;
f325b2
-    Scheduler::ProcessTaskScheduling( true );
f325b2
+    Scheduler::ProcessTaskScheduling( false );
f325b2
+}
f325b2
+
f325b2
+bool Scheduler::ProcessTaskScheduling( bool bTimerOnly )
f325b2
+{
f325b2
+    ImplSchedulerData* pSchedulerData;
f325b2
+
f325b2
+    // tdf#91727 - NB. bTimerOnly is ultimately not used
f325b2
+    if ((pSchedulerData = ImplSchedulerData::GetMostImportantTask(bTimerOnly)))
f325b2
+    {
f325b2
+        SAL_INFO("vcl.schedule", "Invoke task " << pSchedulerData->GetDebugName());
f325b2
+
f325b2
+        pSchedulerData->mnUpdateTime = tools::Time::GetSystemTicks();
f325b2
+        pSchedulerData->Invoke();
f325b2
+        return true;
f325b2
+    }
f325b2
+    else
f325b2
+        return false;
f325b2
+}
f325b2
+
f325b2
+void Scheduler::ProcessEventsToIdle()
f325b2
+{
f325b2
+    // FIXME: really we should process incoming OS events too ...
f325b2
+    int nSanity = 1000;
f325b2
+    while (Scheduler::ProcessTaskScheduling(false))
f325b2
+    {
f325b2
+        if (nSanity-- < 0)
f325b2
+        {
f325b2
+            SAL_WARN("vcl.schedule", "Unexpected volume of events to process");
f325b2
+            break;
f325b2
+        }
f325b2
+    }
f325b2
 }
f325b2
 
f325b2
-void Scheduler::ProcessTaskScheduling( bool bTimer )
f325b2
+sal_uInt64 Scheduler::CalculateMinimumTimeout( bool &bHasActiveIdles )
f325b2
 {
f325b2
     // process all pending Tasks
f325b2
     // if bTimer True, only handle timer
f325b2
@@ -117,63 +184,70 @@ void Scheduler::ProcessTaskScheduling( bool bTimer )
f325b2
     ImplSchedulerData* pPrevSchedulerData = NULL;
f325b2
     ImplSVData*        pSVData = ImplGetSVData();
f325b2
     sal_uInt64         nTime = tools::Time::GetSystemTicks();
f325b2
-    sal_uInt64         nMinPeriod = MAX_TIMER_PERIOD;
f325b2
-    pSVData->mnUpdateStack++;
f325b2
-
f325b2
-    // tdf#91727 - NB. bTimer is ultimately not used
f325b2
-    if ((pSchedulerData = ImplSchedulerData::GetMostImportantTask(bTimer)))
f325b2
-    {
f325b2
-        pSchedulerData->mnUpdateTime = nTime;
f325b2
-        pSchedulerData->Invoke();
f325b2
-    }
f325b2
+    sal_uInt64         nMinPeriod = MaximumTimeoutMs;
f325b2
 
f325b2
+    SAL_INFO("vcl.schedule", "Calculating minimum timeout:");
f325b2
     pSchedulerData = pSVData->mpFirstSchedulerData;
f325b2
     while ( pSchedulerData )
f325b2
     {
f325b2
-        if( pSchedulerData->mbInScheduler )
f325b2
-        {
f325b2
-            pPrevSchedulerData = pSchedulerData;
f325b2
-            pSchedulerData = pSchedulerData->mpNext;
f325b2
-        }
f325b2
+        ImplSchedulerData *pNext = pSchedulerData->mpNext;
f325b2
+
f325b2
         // Should Task be released from scheduling?
f325b2
-        else if ( pSchedulerData->mbDelete )
f325b2
+        if ( !pSchedulerData->mbInScheduler &&
f325b2
+              pSchedulerData->mbDelete )
f325b2
         {
f325b2
             if ( pPrevSchedulerData )
f325b2
                 pPrevSchedulerData->mpNext = pSchedulerData->mpNext;
f325b2
             else
f325b2
                 pSVData->mpFirstSchedulerData = pSchedulerData->mpNext;
f325b2
             if ( pSchedulerData->mpScheduler )
f325b2
-                pSchedulerData->mpScheduler->mpSchedulerData = NULL;
f325b2
-            ImplSchedulerData* pTempSchedulerData = pSchedulerData;
f325b2
-            pSchedulerData = pSchedulerData->mpNext;
f325b2
-            delete pTempSchedulerData;
f325b2
+                pSchedulerData->mpScheduler->mpSchedulerData = nullptr;
f325b2
+            pNext = pSchedulerData->mpNext;
f325b2
+            delete pSchedulerData;
f325b2
         }
f325b2
         else
f325b2
         {
f325b2
-            pSchedulerData->mnUpdateStack = 0;
f325b2
-            nMinPeriod = pSchedulerData->mpScheduler->UpdateMinPeriod( nMinPeriod, nTime );
f325b2
+            if (!pSchedulerData->mbInScheduler)
f325b2
+            {
f325b2
+                if ( !pSchedulerData->mpScheduler->IsIdle() )
f325b2
+                {
f325b2
+                    sal_uInt64 nOldMinPeriod = nMinPeriod;
f325b2
+                    nMinPeriod = pSchedulerData->mpScheduler->UpdateMinPeriod(
f325b2
+                                                                nOldMinPeriod, nTime );
f325b2
+                    SAL_INFO("vcl.schedule", "Have active timer " <<
f325b2
+                             pSchedulerData->GetDebugName() <<
f325b2
+                             "update min period from " << nOldMinPeriod <<
f325b2
+                             " to " << nMinPeriod);
f325b2
+                }
f325b2
+                else
f325b2
+                {
f325b2
+                    SAL_INFO("vcl.schedule", "Have active idle " <<
f325b2
+                             pSchedulerData->GetDebugName());
f325b2
+                    bHasActiveIdles = true;
f325b2
+                }
f325b2
+            }
f325b2
             pPrevSchedulerData = pSchedulerData;
f325b2
-            pSchedulerData = pSchedulerData->mpNext;
f325b2
         }
f325b2
+        pSchedulerData = pNext;
f325b2
     }
f325b2
 
f325b2
-    // delete clock if no more timers available
f325b2
+    // delete clock if no more timers available,
f325b2
     if ( !pSVData->mpFirstSchedulerData )
f325b2
     {
f325b2
         if ( pSVData->mpSalTimer )
f325b2
             pSVData->mpSalTimer->Stop();
f325b2
-        pSVData->mnTimerPeriod = MAX_TIMER_PERIOD;
f325b2
+        nMinPeriod = MaximumTimeoutMs;
f325b2
+        pSVData->mnTimerPeriod = nMinPeriod;
f325b2
+        SAL_INFO("vcl.schedule", "Unusual - no more timers available - stop timer");
f325b2
     }
f325b2
     else
f325b2
     {
f325b2
-        Timer::ImplStartTimer( pSVData, nMinPeriod );
f325b2
+        Scheduler::ImplStartTimer(nMinPeriod, true);
f325b2
+        SAL_INFO("vcl.schedule", "Calculated minimum timeout as " << nMinPeriod << " and " <<
f325b2
+                 (const char *)(bHasActiveIdles ? "has active idles" : "no idles"));
f325b2
     }
f325b2
-    pSVData->mnUpdateStack--;
f325b2
-}
f325b2
 
f325b2
-void Scheduler::SetPriority( SchedulerPriority ePriority )
f325b2
-{
f325b2
-    mePriority = ePriority;
f325b2
+    return nMinPeriod;
f325b2
 }
f325b2
 
f325b2
 void Scheduler::Start()
f325b2
@@ -205,7 +279,6 @@ void Scheduler::Start()
f325b2
     }
f325b2
     mpSchedulerData->mbDelete      = false;
f325b2
     mpSchedulerData->mnUpdateTime  = tools::Time::GetSystemTicks();
f325b2
-    mpSchedulerData->mnUpdateStack = pSVData->mnUpdateStack;
f325b2
 }
f325b2
 
f325b2
 void Scheduler::Stop()
f325b2
@@ -221,7 +294,7 @@ Scheduler& Scheduler::operator=( const Scheduler& rScheduler )
f325b2
     if ( IsActive() )
f325b2
         Stop();
f325b2
 
f325b2
-    mbActive          = false;
f325b2
+    mbActive = false;
f325b2
     mePriority = rScheduler.mePriority;
f325b2
 
f325b2
     if ( rScheduler.IsActive() )
f325b2
@@ -257,3 +330,10 @@ Scheduler::~Scheduler()
f325b2
     }
f325b2
 }
f325b2
 
f325b2
+const char *ImplSchedulerData::GetDebugName() const
f325b2
+{
f325b2
+    return mpScheduler && mpScheduler->GetDebugName() ?
f325b2
+        mpScheduler->GetDebugName() : "unknown";
f325b2
+}
f325b2
+
f325b2
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
f325b2
diff --git a/vcl/source/app/svapp.cxx b/vcl/source/app/svapp.cxx
f325b2
index c261a37..302c4a7 100644
f325b2
--- a/vcl/source/app/svapp.cxx
f325b2
+++ b/vcl/source/app/svapp.cxx
f325b2
@@ -338,48 +338,86 @@ void Application::Execute()
f325b2
     pSVData->maAppData.mbInAppExecute = false;
f325b2
 }
f325b2
 
f325b2
-inline void ImplYield( bool i_bWait, bool i_bAllEvents )
f325b2
+inline void ImplYield(bool i_bWait, bool i_bAllEvents, sal_uLong const nReleased)
f325b2
 {
f325b2
     ImplSVData* pSVData = ImplGetSVData();
f325b2
 
f325b2
-    //Process all Tasks
f325b2
-    Scheduler::ProcessTaskScheduling(false);
f325b2
+    SAL_INFO("vcl.schedule", "Enter ImplYield: " << (i_bWait ? "wait" : "no wait") <<
f325b2
+             ": " << (i_bAllEvents ? "all events" : "one event") << ": " << nReleased);
f325b2
 
f325b2
+    bool bHasActiveIdles = false;
f325b2
+    sal_uInt64 nMinTimeout = 0;
f325b2
+    if (nReleased == 0) // else thread doesn't have SolarMutex so avoid race
f325b2
+        nMinTimeout = Scheduler::CalculateMinimumTimeout(bHasActiveIdles);
f325b2
+
f325b2
+    // FIXME: should use returned value as param to DoYield
f325b2
+    (void)nMinTimeout;
f325b2
+
f325b2
+    // If we have idles, don't wait for the timeout; check for events
f325b2
+    // and come back as quick as possible.
f325b2
+    if (bHasActiveIdles)
f325b2
+        i_bWait = false;
f325b2
+
f325b2
+    // TODO: there's a data race here on WNT only because ImplYield may be
f325b2
+    // called without SolarMutex; if we can get rid of LazyDelete (with VclPtr)
f325b2
+    // then the only remaining use of mnDispatchLevel is in OSX specific code
f325b2
+    // so that would effectively eliminate the race on WNT
f325b2
     pSVData->maAppData.mnDispatchLevel++;
f325b2
+
f325b2
     // do not wait for events if application was already quit; in that
f325b2
     // case only dispatch events already available
f325b2
     // do not wait for events either if the app decided that it is too busy for timers
f325b2
     // (feature added for the slideshow)
f325b2
-    pSVData->mpDefInst->Yield( i_bWait && !pSVData->maAppData.mbAppQuit && !pSVData->maAppData.mbNoYield, i_bAllEvents );
f325b2
+    SalYieldResult eResult =
f325b2
+        pSVData->mpDefInst->DoYield(
f325b2
+            i_bWait && !pSVData->maAppData.mbAppQuit,
f325b2
+            i_bAllEvents, nReleased);
f325b2
+
f325b2
+    SAL_INFO("vcl.schedule", "DoYield with " << (bHasActiveIdles ? "active idles" : "no ides") <<
f325b2
+             " returns: " << (eResult == SalYieldResult::EVENT ? "processed event" : "timeout"));
f325b2
+
f325b2
     pSVData->maAppData.mnDispatchLevel--;
f325b2
 
f325b2
     DBG_TESTSOLARMUTEX(); // must be locked on return from Yield
f325b2
 
f325b2
+    // Process all Tasks
f325b2
+    Scheduler::ProcessTaskScheduling(eResult == SalYieldResult::EVENT);
f325b2
+
f325b2
     // flush lazy deleted objects
f325b2
     if( pSVData->maAppData.mnDispatchLevel == 0 )
f325b2
         vcl::LazyDelete::flush();
f325b2
 
f325b2
-    // the system timer events will not necessarily come in non waiting mode
f325b2
-    // e.g. on OS X; need to trigger timer checks manually
f325b2
-    if( pSVData->maAppData.mbNoYield )
f325b2
-    {
f325b2
-        //Process all timers
f325b2
-        Scheduler::ProcessTaskScheduling(true);
f325b2
-    }
f325b2
-
f325b2
-    // call post yield listeners
f325b2
-    if( pSVData->maAppData.mpPostYieldListeners )
f325b2
-        pSVData->maAppData.mpPostYieldListeners->callListeners( NULL );
f325b2
+    SAL_INFO("vcl.schedule", "Leave ImplYield");
f325b2
 }
f325b2
 
f325b2
 void Application::Reschedule( bool i_bAllEvents )
f325b2
 {
f325b2
-    ImplYield( false, i_bAllEvents );
f325b2
+    ImplYield(false, i_bAllEvents, 0);
f325b2
 }
f325b2
 
f325b2
 void Application::Yield()
f325b2
 {
f325b2
-    ImplYield( true, false );
f325b2
+    ImplYield(true, false, 0);
f325b2
+}
f325b2
+
f325b2
+void Application::ReAcquireSolarMutex(sal_uLong const nReleased)
f325b2
+{
f325b2
+    // 0 would mean that events/timers will be handled without locking
f325b2
+    // SolarMutex (racy)
f325b2
+    assert(nReleased != 0);
f325b2
+#ifdef WNT
f325b2
+    if (ImplGetSVData()->mbDeInit) // do not Yield in DeInitVCL
f325b2
+        AcquireSolarMutex(nReleased);
f325b2
+    else
f325b2
+        ImplYield(false, false, nReleased);
f325b2
+#else
f325b2
+    // a) Yield is not needed on non-WNT platforms
f325b2
+    // b) some Yield implementations for X11 (e.g. kde4) make it non-obvious
f325b2
+    //    how to use nReleased
f325b2
+    // c) would require a review of what all Yield implementations do
f325b2
+    //    currently _before_ releasing SolarMutex that would run without lock
f325b2
+    AcquireSolarMutex(nReleased);
f325b2
+#endif
f325b2
 }
f325b2
 
f325b2
 IMPL_STATIC_LINK_NOARG( ImplSVAppData, ImplQuitMsg )
f325b2
@@ -965,33 +1003,6 @@ void Application::RemoveIdleHdl( const Link<>& rLink )
f325b2
         pSVData->maAppData.mpIdleMgr->RemoveIdleHdl( rLink );
f325b2
 }
f325b2
 
f325b2
-void Application::EnableNoYieldMode()
f325b2
-{
f325b2
-    ImplSVData* pSVData = ImplGetSVData();
f325b2
-    pSVData->maAppData.mbNoYield = true;
f325b2
-}
f325b2
-
f325b2
-void Application::DisableNoYieldMode()
f325b2
-{
f325b2
-    ImplSVData* pSVData = ImplGetSVData();
f325b2
-    pSVData->maAppData.mbNoYield = false;
f325b2
-}
f325b2
-
f325b2
-void Application::AddPostYieldListener( const Link<>& i_rListener )
f325b2
-{
f325b2
-    ImplSVData* pSVData = ImplGetSVData();
f325b2
-    if( ! pSVData->maAppData.mpPostYieldListeners )
f325b2
-        pSVData->maAppData.mpPostYieldListeners = new VclEventListeners2();
f325b2
-    pSVData->maAppData.mpPostYieldListeners->addListener( i_rListener );
f325b2
-}
f325b2
-
f325b2
-void Application::RemovePostYieldListener( const Link<>& i_rListener )
f325b2
-{
f325b2
-    ImplSVData* pSVData = ImplGetSVData();
f325b2
-    if( pSVData->maAppData.mpPostYieldListeners )
f325b2
-        pSVData->maAppData.mpPostYieldListeners->removeListener( i_rListener );
f325b2
-}
f325b2
-
f325b2
 WorkWindow* Application::GetAppWindow()
f325b2
 {
f325b2
     return ImplGetSVData()->maWinData.mpAppWin;
f325b2
diff --git a/vcl/source/app/svmain.cxx b/vcl/source/app/svmain.cxx
f325b2
index 72881a6..23757e8 100644
f325b2
--- a/vcl/source/app/svmain.cxx
f325b2
+++ b/vcl/source/app/svmain.cxx
f325b2
@@ -508,11 +508,6 @@ void DeInitVCL()
f325b2
         delete pSVData->maAppData.mpKeyListeners;
f325b2
         pSVData->maAppData.mpKeyListeners = NULL;
f325b2
     }
f325b2
-    if ( pSVData->maAppData.mpPostYieldListeners )
f325b2
-    {
f325b2
-        delete pSVData->maAppData.mpPostYieldListeners;
f325b2
-        pSVData->maAppData.mpPostYieldListeners = NULL;
f325b2
-    }
f325b2
 
f325b2
     if ( pSVData->maAppData.mpFirstHotKey )
f325b2
         ImplFreeHotKeyData();
f325b2
diff --git a/vcl/source/app/timer.cxx b/vcl/source/app/timer.cxx
f325b2
index 7d92283..1766d7f 100644
f325b2
--- a/vcl/source/app/timer.cxx
f325b2
+++ b/vcl/source/app/timer.cxx
f325b2
@@ -19,46 +19,30 @@
f325b2
 
f325b2
 #include <tools/time.hxx>
f325b2
 #include <vcl/timer.hxx>
f325b2
-#include <saltimer.hxx>
f325b2
-#include <svdata.hxx>
f325b2
-#include <salinst.hxx>
f325b2
+#include "saltimer.hxx"
f325b2
 
f325b2
-#define MAX_TIMER_PERIOD   SAL_MAX_UINT64
f325b2
-
f325b2
-void Timer::ImplStartTimer( ImplSVData* pSVData, sal_uInt64 nMS )
f325b2
+void Timer::SetDeletionFlags()
f325b2
 {
f325b2
-    InitSystemTimer();
f325b2
-
f325b2
-    if ( !nMS )
f325b2
-        nMS = 1;
f325b2
-
f325b2
-    // Assume underlying timers are recurring timers, if same period - just wait.
f325b2
-    if ( nMS != pSVData->mnTimerPeriod )
f325b2
+    // If no AutoTimer, then stop.
f325b2
+    if ( !mbAuto )
f325b2
     {
f325b2
-        pSVData->mnTimerPeriod = nMS;
f325b2
-        pSVData->mpSalTimer->Start( nMS );
f325b2
+        mpSchedulerData->mbDelete = true;
f325b2
+        mbActive = false;
f325b2
     }
f325b2
 }
f325b2
 
f325b2
-void Timer::SetDeletionFlags()
f325b2
+bool Timer::ReadyForSchedule( bool /* bTimerOnly */, sal_uInt64 nTimeNow ) const
f325b2
 {
f325b2
-        // if no AutoTimer than stop
f325b2
-        if ( !mbAuto )
f325b2
-        {
f325b2
-            mpSchedulerData->mbDelete = true;
f325b2
-            mbActive = false;
f325b2
-        }
f325b2
+    return (mpSchedulerData->mnUpdateTime + mnTimeout) <= nTimeNow;
f325b2
 }
f325b2
 
f325b2
-bool Timer::ReadyForSchedule( bool bTimer )
f325b2
+bool Timer::IsIdle() const
f325b2
 {
f325b2
-    (void)bTimer;
f325b2
-    return (mpSchedulerData->mnUpdateTime + mnTimeout) <= tools::Time::GetSystemTicks();
f325b2
+    return false;
f325b2
 }
f325b2
 
f325b2
-sal_uInt64 Timer::UpdateMinPeriod( sal_uInt64 nMinPeriod, sal_uInt64 nTime )
f325b2
+sal_uInt64 Timer::UpdateMinPeriod( sal_uInt64 nMinPeriod, sal_uInt64 nTime ) const
f325b2
 {
f325b2
-    sal_uInt64 nNewTime = tools::Time::GetSystemTicks();
f325b2
     sal_uInt64 nDeltaTime;
f325b2
     //determine smallest time slot
f325b2
     if( mpSchedulerData->mnUpdateTime == nTime )
f325b2
@@ -70,11 +54,11 @@ sal_uInt64 Timer::UpdateMinPeriod( sal_uInt64 nMinPeriod, sal_uInt64 nTime )
f325b2
     else
f325b2
     {
f325b2
         nDeltaTime = mpSchedulerData->mnUpdateTime + mnTimeout;
f325b2
-        if( nDeltaTime < nNewTime )
f325b2
-            nMinPeriod = 1;
f325b2
+        if( nDeltaTime < nTime )
f325b2
+            nMinPeriod = ImmediateTimeoutMs;
f325b2
         else
f325b2
         {
f325b2
-            nDeltaTime -= nNewTime;
f325b2
+            nDeltaTime -= nTime;
f325b2
             if( nDeltaTime < nMinPeriod )
f325b2
                 nMinPeriod = nDeltaTime;
f325b2
         }
f325b2
@@ -83,32 +67,19 @@ sal_uInt64 Timer::UpdateMinPeriod( sal_uInt64 nMinPeriod, sal_uInt64 nTime )
f325b2
     return nMinPeriod;
f325b2
 }
f325b2
 
f325b2
-/**
f325b2
- * Initialize the platform specific timer on which all the
f325b2
- * platform independent timers are built
f325b2
- */
f325b2
-void Timer::InitSystemTimer()
f325b2
-{
f325b2
-    ImplSVData* pSVData = ImplGetSVData();
f325b2
-    if( ! pSVData->mpSalTimer )
f325b2
-    {
f325b2
-        pSVData->mnTimerPeriod = MAX_TIMER_PERIOD;
f325b2
-        pSVData->mpSalTimer = pSVData->mpDefInst->CreateSalTimer();
f325b2
-        pSVData->mpSalTimer->SetCallback( CallbackTaskScheduling );
f325b2
-    }
f325b2
-}
f325b2
-
f325b2
-Timer::Timer(const sal_Char *pDebugName) : Scheduler(pDebugName)
f325b2
+Timer::Timer(const sal_Char *pDebugName) :
f325b2
+    Scheduler(pDebugName),
f325b2
+    mnTimeout(ImmediateTimeoutMs),
f325b2
+    mbAuto(false)
f325b2
 {
f325b2
-    mnTimeout = 1;
f325b2
-    mbAuto = false;
f325b2
     mePriority = SchedulerPriority::HIGHEST;
f325b2
 }
f325b2
 
f325b2
-Timer::Timer( const Timer& rTimer ) : Scheduler(rTimer)
f325b2
+Timer::Timer( const Timer& rTimer ) :
f325b2
+    Scheduler(rTimer),
f325b2
+    mnTimeout(rTimer.mnTimeout),
f325b2
+    mbAuto(rTimer.mbAuto)
f325b2
 {
f325b2
-    mnTimeout = rTimer.mnTimeout;
f325b2
-    mbAuto = rTimer.mbAuto;
f325b2
     maTimeoutHdl = rTimer.maTimeoutHdl;
f325b2
 }
f325b2
 
f325b2
@@ -120,21 +91,16 @@ void Timer::Invoke()
f325b2
 void Timer::Start()
f325b2
 {
f325b2
     Scheduler::Start();
f325b2
-
f325b2
-    ImplSVData* pSVData = ImplGetSVData();
f325b2
-    if ( mnTimeout < pSVData->mnTimerPeriod )
f325b2
-        Timer::ImplStartTimer( pSVData, mnTimeout );
f325b2
+    Scheduler::ImplStartTimer(mnTimeout);
f325b2
 }
f325b2
 
f325b2
 void Timer::SetTimeout( sal_uInt64 nNewTimeout )
f325b2
 {
f325b2
     mnTimeout = nNewTimeout;
f325b2
-    // if timer is active then renew clock
f325b2
+    // If timer is active, then renew clock.
f325b2
     if ( mbActive )
f325b2
     {
f325b2
-        ImplSVData* pSVData = ImplGetSVData();
f325b2
-        if ( !pSVData->mnUpdateStack && (mnTimeout < pSVData->mnTimerPeriod) )
f325b2
-            Timer::ImplStartTimer( pSVData, mnTimeout );
f325b2
+        Scheduler::ImplStartTimer(mnTimeout);
f325b2
     }
f325b2
 }
f325b2
 
f325b2
diff --git a/vcl/unx/generic/app/saldata.cxx b/vcl/unx/generic/app/saldata.cxx
f325b2
index b2212a4..ac872b7 100644
f325b2
--- a/vcl/unx/generic/app/saldata.cxx
f325b2
+++ b/vcl/unx/generic/app/saldata.cxx
f325b2
@@ -619,7 +619,8 @@ bool SalXLib::CheckTimeout( bool bExecuteTimers )
f325b2
     return bRet;
f325b2
 }
f325b2
 
f325b2
-void SalXLib::Yield( bool bWait, bool bHandleAllCurrentEvents )
f325b2
+SalYieldResult
f325b2
+SalXLib::Yield( bool bWait, bool bHandleAllCurrentEvents )
f325b2
 {
f325b2
     blockIdleTimeout = !bWait;
f325b2
     // check for timeouts here if you want to make screenshots
f325b2
@@ -642,7 +643,7 @@ void SalXLib::Yield( bool bWait, bool bHandleAllCurrentEvents )
f325b2
                 if( ! bHandleAllCurrentEvents )
f325b2
                 {
f325b2
                     blockIdleTimeout = false;
f325b2
-                    return;
f325b2
+                    return SalYieldResult::EVENT;
f325b2
                 }
f325b2
             }
f325b2
         }
f325b2
@@ -657,6 +658,8 @@ void SalXLib::Yield( bool bWait, bool bHandleAllCurrentEvents )
f325b2
     timeval  Timeout      = noyield__;
f325b2
     timeval *pTimeout     = &Timeout;
f325b2
 
f325b2
+    bool bHandledEvent = false;
f325b2
+
f325b2
     if (bWait)
f325b2
     {
f325b2
         pTimeout = 0;
f325b2
@@ -717,7 +720,7 @@ void SalXLib::Yield( bool bWait, bool bHandleAllCurrentEvents )
f325b2
         if (nFound == 0)
f325b2
         {
f325b2
             blockIdleTimeout = false;
f325b2
-            return;
f325b2
+            return SalYieldResult::TIMEOUT;
f325b2
         }
f325b2
 
f325b2
         for ( int nFD = 0; nFD < nFDs_; nFD++ )
f325b2
@@ -736,6 +739,7 @@ void SalXLib::Yield( bool bWait, bool bHandleAllCurrentEvents )
f325b2
                     for( int i = 0; pEntry->IsEventQueued() && i < nMaxEvents; i++ )
f325b2
                     {
f325b2
                         pEntry->HandleNextEvent();
f325b2
+                        bHandledEvent = true;
f325b2
                         // if a recursive call has done the job
f325b2
                         // so abort here
f325b2
                     }
f325b2
@@ -745,6 +749,9 @@ void SalXLib::Yield( bool bWait, bool bHandleAllCurrentEvents )
f325b2
         }
f325b2
     }
f325b2
     blockIdleTimeout = false;
f325b2
+
f325b2
+    return bHandledEvent ? SalYieldResult::EVENT
f325b2
+                         : SalYieldResult::TIMEOUT;
f325b2
 }
f325b2
 
f325b2
 void SalXLib::Wakeup()
f325b2
diff --git a/vcl/unx/generic/app/saldisp.cxx b/vcl/unx/generic/app/saldisp.cxx
f325b2
index ff71bc6..c039ee2 100644
f325b2
--- a/vcl/unx/generic/app/saldisp.cxx
f325b2
+++ b/vcl/unx/generic/app/saldisp.cxx
f325b2
@@ -1878,10 +1878,10 @@ bool SalX11Display::IsEvent()
f325b2
     return false;
f325b2
 }
f325b2
 
f325b2
-void SalX11Display::Yield()
f325b2
+bool SalX11Display::Yield()
f325b2
 {
f325b2
     if( DispatchInternalEvent() )
f325b2
-        return;
f325b2
+        return true;
f325b2
 
f325b2
     XEvent aEvent;
f325b2
     DBG_ASSERT( static_cast<SalYieldMutex*>(GetSalData()->m_pInstance->GetYieldMutex())->GetThreadId() ==
f325b2
@@ -1890,7 +1890,8 @@ void SalX11Display::Yield()
f325b2
 
f325b2
     XNextEvent( pDisp_, &aEvent );
f325b2
 
f325b2
-    Dispatch( &aEvent );
f325b2
+    // FIXME: under-convinced by Dispatch boolean return value vs. salframe.
f325b2
+    bool bProcessedEvent = Dispatch( &aEvent );
f325b2
 
f325b2
 #ifdef DBG_UTIL
f325b2
     if( GetX11SalData()->HasXErrorOccurred() )
f325b2
@@ -1900,6 +1901,8 @@ void SalX11Display::Yield()
f325b2
     }
f325b2
 #endif
f325b2
     GetX11SalData()->ResetXErrorOccurred();
f325b2
+
f325b2
+    return bProcessedEvent;
f325b2
 }
f325b2
 
f325b2
 bool SalX11Display::Dispatch( XEvent *pEvent )
f325b2
diff --git a/vcl/unx/generic/app/salinst.cxx b/vcl/unx/generic/app/salinst.cxx
f325b2
index 9c00f6d..7ac0789 100644
f325b2
--- a/vcl/unx/generic/app/salinst.cxx
f325b2
+++ b/vcl/unx/generic/app/salinst.cxx
f325b2
@@ -151,9 +151,11 @@ bool X11SalInstance::AnyInput(VclInputFlags nType)
f325b2
     return bRet;
f325b2
 }
f325b2
 
f325b2
-void X11SalInstance::Yield( bool bWait, bool bHandleAllCurrentEvents )
f325b2
+SalYieldResult X11SalInstance::DoYield(bool bWait, bool bHandleAllCurrentEvents, sal_uLong const nReleased)
f325b2
 {
f325b2
-    mpXLib->Yield( bWait, bHandleAllCurrentEvents );
f325b2
+    (void) nReleased;
f325b2
+    assert(nReleased == 0); // not implemented
f325b2
+    return mpXLib->Yield( bWait, bHandleAllCurrentEvents );
f325b2
 }
f325b2
 
f325b2
 void* X11SalInstance::GetConnectionIdentifier( ConnectionIdentifierType& rReturnedType,
f325b2
diff --git a/vcl/unx/gtk/a11y/atkwrapper.cxx b/vcl/unx/gtk/a11y/atkwrapper.cxx
f325b2
index 30cfa9c..006df49 100644
f325b2
--- a/vcl/unx/gtk/a11y/atkwrapper.cxx
f325b2
+++ b/vcl/unx/gtk/a11y/atkwrapper.cxx
f325b2
@@ -872,7 +872,7 @@ atk_object_wrapper_new( const ::com::sun::star::uno::Reference< ::com::sun::star
f325b2
             uno::Reference< accessibility::XAccessibleEventBroadcaster > xBroadcaster(xContext, uno::UNO_QUERY);
f325b2
             if( xBroadcaster.is() )
f325b2
                 xBroadcaster->addAccessibleEventListener( static_cast< accessibility::XAccessibleEventListener * > ( new AtkListener(pWrap) ) );
f325b2
-        else
f325b2
+            else
f325b2
                 OSL_ASSERT( false );
f325b2
         }
f325b2
 
f325b2
diff --git a/vcl/unx/gtk/app/gtkdata.cxx b/vcl/unx/gtk/app/gtkdata.cxx
f325b2
index 2d8e26c..b59b962 100644
f325b2
--- a/vcl/unx/gtk/app/gtkdata.cxx
f325b2
+++ b/vcl/unx/gtk/app/gtkdata.cxx
f325b2
@@ -566,9 +566,11 @@ void GtkData::Dispose()
f325b2
     deInitNWF();
f325b2
 }
f325b2
 
f325b2
-void GtkData::Yield( bool bWait, bool bHandleAllCurrentEvents )
f325b2
+/// Allows events to be processed, returns true if we processed an event.
f325b2
+SalYieldResult GtkData::Yield( bool bWait, bool bHandleAllCurrentEvents )
f325b2
 {
f325b2
     blockIdleTimeout = !bWait;
f325b2
+
f325b2
     /* #i33212# only enter g_main_context_iteration in one thread at any one
f325b2
      * time, else one of them potentially will never end as long as there is
f325b2
      * another thread in there. Having only one yieldin thread actually dispatch
f325b2
@@ -584,7 +586,7 @@ void GtkData::Yield( bool bWait, bool bHandleAllCurrentEvents )
f325b2
         else if( ! bWait )
f325b2
         {
f325b2
             blockIdleTimeout = false;
f325b2
-            return; // someone else is waiting already, return
f325b2
+            return SalYieldResult::TIMEOUT; // someone else is waiting already, return
f325b2
         }
f325b2
 
f325b2
         if( bDispatchThread )
f325b2
@@ -618,6 +620,9 @@ void GtkData::Yield( bool bWait, bool bHandleAllCurrentEvents )
f325b2
             osl_setCondition( m_aDispatchCondition ); // trigger non dispatch thread yields
f325b2
     }
f325b2
     blockIdleTimeout = false;
f325b2
+
f325b2
+    return bWasEvent ? SalYieldResult::EVENT
f325b2
+                     : SalYieldResult::TIMEOUT;
f325b2
 }
f325b2
 
f325b2
 void GtkData::Init()
f325b2
@@ -885,6 +890,9 @@ create_sal_gtk_timeout( GtkSalTimer *pTimer )
f325b2
                          /* unused dummy */ g_idle_remove_by_data,
f325b2
                          NULL, NULL );
f325b2
   g_source_attach( pSource, g_main_context_default() );
f325b2
+#ifdef DBG_UTIL
f325b2
+  g_source_set_name( pSource, "VCL timeout source" );
f325b2
+#endif
f325b2
 
f325b2
   sal_gtk_timeout_defer( pTSource );
f325b2
 
f325b2
@@ -917,6 +925,8 @@ bool GtkSalTimer::Expired()
f325b2
 
f325b2
 void GtkSalTimer::Start( sal_uLong nMS )
f325b2
 {
f325b2
+    // glib is not 64bit safe in this regard.
f325b2
+    assert( nMS <= G_MAXINT );
f325b2
     m_nTimeoutMS = nMS; // for restarting
f325b2
     Stop(); // FIXME: ideally re-use an existing m_pTimeout
f325b2
     m_pTimeout = create_sal_gtk_timeout( this );
f325b2
diff --git a/vcl/unx/gtk/app/gtkinst.cxx b/vcl/unx/gtk/app/gtkinst.cxx
f325b2
index 601fd21..9242b88 100644
f325b2
--- a/vcl/unx/gtk/app/gtkinst.cxx
f325b2
+++ b/vcl/unx/gtk/app/gtkinst.cxx
f325b2
@@ -401,10 +401,12 @@ void GtkInstance::RemoveTimer (SalTimer *pTimer)
f325b2
         m_aTimers.erase( it );
f325b2
 }
f325b2
 
f325b2
-void GtkInstance::Yield( bool bWait, bool bHandleAllCurrentEvents )
f325b2
+SalYieldResult GtkInstance::DoYield(bool bWait, bool bHandleAllCurrentEvents, sal_uLong const nReleased)
f325b2
 {
f325b2
+    (void) nReleased;
f325b2
+    assert(nReleased == 0); // not implemented
f325b2
     EnsureInit();
f325b2
-    GetGtkSalData()->Yield( bWait, bHandleAllCurrentEvents );
f325b2
+    return GetGtkSalData()->Yield( bWait, bHandleAllCurrentEvents );
f325b2
 }
f325b2
 
f325b2
 bool GtkInstance::IsTimerExpired()
f325b2
diff --git a/vcl/unx/kde4/KDESalDisplay.cxx b/vcl/unx/kde4/KDESalDisplay.cxx
f325b2
index 06e7b6d..42f8ebc 100644
f325b2
--- a/vcl/unx/kde4/KDESalDisplay.cxx
f325b2
+++ b/vcl/unx/kde4/KDESalDisplay.cxx
f325b2
@@ -46,14 +46,14 @@ SalKDEDisplay::~SalKDEDisplay()
f325b2
     pDisp_ = NULL;
f325b2
 }
f325b2
 
f325b2
-void SalKDEDisplay::Yield()
f325b2
+bool SalKDEDisplay::Yield()
f325b2
 {
f325b2
     if( DispatchInternalEvent() )
f325b2
-        return;
f325b2
+        return true;
f325b2
 
f325b2
     // Prevent blocking from Drag'n'Drop events, which may have already have processed the event
f325b2
     if (XEventsQueued( pDisp_, QueuedAfterReading ) == 0)
f325b2
-        return;
f325b2
+        return false;
f325b2
 
f325b2
     DBG_ASSERT( static_cast<SalYieldMutex*>(GetSalData()->m_pInstance->GetYieldMutex())->GetThreadId() ==
f325b2
                 osl::Thread::getCurrentIdentifier(),
f325b2
@@ -62,8 +62,9 @@ void SalKDEDisplay::Yield()
f325b2
     XEvent event;
f325b2
     XNextEvent( pDisp_, &event );
f325b2
     if( checkDirectInputEvent( &event ))
f325b2
-        return;
f325b2
+        return true;
f325b2
     qApp->x11ProcessEvent( &event );
f325b2
+    return true;
f325b2
 }
f325b2
 
f325b2
 // HACK: When using Qt event loop, input methods (japanese, etc.) will get broken because
f325b2
diff --git a/vcl/unx/kde4/KDESalDisplay.hxx b/vcl/unx/kde4/KDESalDisplay.hxx
f325b2
index f4a4146..3e027fd 100644
f325b2
--- a/vcl/unx/kde4/KDESalDisplay.hxx
f325b2
+++ b/vcl/unx/kde4/KDESalDisplay.hxx
f325b2
@@ -27,7 +27,7 @@ class SalKDEDisplay : public SalX11Display
f325b2
         SalKDEDisplay( Display* pDisp );
f325b2
         virtual ~SalKDEDisplay();
f325b2
         static SalKDEDisplay* self();
f325b2
-        virtual void Yield() SAL_OVERRIDE;
f325b2
+        virtual bool Yield() SAL_OVERRIDE;
f325b2
         bool checkDirectInputEvent( XEvent* ev );
f325b2
     private:
f325b2
         Atom xim_protocol;
f325b2
diff --git a/vcl/unx/kde4/KDEXLib.cxx b/vcl/unx/kde4/KDEXLib.cxx
f325b2
index 3101d37..c758e18 100644
f325b2
--- a/vcl/unx/kde4/KDEXLib.cxx
f325b2
+++ b/vcl/unx/kde4/KDEXLib.cxx
f325b2
@@ -281,22 +281,25 @@ void KDEXLib::socketNotifierActivated( int fd )
f325b2
     sdata.handle( fd, sdata.data );
f325b2
 }
f325b2
 
f325b2
-void KDEXLib::Yield( bool bWait, bool bHandleAllCurrentEvents )
f325b2
+SalYieldResult KDEXLib::Yield( bool bWait, bool bHandleAllCurrentEvents )
f325b2
 {
f325b2
     if( !m_isGlibEventLoopType )
f325b2
     {
f325b2
+        bool wasEvent = false;
f325b2
         if( qApp->thread() == QThread::currentThread())
f325b2
         {
f325b2
             // even if we use the LO event loop, still process Qt's events,
f325b2
             // otherwise they can remain unhandled for quite a long while
f325b2
-            processYield( false, bHandleAllCurrentEvents );
f325b2
+            wasEvent = processYield( false, bHandleAllCurrentEvents );
f325b2
         }
f325b2
-        return SalXLib::Yield( bWait, bHandleAllCurrentEvents );
f325b2
+        SalYieldResult aResult = SalXLib::Yield(bWait, bHandleAllCurrentEvents);
f325b2
+        return (aResult == SalYieldResult::EVENT || wasEvent) ?
f325b2
+            SalYieldResult::EVENT : SalYieldResult::TIMEOUT;
f325b2
     }
f325b2
     // if we are the main thread (which is where the event processing is done),
f325b2
     // good, just do it
f325b2
     if( qApp->thread() == QThread::currentThread())
f325b2
-        processYield( bWait, bHandleAllCurrentEvents );
f325b2
+        return processYield( bWait, bHandleAllCurrentEvents );
f325b2
     else
f325b2
     {
f325b2
         // we were called from another thread;
f325b2
@@ -305,10 +308,11 @@ void KDEXLib::Yield( bool bWait, bool bHandleAllCurrentEvents )
f325b2
         // temporarily do it while checking for new events)
f325b2
         SalYieldMutexReleaser aReleaser;
f325b2
         Q_EMIT processYieldSignal( bWait, bHandleAllCurrentEvents );
f325b2
+        return SalYieldResult::TIMEOUT;
f325b2
     }
f325b2
 }
f325b2
 
f325b2
-void KDEXLib::processYield( bool bWait, bool bHandleAllCurrentEvents )
f325b2
+SalYieldResult KDEXLib::processYield( bool bWait, bool bHandleAllCurrentEvents )
f325b2
 {
f325b2
     blockIdleTimeout = !bWait;
f325b2
     QAbstractEventDispatcher* dispatcher = QAbstractEventDispatcher::instance( qApp->thread());
f325b2
@@ -324,6 +328,8 @@ void KDEXLib::processYield( bool bWait, bool bHandleAllCurrentEvents )
f325b2
     if( bWait && !wasEvent )
f325b2
         dispatcher->processEvents( QEventLoop::WaitForMoreEvents );
f325b2
     blockIdleTimeout = false;
f325b2
+    return wasEvent ? SalYieldResult::EVENT
f325b2
+                    : SalYieldResult::TIMEOUT;
f325b2
 }
f325b2
 
f325b2
 void KDEXLib::StartTimer( sal_uLong nMS )
f325b2
diff --git a/vcl/unx/kde4/KDEXLib.hxx b/vcl/unx/kde4/KDEXLib.hxx
f325b2
index 0a1aec3..7e432e5 100644
f325b2
--- a/vcl/unx/kde4/KDEXLib.hxx
f325b2
+++ b/vcl/unx/kde4/KDEXLib.hxx
f325b2
@@ -65,7 +65,7 @@ class KDEXLib : public QObject, public SalXLib
f325b2
         void userEventActivated();
f325b2
         void startTimeoutTimer();
f325b2
         void startUserEventTimer();
f325b2
-        void processYield( bool bWait, bool bHandleAllCurrentEvents );
f325b2
+        SalYieldResult processYield( bool bWait, bool bHandleAllCurrentEvents );
f325b2
     Q_SIGNALS:
f325b2
         void startTimeoutTimerSignal();
f325b2
         void startUserEventTimerSignal();
f325b2
@@ -80,7 +80,7 @@ class KDEXLib : public QObject, public SalXLib
f325b2
         virtual ~KDEXLib();
f325b2
 
f325b2
         virtual void Init() SAL_OVERRIDE;
f325b2
-        virtual void Yield( bool bWait, bool bHandleAllCurrentEvents ) SAL_OVERRIDE;
f325b2
+        virtual SalYieldResult Yield( bool bWait, bool bHandleAllCurrentEvents ) SAL_OVERRIDE;
f325b2
         virtual void Insert( int fd, void* data, YieldFunc pending, YieldFunc queued, YieldFunc handle ) SAL_OVERRIDE;
f325b2
         virtual void Remove( int fd ) SAL_OVERRIDE;
f325b2
         virtual void StartTimer( sal_uLong nMS ) SAL_OVERRIDE;
f325b2
diff --git a/vcl/win/source/app/salinst.cxx b/vcl/win/source/app/salinst.cxx
f325b2
index 1c21246..d61060f 100644
f325b2
--- a/vcl/win/source/app/salinst.cxx
f325b2
+++ b/vcl/win/source/app/salinst.cxx
f325b2
@@ -602,7 +602,8 @@ static void ImplSalDispatchMessage( MSG* pMsg )
f325b2
         ImplSalPostDispatchMsg( pMsg, lResult );
f325b2
 }
f325b2
 
f325b2
-void ImplSalYield( bool bWait, bool bHandleAllCurrentEvents )
f325b2
+SalYieldResult
f325b2
+ImplSalYield( bool bWait, bool bHandleAllCurrentEvents )
f325b2
 {
f325b2
     MSG aMsg;
f325b2
     bool bWasMsg = false, bOneEvent = false;
f325b2
@@ -629,15 +630,22 @@ void ImplSalYield( bool bWait, bool bHandleAllCurrentEvents )
f325b2
             ImplSalDispatchMessage( &aMsg );
f325b2
         }
f325b2
     }
f325b2
+    return bWasMsg ? SalYieldResult::EVENT :
f325b2
+                     SalYieldResult::TIMEOUT;
f325b2
 }
f325b2
 
f325b2
-void WinSalInstance::Yield( bool bWait, bool bHandleAllCurrentEvents )
f325b2
+SalYieldResult WinSalInstance::DoYield(bool bWait, bool bHandleAllCurrentEvents, sal_uLong const nReleased)
f325b2
 {
f325b2
+    SalYieldResult eDidWork = SalYieldResult::TIMEOUT;
f325b2
+    // NOTE: if nReleased != 0 this will be called without SolarMutex
f325b2
+    //       so don't do anything dangerous before releasing it here
f325b2
     SalYieldMutex*  pYieldMutex = mpSalYieldMutex;
f325b2
     SalData*        pSalData = GetSalData();
f325b2
     DWORD           nCurThreadId = GetCurrentThreadId();
f325b2
-    sal_uLong           nCount = pYieldMutex->GetAcquireCount( nCurThreadId );
f325b2
-    sal_uLong           n = nCount;
f325b2
+    sal_uLong const nCount = (nReleased != 0)
f325b2
+                                ? nReleased
f325b2
+                                : pYieldMutex->GetAcquireCount(nCurThreadId);
f325b2
+    sal_uLong       n = (nReleased != 0) ? 0 : nCount;
f325b2
     while ( n )
f325b2
     {
f325b2
         pYieldMutex->release();
f325b2
@@ -669,7 +677,7 @@ void WinSalInstance::Yield( bool bWait, bool bHandleAllCurrentEvents )
f325b2
     }
f325b2
     else
f325b2
     {
f325b2
-        ImplSalYield( bWait, bHandleAllCurrentEvents );
f325b2
+        eDidWork = ImplSalYield( bWait, bHandleAllCurrentEvents );
f325b2
 
f325b2
         n = nCount;
f325b2
         while ( n )
f325b2
@@ -678,6 +686,7 @@ void WinSalInstance::Yield( bool bWait, bool bHandleAllCurrentEvents )
f325b2
             n--;
f325b2
         }
f325b2
     }
f325b2
+    return eDidWork;
f325b2
 }
f325b2
 
f325b2
 LRESULT CALLBACK SalComWndProc( HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam, int& rDef )
f325b2
-- 
f325b2
2.5.0
f325b2