Kaydet (Commit) d72aad21 authored tarafından Jan-Marek Glogowski's avatar Jan-Marek Glogowski

Refactor Scheduler global data

Move all Scheduler members of ImplSVData into ImplSchedulerContext
and make ImplSchedulerContext a member of ImplSVData.

Change-Id: I186bebdfb5701543595848968235b5a56b6598e9
üst c0710abf
...@@ -238,10 +238,10 @@ bool SvpSalInstance::CheckTimeout( bool bExecuteTimers ) ...@@ -238,10 +238,10 @@ bool SvpSalInstance::CheckTimeout( bool bExecuteTimers )
// notify // notify
ImplSVData* pSVData = ImplGetSVData(); ImplSVData* pSVData = ImplGetSVData();
if( pSVData->mpSalTimer ) if( pSVData->maSchedCtx.mpSalTimer )
{ {
bool idle = true; // TODO bool idle = true; // TODO
pSVData->mpSalTimer->CallCallback( idle ); pSVData->maSchedCtx.mpSalTimer->CallCallback( idle );
} }
} }
} }
......
...@@ -317,6 +317,13 @@ struct BlendFrameCache ...@@ -317,6 +317,13 @@ struct BlendFrameCache
} }
}; };
struct ImplSchedulerContext
{
ImplSchedulerData* mpFirstSchedulerData = nullptr; ///< list of all active tasks
SalTimer* mpSalTimer = nullptr; ///< interface to sal event loop / system timer
sal_uInt64 mnTimerPeriod = 0; ///< current timer period
};
struct ImplSVData struct ImplSVData
{ {
~ImplSVData(); ~ImplSVData();
...@@ -325,12 +332,10 @@ struct ImplSVData ...@@ -325,12 +332,10 @@ struct ImplSVData
Application* mpApp = nullptr; // pApp Application* mpApp = nullptr; // pApp
VclPtr<WorkWindow> mpDefaultWin; // Default-Window VclPtr<WorkWindow> mpDefaultWin; // Default-Window
bool mbDeInit = false; // Is VCL deinitializing bool mbDeInit = false; // Is VCL deinitializing
ImplSchedulerData* mpFirstSchedulerData = nullptr; // list of all running tasks
SalTimer* mpSalTimer = nullptr; // interface to sal event loop/timers
SalI18NImeStatus* mpImeStatus = nullptr; // interface to ime status window SalI18NImeStatus* mpImeStatus = nullptr; // interface to ime status window
SalSystem* mpSalSystem = nullptr; // SalSystem interface SalSystem* mpSalSystem = nullptr; // SalSystem interface
ResMgr* mpResMgr = nullptr; // SV-Resource-Manager ResMgr* mpResMgr = nullptr; // SV-Resource-Manager
sal_uInt64 mnTimerPeriod = 0; // current timer period ImplSchedulerContext maSchedCtx; // indepen data for class Scheduler
ImplSVAppData maAppData; // indepen data for class Application ImplSVAppData maAppData; // indepen data for class Application
ImplSVGDIData maGDIData; // indepen data for Output classes ImplSVGDIData maGDIData; // indepen data for Output classes
ImplSVWinData maWinData; // indepen data for Windows classes ImplSVWinData maWinData; // indepen data for Windows classes
......
...@@ -660,10 +660,10 @@ SAL_WNODEPRECATED_DECLARATIONS_POP ...@@ -660,10 +660,10 @@ SAL_WNODEPRECATED_DECLARATIONS_POP
{ {
// this cause crashes on MacOSX 10.4 // this cause crashes on MacOSX 10.4
// [AquaSalTimer::pRunningTimer fire]; // [AquaSalTimer::pRunningTimer fire];
if (ImplGetSVData()->mpSalTimer != nullptr) if (ImplGetSVData()->maSchedCtx.mpSalTimer != nullptr)
{ {
bool const idle = true; // TODO bool const idle = true; // TODO
ImplGetSVData()->mpSalTimer->CallCallback( idle ); ImplGetSVData()->maSchedCtx.mpSalTimer->CallCallback( idle );
} }
} }
} }
......
...@@ -33,10 +33,10 @@ ...@@ -33,10 +33,10 @@
{ {
SolarMutexGuard aGuard; SolarMutexGuard aGuard;
ImplSVData* pSVData = ImplGetSVData(); ImplSVData* pSVData = ImplGetSVData();
if( pSVData->mpSalTimer ) if( pSVData->maSchedCtx.mpSalTimer )
{ {
bool const idle = true; // TODO bool const idle = true; // TODO
pSVData->mpSalTimer->CallCallback( idle ); pSVData->maSchedCtx.mpSalTimer->CallCallback( idle );
// NSTimer does not end nextEventMatchingMask of NSApplication // NSTimer does not end nextEventMatchingMask of NSApplication
// so we need to wakeup a waiting Yield to inform it something happened // so we need to wakeup a waiting Yield to inform it something happened
......
...@@ -93,18 +93,18 @@ void ImplSalStopTimer() ...@@ -93,18 +93,18 @@ void ImplSalStopTimer()
void AquaSalTimer::handleStartTimerEvent( NSEvent* pEvent ) void AquaSalTimer::handleStartTimerEvent( NSEvent* pEvent )
{ {
ImplSVData* pSVData = ImplGetSVData(); ImplSVData* pSVData = ImplGetSVData();
if( pSVData->mpSalTimer ) if( pSVData->maSchedCtx.mpSalTimer )
{ {
NSTimeInterval posted = [pEvent timestamp] + NSTimeInterval([pEvent data1])/1000.0; NSTimeInterval posted = [pEvent timestamp] + NSTimeInterval([pEvent data1])/1000.0;
NSTimeInterval current = [NSDate timeIntervalSinceReferenceDate]; NSTimeInterval current = [NSDate timeIntervalSinceReferenceDate];
if( (posted - current) <= 0.0 ) if( (posted - current) <= 0.0 )
{ {
SolarMutexGuard aGuard; SolarMutexGuard aGuard;
if( pSVData->mpSalTimer ) if( pSVData->maSchedCtx.mpSalTimer )
{ {
// timer already elapsed since event posted // timer already elapsed since event posted
bool const idle = true; // TODO bool const idle = true; // TODO
pSVData->mpSalTimer->CallCallback( idle ); pSVData->maSchedCtx.mpSalTimer->CallCallback( idle );
} }
} }
ImplSalStartTimer( sal_uLong( [pEvent data1] ) ); ImplSalStartTimer( sal_uLong( [pEvent data1] ) );
......
...@@ -95,34 +95,28 @@ void ImplSchedulerData::Invoke() ...@@ -95,34 +95,28 @@ void ImplSchedulerData::Invoke()
void Scheduler::ImplDeInitScheduler() void Scheduler::ImplDeInitScheduler()
{ {
ImplSVData* pSVData = ImplGetSVData(); ImplSVData* pSVData = ImplGetSVData();
ImplSchedulerData* pSchedulerData = pSVData->mpFirstSchedulerData; assert( pSVData != nullptr );
if (pSVData->mpSalTimer) ImplSchedulerContext &rSchedCtx = pSVData->maSchedCtx;
{
pSVData->mpSalTimer->Stop(); if (rSchedCtx.mpSalTimer) rSchedCtx.mpSalTimer->Stop();
} DELETEZ( rSchedCtx.mpSalTimer );
if ( pSchedulerData ) ImplSchedulerData* pSchedulerData = rSchedCtx.mpFirstSchedulerData;
while ( pSchedulerData )
{ {
do if ( pSchedulerData->mpTask )
{ {
ImplSchedulerData* pTempSchedulerData = pSchedulerData; pSchedulerData->mpTask->mbActive = false;
if ( pSchedulerData->mpTask ) pSchedulerData->mpTask->mpSchedulerData = nullptr;
{
pSchedulerData->mpTask->mbActive = false;
pSchedulerData->mpTask->mpSchedulerData = nullptr;
}
pSchedulerData = pSchedulerData->mpNext;
delete pTempSchedulerData;
} }
while ( pSchedulerData ); ImplSchedulerData* pDeleteSchedulerData = pSchedulerData;
pSchedulerData = pSchedulerData->mpNext;
pSVData->mpFirstSchedulerData = nullptr; delete pDeleteSchedulerData;
pSVData->mnTimerPeriod = 0;
} }
delete pSVData->mpSalTimer; rSchedCtx.mpFirstSchedulerData = nullptr;
pSVData->mpSalTimer = nullptr; rSchedCtx.mnTimerPeriod = 0;
} }
/** /**
...@@ -144,21 +138,22 @@ void Scheduler::ImplStartTimer(sal_uInt64 nMS, bool bForce) ...@@ -144,21 +138,22 @@ void Scheduler::ImplStartTimer(sal_uInt64 nMS, bool bForce)
DBG_TESTSOLARMUTEX(); DBG_TESTSOLARMUTEX();
if (!pSVData->mpSalTimer) ImplSchedulerContext &rSchedCtx = pSVData->maSchedCtx;
if (!rSchedCtx.mpSalTimer)
{ {
pSVData->mnTimerPeriod = MaximumTimeoutMs; rSchedCtx.mnTimerPeriod = MaximumTimeoutMs;
pSVData->mpSalTimer = pSVData->mpDefInst->CreateSalTimer(); rSchedCtx.mpSalTimer = pSVData->mpDefInst->CreateSalTimer();
pSVData->mpSalTimer->SetCallback(Scheduler::CallbackTaskScheduling); rSchedCtx.mpSalTimer->SetCallback(Scheduler::CallbackTaskScheduling);
} }
if ( !nMS ) if ( !nMS )
nMS = 1; nMS = 1;
// Only if smaller timeout, to avoid skipping. // Only if smaller timeout, to avoid skipping.
if (bForce || nMS < pSVData->mnTimerPeriod) if (bForce || nMS < rSchedCtx.mnTimerPeriod)
{ {
pSVData->mnTimerPeriod = nMS; rSchedCtx.mnTimerPeriod = nMS;
pSVData->mpSalTimer->Start(nMS); rSchedCtx.mpSalTimer->Start( nMS );
} }
} }
...@@ -178,7 +173,7 @@ bool Scheduler::ProcessTaskScheduling( bool bIdle ) ...@@ -178,7 +173,7 @@ bool Scheduler::ProcessTaskScheduling( bool bIdle )
DBG_TESTSOLARMUTEX(); DBG_TESTSOLARMUTEX();
for ( ImplSchedulerData *pSchedulerData = pSVData->mpFirstSchedulerData; for ( ImplSchedulerData *pSchedulerData = pSVData->maSchedCtx.mpFirstSchedulerData;
pSchedulerData; pSchedulerData = pSchedulerData->mpNext ) pSchedulerData; pSchedulerData = pSchedulerData->mpNext )
{ {
if ( !pSchedulerData->mpTask || pSchedulerData->mbDelete || pSchedulerData->mbInScheduler || if ( !pSchedulerData->mpTask || pSchedulerData->mbDelete || pSchedulerData->mbInScheduler ||
...@@ -232,11 +227,12 @@ sal_uInt64 Scheduler::CalculateMinimumTimeout( bool &bHasActiveIdles ) ...@@ -232,11 +227,12 @@ sal_uInt64 Scheduler::CalculateMinimumTimeout( bool &bHasActiveIdles )
ImplSVData* pSVData = ImplGetSVData(); ImplSVData* pSVData = ImplGetSVData();
sal_uInt64 nTime = tools::Time::GetSystemTicks(); sal_uInt64 nTime = tools::Time::GetSystemTicks();
sal_uInt64 nMinPeriod = MaximumTimeoutMs; sal_uInt64 nMinPeriod = MaximumTimeoutMs;
ImplSchedulerContext &rSchedCtx = pSVData->maSchedCtx;
DBG_TESTSOLARMUTEX(); DBG_TESTSOLARMUTEX();
SAL_INFO("vcl.schedule", "Calculating minimum timeout:"); SAL_INFO("vcl.schedule", "Calculating minimum timeout:");
pSchedulerData = pSVData->mpFirstSchedulerData; pSchedulerData = rSchedCtx.mpFirstSchedulerData;
while ( pSchedulerData ) while ( pSchedulerData )
{ {
const Timer *timer = dynamic_cast<Timer*>( pSchedulerData->mpTask ); const Timer *timer = dynamic_cast<Timer*>( pSchedulerData->mpTask );
...@@ -260,7 +256,7 @@ sal_uInt64 Scheduler::CalculateMinimumTimeout( bool &bHasActiveIdles ) ...@@ -260,7 +256,7 @@ sal_uInt64 Scheduler::CalculateMinimumTimeout( bool &bHasActiveIdles )
if ( pPrevSchedulerData ) if ( pPrevSchedulerData )
pPrevSchedulerData->mpNext = pSchedulerData->mpNext; pPrevSchedulerData->mpNext = pSchedulerData->mpNext;
else else
pSVData->mpFirstSchedulerData = pSchedulerData->mpNext; rSchedCtx.mpFirstSchedulerData = pSchedulerData->mpNext;
if ( pSchedulerData->mpTask ) if ( pSchedulerData->mpTask )
pSchedulerData->mpTask->mpSchedulerData = nullptr; pSchedulerData->mpTask->mpSchedulerData = nullptr;
pNext = pSchedulerData->mpNext; pNext = pSchedulerData->mpNext;
...@@ -292,12 +288,12 @@ sal_uInt64 Scheduler::CalculateMinimumTimeout( bool &bHasActiveIdles ) ...@@ -292,12 +288,12 @@ sal_uInt64 Scheduler::CalculateMinimumTimeout( bool &bHasActiveIdles )
} }
// delete clock if no more timers available, // delete clock if no more timers available,
if ( !pSVData->mpFirstSchedulerData ) if ( !pSVData->maSchedCtx.mpFirstSchedulerData )
{ {
if ( pSVData->mpSalTimer ) if ( pSVData->maSchedCtx.mpSalTimer )
pSVData->mpSalTimer->Stop(); pSVData->maSchedCtx.mpSalTimer->Stop();
nMinPeriod = MaximumTimeoutMs; nMinPeriod = MaximumTimeoutMs;
pSVData->mnTimerPeriod = nMinPeriod; pSVData->maSchedCtx.mnTimerPeriod = nMinPeriod;
SAL_INFO("vcl.schedule", "Unusual - no more timers available - stop timer"); SAL_INFO("vcl.schedule", "Unusual - no more timers available - stop timer");
} }
else else
...@@ -349,7 +345,7 @@ void Task::Start() ...@@ -349,7 +345,7 @@ void Task::Start()
// insert last due to SFX! // insert last due to SFX!
ImplSchedulerData* pPrev = nullptr; ImplSchedulerData* pPrev = nullptr;
ImplSchedulerData* pData = pSVData->mpFirstSchedulerData; ImplSchedulerData* pData = pSVData->maSchedCtx.mpFirstSchedulerData;
while ( pData ) while ( pData )
{ {
pPrev = pData; pPrev = pData;
...@@ -359,7 +355,7 @@ void Task::Start() ...@@ -359,7 +355,7 @@ void Task::Start()
if ( pPrev ) if ( pPrev )
pPrev->mpNext = mpSchedulerData; pPrev->mpNext = mpSchedulerData;
else else
pSVData->mpFirstSchedulerData = mpSchedulerData; pSVData->maSchedCtx.mpFirstSchedulerData = mpSchedulerData;
SAL_INFO( "vcl.schedule", tools::Time::GetSystemTicks() SAL_INFO( "vcl.schedule", tools::Time::GetSystemTicks()
<< " " << mpSchedulerData << " added " << *this ); << " " << mpSchedulerData << " added " << *this );
} }
......
...@@ -548,7 +548,7 @@ void Scheduler::ProcessEventsToIdle() ...@@ -548,7 +548,7 @@ void Scheduler::ProcessEventsToIdle()
const ImplSVData* pSVData = ImplGetSVData(); const ImplSVData* pSVData = ImplGetSVData();
if ( !pSVData->mpDefInst->IsMainThread() ) if ( !pSVData->mpDefInst->IsMainThread() )
return; return;
const ImplSchedulerData* pSchedulerData = ImplGetSVData()->mpFirstSchedulerData; const ImplSchedulerData* pSchedulerData = ImplGetSVData()->maSchedCtx.mpFirstSchedulerData;
bool bAnyIdle = false; bool bAnyIdle = false;
while ( pSchedulerData ) while ( pSchedulerData )
{ {
......
...@@ -584,8 +584,9 @@ void DeInitVCL() ...@@ -584,8 +584,9 @@ void DeInitVCL()
// and thereby unloading the plugin // and thereby unloading the plugin
delete pSVData->mpSalSystem; delete pSVData->mpSalSystem;
pSVData->mpSalSystem = nullptr; pSVData->mpSalSystem = nullptr;
delete pSVData->mpSalTimer; assert( !pSVData->maSchedCtx.mpSalTimer );
pSVData->mpSalTimer = nullptr; delete pSVData->maSchedCtx.mpSalTimer;
pSVData->maSchedCtx.mpSalTimer = nullptr;
pSVData->mpDefaultWin = nullptr; pSVData->mpDefaultWin = nullptr;
pSVData->mpIntroWindow = nullptr; pSVData->mpIntroWindow = nullptr;
......
...@@ -564,8 +564,8 @@ void X11SalData::XError( Display *pDisplay, XErrorEvent *pEvent ) ...@@ -564,8 +564,8 @@ void X11SalData::XError( Display *pDisplay, XErrorEvent *pEvent )
void X11SalData::Timeout( bool idle ) void X11SalData::Timeout( bool idle )
{ {
ImplSVData* pSVData = ImplGetSVData(); ImplSVData* pSVData = ImplGetSVData();
if( pSVData->mpSalTimer ) if( pSVData->maSchedCtx.mpSalTimer )
pSVData->mpSalTimer->CallCallback( idle ); pSVData->maSchedCtx.mpSalTimer->CallCallback( idle );
} }
struct YieldEntry struct YieldEntry
......
...@@ -735,11 +735,11 @@ extern "C" { ...@@ -735,11 +735,11 @@ extern "C" {
sal_gtk_timeout_defer( pTSource ); sal_gtk_timeout_defer( pTSource );
ImplSVData* pSVData = ImplGetSVData(); ImplSVData* pSVData = ImplGetSVData();
if( pSVData->mpSalTimer ) if( pSVData->maSchedCtx.mpSalTimer )
{ {
// TODO: context_pending should be probably checked too, but it causes locking assertion failures // TODO: context_pending should be probably checked too, but it causes locking assertion failures
bool idle = !pSalData->BlockIdleTimeout() && /*!g_main_context_pending( NULL ) &&*/ !gdk_events_pending(); bool idle = !pSalData->BlockIdleTimeout() && /*!g_main_context_pending( NULL ) &&*/ !gdk_events_pending();
pSVData->mpSalTimer->CallCallback( idle ); pSVData->maSchedCtx.mpSalTimer->CallCallback( idle );
} }
return TRUE; return TRUE;
......
...@@ -697,11 +697,11 @@ extern "C" { ...@@ -697,11 +697,11 @@ extern "C" {
sal_gtk_timeout_defer( pTSource ); sal_gtk_timeout_defer( pTSource );
ImplSVData* pSVData = ImplGetSVData(); ImplSVData* pSVData = ImplGetSVData();
if( pSVData->mpSalTimer ) if( pSVData->maSchedCtx.mpSalTimer )
{ {
// TODO: context_pending should be probably checked too, but it causes locking assertion failures // TODO: context_pending should be probably checked too, but it causes locking assertion failures
bool idle = !pSalData->BlockIdleTimeout() && /*!g_main_context_pending( NULL ) &&*/ !gdk_events_pending(); bool idle = !pSalData->BlockIdleTimeout() && /*!g_main_context_pending( NULL ) &&*/ !gdk_events_pending();
pSVData->mpSalTimer->CallCallback( idle ); pSVData->maSchedCtx.mpSalTimer->CallCallback( idle );
} }
return TRUE; return TRUE;
......
...@@ -148,10 +148,10 @@ void EmitTimerCallback() ...@@ -148,10 +148,10 @@ void EmitTimerCallback()
// Try to acquire the mutex. If we don't get the mutex then we // Try to acquire the mutex. If we don't get the mutex then we
// try this a short time later again. // try this a short time later again.
if (pSVData->mpSalTimer && ImplSalYieldMutexTryToAcquire()) if (pSVData->maSchedCtx.mpSalTimer && ImplSalYieldMutexTryToAcquire())
{ {
bool const idle = true; // TODO bool const idle = true; // TODO
pSVData->mpSalTimer->CallCallback( idle ); pSVData->maSchedCtx.mpSalTimer->CallCallback( idle );
ImplSalYieldMutexRelease(); ImplSalYieldMutexRelease();
// Run the timer again if it was started before, and also // Run the timer again if it was started before, and also
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment