bump product version to 7.6.3.2-android
[LibreOffice.git] / vcl / source / app / scheduler.cxx
blob098242fe6c704ba42d082561bd70047e127779bd
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <sal/config.h>
22 #include <cassert>
23 #include <cstdlib>
24 #include <exception>
25 #include <typeinfo>
27 #include <com/sun/star/uno/Exception.hpp>
28 #include <sal/log.hxx>
29 #include <sal/types.h>
30 #include <svdata.hxx>
31 #include <tools/time.hxx>
32 #include <tools/debug.hxx>
33 #include <comphelper/diagnose_ex.hxx>
34 #include <unotools/configmgr.hxx>
35 #include <vcl/TaskStopwatch.hxx>
36 #include <vcl/scheduler.hxx>
37 #include <vcl/idle.hxx>
38 #include <saltimer.hxx>
39 #include <salinst.hxx>
40 #include <comphelper/profilezone.hxx>
41 #include <schedulerimpl.hxx>
43 namespace {
45 template< typename charT, typename traits >
46 std::basic_ostream<charT, traits> & operator <<(
47 std::basic_ostream<charT, traits> & stream, const Task& task )
49 stream << "a: " << task.IsActive() << " p: " << static_cast<int>(task.GetPriority());
50 const char *name = task.GetDebugName();
51 if( nullptr == name )
52 return stream << " (nullptr)";
53 else
54 return stream << " " << name;
57 /**
58 * clang won't compile this in the Timer.hxx header, even with a class Idle
59 * forward definition, due to the incomplete Idle type in the template.
60 * Currently the code is just used in the Scheduler, so we keep it local.
62 * @see http://clang.llvm.org/compatibility.html#undep_incomplete
64 template< typename charT, typename traits >
65 std::basic_ostream<charT, traits> & operator <<(
66 std::basic_ostream<charT, traits> & stream, const Timer& timer )
68 bool bIsIdle = (dynamic_cast<const Idle*>( &timer ) != nullptr);
69 stream << (bIsIdle ? "Idle " : "Timer")
70 << " a: " << timer.IsActive() << " p: " << static_cast<int>(timer.GetPriority());
71 const char *name = timer.GetDebugName();
72 if ( nullptr == name )
73 stream << " (nullptr)";
74 else
75 stream << " " << name;
76 if ( !bIsIdle )
77 stream << " " << timer.GetTimeout() << "ms";
78 stream << " (" << &timer << ")";
79 return stream;
82 template< typename charT, typename traits >
83 std::basic_ostream<charT, traits> & operator <<(
84 std::basic_ostream<charT, traits> & stream, const Idle& idle )
86 return stream << static_cast<const Timer*>( &idle );
89 template< typename charT, typename traits >
90 std::basic_ostream<charT, traits> & operator <<(
91 std::basic_ostream<charT, traits> & stream, const ImplSchedulerData& data )
93 stream << " i: " << data.mbInScheduler;
94 return stream;
97 } // end anonymous namespace
99 unsigned int TaskStopwatch::m_nTimeSlice = TaskStopwatch::nDefaultTimeSlice;
101 void Scheduler::ImplDeInitScheduler()
103 ImplSVData* pSVData = ImplGetSVData();
104 assert( pSVData != nullptr );
105 ImplSchedulerContext &rSchedCtx = pSVData->maSchedCtx;
107 DBG_TESTSOLARMUTEX();
109 SchedulerGuard aSchedulerGuard;
111 int nTaskPriority = 0;
112 #if OSL_DEBUG_LEVEL > 0
113 sal_uInt32 nTasks = 0;
114 for (nTaskPriority = 0; nTaskPriority < PRIO_COUNT; ++nTaskPriority)
116 ImplSchedulerData* pSchedulerData = rSchedCtx.mpFirstSchedulerData[nTaskPriority];
117 while ( pSchedulerData )
119 ++nTasks;
120 pSchedulerData = pSchedulerData->mpNext;
123 SAL_INFO( "vcl.schedule.deinit",
124 "DeInit the scheduler - pending tasks: " << nTasks );
126 // clean up all the sfx::SfxItemDisruptor_Impl Idles
127 Unlock();
128 ProcessEventsToIdle();
129 Lock();
130 #endif
131 rSchedCtx.mbActive = false;
133 assert( nullptr == rSchedCtx.mpSchedulerStack );
135 if (rSchedCtx.mpSalTimer) rSchedCtx.mpSalTimer->Stop();
136 delete rSchedCtx.mpSalTimer;
137 rSchedCtx.mpSalTimer = nullptr;
139 #if OSL_DEBUG_LEVEL > 0
140 sal_uInt32 nActiveTasks = 0, nIgnoredTasks = 0;
141 #endif
142 nTaskPriority = 0;
143 ImplSchedulerData* pSchedulerData = nullptr;
145 next_priority:
146 pSchedulerData = rSchedCtx.mpFirstSchedulerData[nTaskPriority];
147 while ( pSchedulerData )
149 Task *pTask = pSchedulerData->mpTask;
150 if ( pTask )
152 if ( pTask->mbActive )
154 #if OSL_DEBUG_LEVEL > 0
155 const char *sIgnored = "";
156 ++nActiveTasks;
157 // TODO: shutdown these timers before Scheduler de-init
158 // TODO: remove Task from static object
159 if ( pTask->GetDebugName() && ( false
160 || !strcmp( pTask->GetDebugName(), "desktop::Desktop m_firstRunTimer" )
161 || !strcmp( pTask->GetDebugName(), "DrawWorkStartupTimer" )
162 || !strcmp( pTask->GetDebugName(), "editeng::ImpEditEngine aOnlineSpellTimer" )
163 || !strcmp( pTask->GetDebugName(), "sc ScModule IdleTimer" )
164 || !strcmp( pTask->GetDebugName(), "sd::CacheConfiguration maReleaseTimer" )
165 || !strcmp( pTask->GetDebugName(), "svtools::GraphicCache maReleaseTimer" )
166 || !strcmp( pTask->GetDebugName(), "svtools::GraphicObject mpSwapOutTimer" )
167 || !strcmp( pTask->GetDebugName(), "svx OLEObjCache pTimer UnloadCheck" )
168 || !strcmp( pTask->GetDebugName(), "vcl SystemDependentDataBuffer aSystemDependentDataBuffer" )
171 sIgnored = " (ignored)";
172 ++nIgnoredTasks;
174 const Timer *timer = dynamic_cast<Timer*>( pTask );
175 if ( timer )
176 SAL_WARN( "vcl.schedule.deinit", "DeInit task: " << *timer << sIgnored );
177 else
178 SAL_WARN( "vcl.schedule.deinit", "DeInit task: " << *pTask << sIgnored );
179 #endif
180 pTask->mbActive = false;
182 pTask->mpSchedulerData = nullptr;
183 pTask->SetStatic();
185 ImplSchedulerData* pDeleteSchedulerData = pSchedulerData;
186 pSchedulerData = pSchedulerData->mpNext;
187 delete pDeleteSchedulerData;
190 ++nTaskPriority;
191 if (nTaskPriority < PRIO_COUNT)
192 goto next_priority;
194 #if OSL_DEBUG_LEVEL > 0
195 SAL_INFO( "vcl.schedule.deinit", "DeInit the scheduler - finished" );
196 SAL_WARN_IF( 0 != nActiveTasks, "vcl.schedule.deinit", "DeInit active tasks: "
197 << nActiveTasks << " (ignored: " << nIgnoredTasks << ")" );
198 // assert( nIgnoredTasks == nActiveTasks );
199 #endif
201 for (nTaskPriority = 0; nTaskPriority < PRIO_COUNT; ++nTaskPriority)
203 rSchedCtx.mpFirstSchedulerData[nTaskPriority] = nullptr;
204 rSchedCtx.mpLastSchedulerData[nTaskPriority] = nullptr;
206 rSchedCtx.mnTimerPeriod = InfiniteTimeoutMs;
209 void Scheduler::Lock()
211 ImplSVData* pSVData = ImplGetSVData();
212 assert( pSVData != nullptr );
213 pSVData->maSchedCtx.maMutex.lock();
216 void Scheduler::Unlock()
218 ImplSVData* pSVData = ImplGetSVData();
219 assert( pSVData != nullptr );
220 pSVData->maSchedCtx.maMutex.unlock();
224 * Start a new timer if we need to for nMS duration.
226 * if this is longer than the existing duration we're
227 * waiting for, do nothing - unless bForce - which means
228 * to reset the minimum period; used by the scheduled itself.
230 void Scheduler::ImplStartTimer(sal_uInt64 nMS, bool bForce, sal_uInt64 nTime)
232 ImplSVData* pSVData = ImplGetSVData();
233 ImplSchedulerContext &rSchedCtx = pSVData->maSchedCtx;
234 if ( !rSchedCtx.mbActive )
235 return;
237 if (!rSchedCtx.mpSalTimer)
239 rSchedCtx.mnTimerStart = 0;
240 rSchedCtx.mnTimerPeriod = InfiniteTimeoutMs;
241 rSchedCtx.mpSalTimer = pSVData->mpDefInst->CreateSalTimer();
242 rSchedCtx.mpSalTimer->SetCallback(Scheduler::CallbackTaskScheduling);
245 assert(SAL_MAX_UINT64 - nMS >= nTime);
247 sal_uInt64 nProposedTimeout = nTime + nMS;
248 sal_uInt64 nCurTimeout = ( rSchedCtx.mnTimerPeriod == InfiniteTimeoutMs )
249 ? SAL_MAX_UINT64 : rSchedCtx.mnTimerStart + rSchedCtx.mnTimerPeriod;
251 // Only if smaller timeout, to avoid skipping.
252 // Force instant wakeup on 0ms, if the previous period was not 0ms
253 if (bForce || nProposedTimeout < nCurTimeout || (!nMS && rSchedCtx.mnTimerPeriod))
255 SAL_INFO( "vcl.schedule", " Starting scheduler system timer (" << nMS << "ms)" );
256 rSchedCtx.mnTimerStart = nTime;
257 rSchedCtx.mnTimerPeriod = nMS;
258 rSchedCtx.mpSalTimer->Start( nMS );
262 static bool g_bDeterministicMode = false;
264 void Scheduler::SetDeterministicMode(bool bDeterministic)
266 g_bDeterministicMode = bDeterministic;
269 bool Scheduler::GetDeterministicMode()
271 return g_bDeterministicMode;
274 inline void Scheduler::UpdateSystemTimer( ImplSchedulerContext &rSchedCtx,
275 const sal_uInt64 nMinPeriod,
276 const bool bForce, const sal_uInt64 nTime )
278 if ( InfiniteTimeoutMs == nMinPeriod )
280 SAL_INFO("vcl.schedule", " Stopping system timer");
281 if ( rSchedCtx.mpSalTimer )
282 rSchedCtx.mpSalTimer->Stop();
283 rSchedCtx.mnTimerPeriod = nMinPeriod;
285 else
286 Scheduler::ImplStartTimer( nMinPeriod, bForce, nTime );
289 static void AppendSchedulerData( ImplSchedulerContext &rSchedCtx,
290 ImplSchedulerData * const pSchedulerData)
292 assert(pSchedulerData->mpTask);
293 pSchedulerData->mePriority = pSchedulerData->mpTask->GetPriority();
294 pSchedulerData->mpNext = nullptr;
296 const int nTaskPriority = static_cast<int>(pSchedulerData->mePriority);
297 if (!rSchedCtx.mpLastSchedulerData[nTaskPriority])
299 rSchedCtx.mpFirstSchedulerData[nTaskPriority] = pSchedulerData;
300 rSchedCtx.mpLastSchedulerData[nTaskPriority] = pSchedulerData;
302 else
304 rSchedCtx.mpLastSchedulerData[nTaskPriority]->mpNext = pSchedulerData;
305 rSchedCtx.mpLastSchedulerData[nTaskPriority] = pSchedulerData;
309 static ImplSchedulerData* DropSchedulerData(
310 ImplSchedulerContext &rSchedCtx, ImplSchedulerData * const pPrevSchedulerData,
311 const ImplSchedulerData * const pSchedulerData, const int nTaskPriority)
313 assert( pSchedulerData );
314 if ( pPrevSchedulerData )
315 assert( pPrevSchedulerData->mpNext == pSchedulerData );
316 else
317 assert(rSchedCtx.mpFirstSchedulerData[nTaskPriority] == pSchedulerData);
319 ImplSchedulerData * const pSchedulerDataNext = pSchedulerData->mpNext;
320 if ( pPrevSchedulerData )
321 pPrevSchedulerData->mpNext = pSchedulerDataNext;
322 else
323 rSchedCtx.mpFirstSchedulerData[nTaskPriority] = pSchedulerDataNext;
324 if ( !pSchedulerDataNext )
325 rSchedCtx.mpLastSchedulerData[nTaskPriority] = pPrevSchedulerData;
326 return pSchedulerDataNext;
329 void Scheduler::CallbackTaskScheduling()
331 ImplSVData *pSVData = ImplGetSVData();
332 ImplSchedulerContext &rSchedCtx = pSVData->maSchedCtx;
334 DBG_TESTSOLARMUTEX();
336 SchedulerGuard aSchedulerGuard;
337 if ( !rSchedCtx.mbActive || InfiniteTimeoutMs == rSchedCtx.mnTimerPeriod )
338 return;
340 sal_uInt64 nTime = tools::Time::GetSystemTicks();
341 // Allow for decimals, so subtract in the compare (needed at least on iOS)
342 if ( nTime < rSchedCtx.mnTimerStart + rSchedCtx.mnTimerPeriod -1)
344 int nSleep = rSchedCtx.mnTimerStart + rSchedCtx.mnTimerPeriod - nTime;
345 UpdateSystemTimer(rSchedCtx, nSleep, true, nTime);
346 return;
349 ImplSchedulerData* pSchedulerData = nullptr;
350 ImplSchedulerData* pPrevSchedulerData = nullptr;
351 ImplSchedulerData *pMostUrgent = nullptr;
352 ImplSchedulerData *pPrevMostUrgent = nullptr;
353 int nMostUrgentPriority = 0;
354 sal_uInt64 nMinPeriod = InfiniteTimeoutMs;
355 sal_uInt64 nReadyPeriod = InfiniteTimeoutMs;
356 unsigned nTasks = 0;
357 int nTaskPriority = 0;
359 for (; nTaskPriority < PRIO_COUNT; ++nTaskPriority)
361 // Related: tdf#152703 Eliminate potential blocking during live resize
362 // Only higher priority tasks need to be fired to redraw the window
363 // so skip firing potentially long-running tasks, such as the Writer
364 // idle layout timer, when a window is in live resize
365 if ( ImplGetSVData()->mpWinData->mbIsLiveResize && nTaskPriority == static_cast<int>(TaskPriority::LOWEST) )
366 continue;
368 pSchedulerData = rSchedCtx.mpFirstSchedulerData[nTaskPriority];
369 pPrevSchedulerData = nullptr;
370 while (pSchedulerData)
372 ++nTasks;
373 const Timer *timer = dynamic_cast<Timer*>( pSchedulerData->mpTask );
374 if ( timer )
375 SAL_INFO( "vcl.schedule", tools::Time::GetSystemTicks() << " "
376 << pSchedulerData << " " << *pSchedulerData << " " << *timer );
377 else if ( pSchedulerData->mpTask )
378 SAL_INFO( "vcl.schedule", tools::Time::GetSystemTicks() << " "
379 << pSchedulerData << " " << *pSchedulerData
380 << " " << *pSchedulerData->mpTask );
381 else
382 SAL_INFO( "vcl.schedule", tools::Time::GetSystemTicks() << " "
383 << pSchedulerData << " " << *pSchedulerData << " (to be deleted)" );
385 // Should the Task be released from scheduling?
386 assert(!pSchedulerData->mbInScheduler);
387 if (!pSchedulerData->mpTask || !pSchedulerData->mpTask->IsActive())
389 ImplSchedulerData * const pSchedulerDataNext =
390 DropSchedulerData(rSchedCtx, pPrevSchedulerData, pSchedulerData, nTaskPriority);
391 if ( pSchedulerData->mpTask )
392 pSchedulerData->mpTask->mpSchedulerData = nullptr;
393 delete pSchedulerData;
394 pSchedulerData = pSchedulerDataNext;
395 continue;
398 assert(pSchedulerData->mpTask);
399 if (pSchedulerData->mpTask->IsActive())
401 nReadyPeriod = pSchedulerData->mpTask->UpdateMinPeriod( nTime );
402 if (ImmediateTimeoutMs == nReadyPeriod)
404 if (!pMostUrgent)
406 pPrevMostUrgent = pPrevSchedulerData;
407 pMostUrgent = pSchedulerData;
408 nMostUrgentPriority = nTaskPriority;
410 else
412 nMinPeriod = ImmediateTimeoutMs;
413 break;
416 else if (nMinPeriod > nReadyPeriod)
417 nMinPeriod = nReadyPeriod;
420 pPrevSchedulerData = pSchedulerData;
421 pSchedulerData = pSchedulerData->mpNext;
424 if (ImmediateTimeoutMs == nMinPeriod)
425 break;
428 if (InfiniteTimeoutMs != nMinPeriod)
429 SAL_INFO("vcl.schedule",
430 "Calculated minimum timeout as " << nMinPeriod << " of " << nTasks << " tasks");
431 UpdateSystemTimer(rSchedCtx, nMinPeriod, true, nTime);
433 if ( !pMostUrgent )
434 return;
436 SAL_INFO( "vcl.schedule", tools::Time::GetSystemTicks() << " "
437 << pMostUrgent << " invoke-in " << *pMostUrgent->mpTask );
439 Task *pTask = pMostUrgent->mpTask;
441 comphelper::ProfileZone aZone( pTask->GetDebugName() );
443 assert(!pMostUrgent->mbInScheduler);
444 pMostUrgent->mbInScheduler = true;
446 // always push the stack, as we don't traverse the whole list to push later
447 DropSchedulerData(rSchedCtx, pPrevMostUrgent, pMostUrgent, nMostUrgentPriority);
448 pMostUrgent->mpNext = rSchedCtx.mpSchedulerStack;
449 rSchedCtx.mpSchedulerStack = pMostUrgent;
450 rSchedCtx.mpSchedulerStackTop = pMostUrgent;
452 bool bIsHighPriorityIdle = pMostUrgent->mePriority >= TaskPriority::HIGH_IDLE;
454 // invoke the task
455 Unlock();
457 // Delay invoking tasks with idle priorities as long as there are user input or repaint events
458 // in the OS event queue. This will often effectively compress such events and repaint only
459 // once at the end, improving performance in cases such as repeated zooming with a complex document.
460 bool bDelayInvoking = bIsHighPriorityIdle &&
461 Application::AnyInput( VclInputFlags::MOUSE | VclInputFlags::KEYBOARD | VclInputFlags::PAINT );
464 * Current policy is that scheduler tasks aren't allowed to throw an exception.
465 * Because otherwise the exception is caught somewhere totally unrelated.
466 * TODO Ideally we could capture a proper backtrace and feed this into breakpad,
467 * which is do-able, but requires writing some assembly.
468 * See also SalUserEventList::DispatchUserEvents
472 if (bDelayInvoking)
473 SAL_INFO( "vcl.schedule", tools::Time::GetSystemTicks()
474 << " idle priority task " << pTask->GetDebugName()
475 << " delayed, system events pending" );
476 else
478 // prepare Scheduler object for deletion after handling
479 pTask->SetDeletionFlags();
480 pTask->Invoke();
483 catch (css::uno::Exception&)
485 TOOLS_WARN_EXCEPTION("vcl.schedule", "Uncaught");
486 std::abort();
488 catch (std::exception& e)
490 SAL_WARN("vcl.schedule", "Uncaught " << typeid(e).name() << " " << e.what());
491 std::abort();
493 catch (...)
495 SAL_WARN("vcl.schedule", "Uncaught exception during Task::Invoke()!");
496 std::abort();
498 Lock();
500 assert(pMostUrgent->mbInScheduler);
501 pMostUrgent->mbInScheduler = false;
503 SAL_INFO( "vcl.schedule", tools::Time::GetSystemTicks() << " "
504 << pMostUrgent << " invoke-out" );
506 // pop the scheduler stack
507 pSchedulerData = rSchedCtx.mpSchedulerStack;
508 assert(pSchedulerData == pMostUrgent);
509 rSchedCtx.mpSchedulerStack = pSchedulerData->mpNext;
511 // coverity[check_after_deref : FALSE] - pMostUrgent->mpTask is initially pMostUrgent->mpTask, but Task::Invoke can clear it
512 const bool bTaskAlive = pMostUrgent->mpTask && pMostUrgent->mpTask->IsActive();
513 if (!bTaskAlive)
515 if (pMostUrgent->mpTask)
516 pMostUrgent->mpTask->mpSchedulerData = nullptr;
517 delete pMostUrgent;
519 else
520 AppendSchedulerData(rSchedCtx, pMostUrgent);
522 // this just happens for nested calls, which renders all accounting
523 // invalid, so we just enforce a rescheduling!
524 if (rSchedCtx.mpSchedulerStackTop != pSchedulerData)
526 UpdateSystemTimer( rSchedCtx, ImmediateTimeoutMs, true,
527 tools::Time::GetSystemTicks() );
529 else if (bTaskAlive)
531 pMostUrgent->mnUpdateTime = nTime;
532 nReadyPeriod = pMostUrgent->mpTask->UpdateMinPeriod( nTime );
533 if ( nMinPeriod > nReadyPeriod )
534 nMinPeriod = nReadyPeriod;
535 UpdateSystemTimer( rSchedCtx, nMinPeriod, false, nTime );
539 void Scheduler::Wakeup()
541 Scheduler::ImplStartTimer( 0, false, tools::Time::GetSystemTicks() );
544 void Task::StartTimer( sal_uInt64 nMS )
546 Scheduler::ImplStartTimer( nMS, false, tools::Time::GetSystemTicks() );
549 void Task::SetDeletionFlags()
551 mbActive = false;
554 void Task::Start(const bool bStartTimer)
556 ImplSVData *const pSVData = ImplGetSVData();
557 ImplSchedulerContext &rSchedCtx = pSVData->maSchedCtx;
559 SchedulerGuard aSchedulerGuard;
560 if ( !rSchedCtx.mbActive )
561 return;
563 // is the task scheduled in the correct priority queue?
564 // if not we have to get a new data object, as we don't want to traverse
565 // the whole list to move the data to the correct list, as the task list
566 // is just single linked.
567 // Task priority doesn't change that often AFAIK, or we might need to
568 // start caching ImplSchedulerData objects.
569 if (mpSchedulerData && mpSchedulerData->mePriority != mePriority)
571 mpSchedulerData->mpTask = nullptr;
572 mpSchedulerData = nullptr;
574 mbActive = true;
576 if ( !mpSchedulerData )
578 // insert Task
579 ImplSchedulerData* pSchedulerData = new ImplSchedulerData;
580 pSchedulerData->mpTask = this;
581 pSchedulerData->mbInScheduler = false;
582 // mePriority is set in AppendSchedulerData
583 mpSchedulerData = pSchedulerData;
585 AppendSchedulerData( rSchedCtx, pSchedulerData );
586 SAL_INFO( "vcl.schedule", tools::Time::GetSystemTicks()
587 << " " << mpSchedulerData << " added " << *this );
589 else
590 SAL_INFO( "vcl.schedule", tools::Time::GetSystemTicks()
591 << " " << mpSchedulerData << " restarted " << *this );
593 mpSchedulerData->mnUpdateTime = tools::Time::GetSystemTicks();
595 if (bStartTimer)
596 Task::StartTimer(0);
599 void Task::Stop()
601 SAL_INFO_IF( mbActive, "vcl.schedule", tools::Time::GetSystemTicks()
602 << " " << mpSchedulerData << " stopped " << *this );
603 mbActive = false;
606 void Task::SetPriority(TaskPriority ePriority)
608 // you don't actually need to call Stop() before but Start() after, but we
609 // can't check that and don't know when Start() should be called.
610 SAL_WARN_IF(mpSchedulerData && mbActive, "vcl.schedule",
611 "Stop the task before changing the priority, as it will just "
612 "change after the task was scheduled with the old prio!");
613 mePriority = ePriority;
616 Task& Task::operator=( const Task& rTask )
618 if(this == &rTask)
619 return *this;
621 if ( IsActive() )
622 Stop();
624 mbActive = false;
625 mePriority = rTask.mePriority;
627 if ( rTask.IsActive() )
628 Start();
630 return *this;
633 Task::Task( const char *pDebugName )
634 : mpSchedulerData( nullptr )
635 , mpDebugName( pDebugName )
636 , mePriority( TaskPriority::DEFAULT )
637 , mbActive( false )
638 , mbStatic( false )
640 assert(mpDebugName);
643 Task::Task( const Task& rTask )
644 : mpSchedulerData( nullptr )
645 , mpDebugName( rTask.mpDebugName )
646 , mePriority( rTask.mePriority )
647 , mbActive( false )
648 , mbStatic( false )
650 assert(mpDebugName);
651 if ( rTask.IsActive() )
652 Start();
655 Task::~Task() COVERITY_NOEXCEPT_FALSE
657 if ( !IsStatic() )
659 SchedulerGuard aSchedulerGuard;
660 if ( mpSchedulerData )
661 mpSchedulerData->mpTask = nullptr;
663 else
664 assert(nullptr == mpSchedulerData || utl::ConfigManager::IsFuzzing());
667 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */