Run Idle tasks immediatly

There is really no reason to wait a millisecond for an idle.

Change-Id: I7665d5f2e7d6ba3e01290a692bbc8e42c36b9986
This commit is contained in:
Jan-Marek Glogowski
2016-09-14 15:33:54 +02:00
parent 503eba23c9
commit 7a1c1699a6
5 changed files with 14 additions and 21 deletions

View File

@@ -45,8 +45,8 @@ class VCL_DLLPUBLIC Scheduler final
static void ImplStartTimer ( sal_uInt64 nMS, bool bForce, sal_uInt64 nTime ); static void ImplStartTimer ( sal_uInt64 nMS, bool bForce, sal_uInt64 nTime );
public: public:
static constexpr sal_uInt64 ImmediateTimeoutMs = 1; static constexpr sal_uInt64 ImmediateTimeoutMs = 0;
static constexpr sal_uInt64 InfiniteTimeoutMs = 1000 * 60 * 60 * 24; // 1 day static constexpr sal_uInt64 InfiniteTimeoutMs = SAL_MAX_UINT64;
static void ImplDeInitScheduler(); static void ImplDeInitScheduler();

View File

@@ -51,7 +51,7 @@ class ImplSchedulerDataPrinter(object):
if (task_type == "Timer"): if (task_type == "Timer"):
res = "{}: {}ms".format(res, timer['mnTimeout']) res = "{}: {}ms".format(res, timer['mnTimeout'])
else: else:
assert 1 == timer['mnTimeout'], "Idle with timeout == {}".format( timer['mnTimeout'] ) assert 0 == timer['mnTimeout'], "Idle with timeout == {}".format( timer['mnTimeout'] )
return res return res
else: else:
assert gdbobj['mbDelete'], "No task set and not marked for deletion!" assert gdbobj['mbDelete'], "No task set and not marked for deletion!"

View File

@@ -19,6 +19,7 @@
#include <vcl/timer.hxx> #include <vcl/timer.hxx>
#include <vcl/idle.hxx> #include <vcl/idle.hxx>
#include <vcl/svapp.hxx> #include <vcl/svapp.hxx>
#include <vcl/scheduler.hxx>
#include "svdata.hxx" #include "svdata.hxx"
#include "salinst.hxx" #include "salinst.hxx"
@@ -125,7 +126,7 @@ void TimerTest::testIdle()
{ {
bool bTriggered = false; bool bTriggered = false;
IdleBool aTest( bTriggered ); IdleBool aTest( bTriggered );
while ( Application::Reschedule() ); Scheduler::ProcessEventsToIdle();
CPPUNIT_ASSERT_MESSAGE("idle triggered", bTriggered); CPPUNIT_ASSERT_MESSAGE("idle triggered", bTriggered);
} }
@@ -438,7 +439,7 @@ void TimerTest::testInvokedReStart()
{ {
sal_Int32 nCount = 0; sal_Int32 nCount = 0;
IdleInvokedReStart aIdle( nCount ); IdleInvokedReStart aIdle( nCount );
while ( Application::Reschedule() ); Scheduler::ProcessEventsToIdle();
CPPUNIT_ASSERT_EQUAL( nCount, sal_Int32(2) ); CPPUNIT_ASSERT_EQUAL( nCount, sal_Int32(2) );
} }
@@ -473,7 +474,7 @@ void TimerTest::testPriority()
aLowPrioIdle.SetPriority( TaskPriority::LOWEST ); aLowPrioIdle.SetPriority( TaskPriority::LOWEST );
IdleSerializer aHighPrioIdle( "IdleSerializer HighPrio", 1, nProcessed ); IdleSerializer aHighPrioIdle( "IdleSerializer HighPrio", 1, nProcessed );
aHighPrioIdle.SetPriority( TaskPriority::HIGHEST ); aHighPrioIdle.SetPriority( TaskPriority::HIGHEST );
while ( Application::Reschedule() ); Scheduler::ProcessEventsToIdle();
CPPUNIT_ASSERT_EQUAL_MESSAGE( "Not all idles processed", sal_uInt32(2), nProcessed ); CPPUNIT_ASSERT_EQUAL_MESSAGE( "Not all idles processed", sal_uInt32(2), nProcessed );
} }
@@ -484,7 +485,7 @@ void TimerTest::testPriority()
aHighPrioIdle.SetPriority( TaskPriority::HIGHEST ); aHighPrioIdle.SetPriority( TaskPriority::HIGHEST );
IdleSerializer aLowPrioIdle( "IdleSerializer LowPrio", 2, nProcessed ); IdleSerializer aLowPrioIdle( "IdleSerializer LowPrio", 2, nProcessed );
aLowPrioIdle.SetPriority( TaskPriority::LOWEST ); aLowPrioIdle.SetPriority( TaskPriority::LOWEST );
while ( Application::Reschedule() ); Scheduler::ProcessEventsToIdle();
CPPUNIT_ASSERT_EQUAL_MESSAGE( "Not all idles processed", sal_uInt32(2), nProcessed ); CPPUNIT_ASSERT_EQUAL_MESSAGE( "Not all idles processed", sal_uInt32(2), nProcessed );
} }
} }

View File

@@ -139,10 +139,6 @@ void Scheduler::ImplStartTimer(sal_uInt64 nMS, bool bForce, sal_uInt64 nTime)
rSchedCtx.mpSalTimer->SetCallback(Scheduler::CallbackTaskScheduling); rSchedCtx.mpSalTimer->SetCallback(Scheduler::CallbackTaskScheduling);
} }
if ( nMS > InfiniteTimeoutMs )
nMS = InfiniteTimeoutMs;
if ( nMS < ImmediateTimeoutMs )
nMS = ImmediateTimeoutMs;
assert(SAL_MAX_UINT64 - nMS >= nTime); assert(SAL_MAX_UINT64 - nMS >= nTime);
sal_uInt64 nProposedTimeout = nTime + nMS; sal_uInt64 nProposedTimeout = nTime + nMS;

View File

@@ -54,6 +54,7 @@
#if HAVE_FEATURE_OPENGL #if HAVE_FEATURE_OPENGL
#include <vcl/opengl/OpenGLWrapper.hxx> #include <vcl/opengl/OpenGLWrapper.hxx>
#endif #endif
#include <saltimer.hxx>
#include "salinst.hxx" #include "salinst.hxx"
#include "salframe.hxx" #include "salframe.hxx"
@@ -513,22 +514,17 @@ bool Application::Reschedule( bool i_bAllEvents )
void Scheduler::ProcessEventsToSignal(bool& bSignal) void Scheduler::ProcessEventsToSignal(bool& bSignal)
{ {
while(!bSignal && (Scheduler::ProcessTaskScheduling() || while (!bSignal && Application::Reschedule( false ) );
ImplYield(false, false, 0)))
{
}
} }
void Scheduler::ProcessEventsToIdle() void Scheduler::ProcessEventsToIdle()
{ {
int nSanity = 1000; int nSanity = 1;
while( Scheduler::ProcessTaskScheduling() || while( Application::Reschedule( true ) )
ImplYield(false, true, 0) )
{ {
if (nSanity-- < 0) if (0 == ++nSanity % 1000)
{ {
SAL_WARN("vcl.schedule", "Unexpected volume of events to process"); SAL_WARN("vcl.schedule", "ProcessEventsToIdle: " << nSanity);
break;
} }
} }
#if OSL_DEBUG_LEVEL > 0 #if OSL_DEBUG_LEVEL > 0