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 )
// notify
ImplSVData* pSVData = ImplGetSVData();
if( pSVData->mpSalTimer )
if( pSVData->maSchedCtx.mpSalTimer )
{
bool idle = true; // TODO
pSVData->mpSalTimer->CallCallback( idle );
pSVData->maSchedCtx.mpSalTimer->CallCallback( idle );
}
}
}
......
......@@ -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
{
~ImplSVData();
......@@ -325,12 +332,10 @@ struct ImplSVData
Application* mpApp = nullptr; // pApp
VclPtr<WorkWindow> mpDefaultWin; // Default-Window
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
SalSystem* mpSalSystem = nullptr; // SalSystem interface
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
ImplSVGDIData maGDIData; // indepen data for Output classes
ImplSVWinData maWinData; // indepen data for Windows classes
......
......@@ -660,10 +660,10 @@ SAL_WNODEPRECATED_DECLARATIONS_POP
{
// this cause crashes on MacOSX 10.4
// [AquaSalTimer::pRunningTimer fire];
if (ImplGetSVData()->mpSalTimer != nullptr)
if (ImplGetSVData()->maSchedCtx.mpSalTimer != nullptr)
{
bool const idle = true; // TODO
ImplGetSVData()->mpSalTimer->CallCallback( idle );
ImplGetSVData()->maSchedCtx.mpSalTimer->CallCallback( idle );
}
}
}
......
......@@ -33,10 +33,10 @@
{
SolarMutexGuard aGuard;
ImplSVData* pSVData = ImplGetSVData();
if( pSVData->mpSalTimer )
if( pSVData->maSchedCtx.mpSalTimer )
{
bool const idle = true; // TODO
pSVData->mpSalTimer->CallCallback( idle );
pSVData->maSchedCtx.mpSalTimer->CallCallback( idle );
// NSTimer does not end nextEventMatchingMask of NSApplication
// so we need to wakeup a waiting Yield to inform it something happened
......
......@@ -93,18 +93,18 @@ void ImplSalStopTimer()
void AquaSalTimer::handleStartTimerEvent( NSEvent* pEvent )
{
ImplSVData* pSVData = ImplGetSVData();
if( pSVData->mpSalTimer )
if( pSVData->maSchedCtx.mpSalTimer )
{
NSTimeInterval posted = [pEvent timestamp] + NSTimeInterval([pEvent data1])/1000.0;
NSTimeInterval current = [NSDate timeIntervalSinceReferenceDate];
if( (posted - current) <= 0.0 )
{
SolarMutexGuard aGuard;
if( pSVData->mpSalTimer )
if( pSVData->maSchedCtx.mpSalTimer )
{
// timer already elapsed since event posted
bool const idle = true; // TODO
pSVData->mpSalTimer->CallCallback( idle );
pSVData->maSchedCtx.mpSalTimer->CallCallback( idle );
}
}
ImplSalStartTimer( sal_uLong( [pEvent data1] ) );
......
......@@ -95,34 +95,28 @@ void ImplSchedulerData::Invoke()
void Scheduler::ImplDeInitScheduler()
{
ImplSVData* pSVData = ImplGetSVData();
ImplSchedulerData* pSchedulerData = pSVData->mpFirstSchedulerData;
if (pSVData->mpSalTimer)
{
pSVData->mpSalTimer->Stop();
}
ImplSVData* pSVData = ImplGetSVData();
assert( pSVData != nullptr );
ImplSchedulerContext &rSchedCtx = pSVData->maSchedCtx;
if (rSchedCtx.mpSalTimer) rSchedCtx.mpSalTimer->Stop();
DELETEZ( rSchedCtx.mpSalTimer );
if ( pSchedulerData )
ImplSchedulerData* pSchedulerData = rSchedCtx.mpFirstSchedulerData;
while ( pSchedulerData )
{
do
if ( pSchedulerData->mpTask )
{
ImplSchedulerData* pTempSchedulerData = pSchedulerData;
if ( pSchedulerData->mpTask )
{
pSchedulerData->mpTask->mbActive = false;
pSchedulerData->mpTask->mpSchedulerData = nullptr;
}
pSchedulerData = pSchedulerData->mpNext;
delete pTempSchedulerData;
pSchedulerData->mpTask->mbActive = false;
pSchedulerData->mpTask->mpSchedulerData = nullptr;
}
while ( pSchedulerData );
pSVData->mpFirstSchedulerData = nullptr;
pSVData->mnTimerPeriod = 0;
ImplSchedulerData* pDeleteSchedulerData = pSchedulerData;
pSchedulerData = pSchedulerData->mpNext;
delete pDeleteSchedulerData;
}
delete pSVData->mpSalTimer;
pSVData->mpSalTimer = nullptr;
rSchedCtx.mpFirstSchedulerData = nullptr;
rSchedCtx.mnTimerPeriod = 0;
}
/**
......@@ -144,21 +138,22 @@ void Scheduler::ImplStartTimer(sal_uInt64 nMS, bool bForce)
DBG_TESTSOLARMUTEX();
if (!pSVData->mpSalTimer)
ImplSchedulerContext &rSchedCtx = pSVData->maSchedCtx;
if (!rSchedCtx.mpSalTimer)
{
pSVData->mnTimerPeriod = MaximumTimeoutMs;
pSVData->mpSalTimer = pSVData->mpDefInst->CreateSalTimer();
pSVData->mpSalTimer->SetCallback(Scheduler::CallbackTaskScheduling);
rSchedCtx.mnTimerPeriod = MaximumTimeoutMs;
rSchedCtx.mpSalTimer = pSVData->mpDefInst->CreateSalTimer();
rSchedCtx.mpSalTimer->SetCallback(Scheduler::CallbackTaskScheduling);
}
if ( !nMS )
nMS = 1;
// Only if smaller timeout, to avoid skipping.
if (bForce || nMS < pSVData->mnTimerPeriod)
if (bForce || nMS < rSchedCtx.mnTimerPeriod)
{
pSVData->mnTimerPeriod = nMS;
pSVData->mpSalTimer->Start(nMS);
rSchedCtx.mnTimerPeriod = nMS;
rSchedCtx.mpSalTimer->Start( nMS );
}
}
......@@ -178,7 +173,7 @@ bool Scheduler::ProcessTaskScheduling( bool bIdle )
DBG_TESTSOLARMUTEX();
for ( ImplSchedulerData *pSchedulerData = pSVData->mpFirstSchedulerData;
for ( ImplSchedulerData *pSchedulerData = pSVData->maSchedCtx.mpFirstSchedulerData;
pSchedulerData; pSchedulerData = pSchedulerData->mpNext )
{
if ( !pSchedulerData->mpTask || pSchedulerData->mbDelete || pSchedulerData->mbInScheduler ||
......@@ -232,11 +227,12 @@ sal_uInt64 Scheduler::CalculateMinimumTimeout( bool &bHasActiveIdles )
ImplSVData* pSVData = ImplGetSVData();
sal_uInt64 nTime = tools::Time::GetSystemTicks();
sal_uInt64 nMinPeriod = MaximumTimeoutMs;
ImplSchedulerContext &rSchedCtx = pSVData->maSchedCtx;
DBG_TESTSOLARMUTEX();
SAL_INFO("vcl.schedule", "Calculating minimum timeout:");
pSchedulerData = pSVData->mpFirstSchedulerData;
pSchedulerData = rSchedCtx.mpFirstSchedulerData;
while ( pSchedulerData )
{
const Timer *timer = dynamic_cast<Timer*>( pSchedulerData->mpTask );
......@@ -260,7 +256,7 @@ sal_uInt64 Scheduler::CalculateMinimumTimeout( bool &bHasActiveIdles )
if ( pPrevSchedulerData )
pPrevSchedulerData->mpNext = pSchedulerData->mpNext;
else
pSVData->mpFirstSchedulerData = pSchedulerData->mpNext;
rSchedCtx.mpFirstSchedulerData = pSchedulerData->mpNext;
if ( pSchedulerData->mpTask )
pSchedulerData->mpTask->mpSchedulerData = nullptr;
pNext = pSchedulerData->mpNext;
......@@ -292,12 +288,12 @@ sal_uInt64 Scheduler::CalculateMinimumTimeout( bool &bHasActiveIdles )
}
// delete clock if no more timers available,
if ( !pSVData->mpFirstSchedulerData )
if ( !pSVData->maSchedCtx.mpFirstSchedulerData )
{
if ( pSVData->mpSalTimer )
pSVData->mpSalTimer->Stop();
if ( pSVData->maSchedCtx.mpSalTimer )
pSVData->maSchedCtx.mpSalTimer->Stop();
nMinPeriod = MaximumTimeoutMs;
pSVData->mnTimerPeriod = nMinPeriod;
pSVData->maSchedCtx.mnTimerPeriod = nMinPeriod;
SAL_INFO("vcl.schedule", "Unusual - no more timers available - stop timer");
}
else
......@@ -349,7 +345,7 @@ void Task::Start()
// insert last due to SFX!
ImplSchedulerData* pPrev = nullptr;
ImplSchedulerData* pData = pSVData->mpFirstSchedulerData;
ImplSchedulerData* pData = pSVData->maSchedCtx.mpFirstSchedulerData;
while ( pData )
{
pPrev = pData;
......@@ -359,7 +355,7 @@ void Task::Start()
if ( pPrev )
pPrev->mpNext = mpSchedulerData;
else
pSVData->mpFirstSchedulerData = mpSchedulerData;
pSVData->maSchedCtx.mpFirstSchedulerData = mpSchedulerData;
SAL_INFO( "vcl.schedule", tools::Time::GetSystemTicks()
<< " " << mpSchedulerData << " added " << *this );
}
......
......@@ -548,7 +548,7 @@ void Scheduler::ProcessEventsToIdle()
const ImplSVData* pSVData = ImplGetSVData();
if ( !pSVData->mpDefInst->IsMainThread() )
return;
const ImplSchedulerData* pSchedulerData = ImplGetSVData()->mpFirstSchedulerData;
const ImplSchedulerData* pSchedulerData = ImplGetSVData()->maSchedCtx.mpFirstSchedulerData;
bool bAnyIdle = false;
while ( pSchedulerData )
{
......
......@@ -584,8 +584,9 @@ void DeInitVCL()
// and thereby unloading the plugin
delete pSVData->mpSalSystem;
pSVData->mpSalSystem = nullptr;
delete pSVData->mpSalTimer;
pSVData->mpSalTimer = nullptr;
assert( !pSVData->maSchedCtx.mpSalTimer );
delete pSVData->maSchedCtx.mpSalTimer;
pSVData->maSchedCtx.mpSalTimer = nullptr;
pSVData->mpDefaultWin = nullptr;
pSVData->mpIntroWindow = nullptr;
......
......@@ -564,8 +564,8 @@ void X11SalData::XError( Display *pDisplay, XErrorEvent *pEvent )
void X11SalData::Timeout( bool idle )
{
ImplSVData* pSVData = ImplGetSVData();
if( pSVData->mpSalTimer )
pSVData->mpSalTimer->CallCallback( idle );
if( pSVData->maSchedCtx.mpSalTimer )
pSVData->maSchedCtx.mpSalTimer->CallCallback( idle );
}
struct YieldEntry
......
......@@ -735,11 +735,11 @@ extern "C" {
sal_gtk_timeout_defer( pTSource );
ImplSVData* pSVData = ImplGetSVData();
if( pSVData->mpSalTimer )
if( pSVData->maSchedCtx.mpSalTimer )
{
// 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();
pSVData->mpSalTimer->CallCallback( idle );
pSVData->maSchedCtx.mpSalTimer->CallCallback( idle );
}
return TRUE;
......
......@@ -697,11 +697,11 @@ extern "C" {
sal_gtk_timeout_defer( pTSource );
ImplSVData* pSVData = ImplGetSVData();
if( pSVData->mpSalTimer )
if( pSVData->maSchedCtx.mpSalTimer )
{
// 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();
pSVData->mpSalTimer->CallCallback( idle );
pSVData->maSchedCtx.mpSalTimer->CallCallback( idle );
}
return TRUE;
......
......@@ -148,10 +148,10 @@ void EmitTimerCallback()
// Try to acquire the mutex. If we don't get the mutex then we
// try this a short time later again.
if (pSVData->mpSalTimer && ImplSalYieldMutexTryToAcquire())
if (pSVData->maSchedCtx.mpSalTimer && ImplSalYieldMutexTryToAcquire())
{
bool const idle = true; // TODO
pSVData->mpSalTimer->CallCallback( idle );
pSVData->maSchedCtx.mpSalTimer->CallCallback( idle );
ImplSalYieldMutexRelease();
// 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