1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <tools/time.hxx>
21 #include <vcl/timer.hxx>
22 #include <saltimer.hxx>
24 #include <salinst.hxx>
26 #define MAX_TIMER_PERIOD SAL_MAX_UINT64
28 void Timer::ImplStartTimer( ImplSVData
* pSVData
, sal_uInt64 nMS
)
35 // Assume underlying timers are recurring timers, if same period - just wait.
36 if ( nMS
!= pSVData
->mnTimerPeriod
)
38 pSVData
->mnTimerPeriod
= nMS
;
39 pSVData
->mpSalTimer
->Start( nMS
);
43 void Timer::SetDeletionFlags()
45 // if no AutoTimer than stop
48 mpSchedulerData
->mbDelete
= true;
53 bool Timer::ReadyForSchedule( bool bTimer
)
56 return (mpSchedulerData
->mnUpdateTime
+ mnTimeout
) <= tools::Time::GetSystemTicks();
59 sal_uInt64
Timer::UpdateMinPeriod( sal_uInt64 nMinPeriod
, sal_uInt64 nTime
)
61 sal_uInt64 nNewTime
= tools::Time::GetSystemTicks();
62 sal_uInt64 nDeltaTime
;
63 //determine smallest time slot
64 if( mpSchedulerData
->mnUpdateTime
== nTime
)
66 nDeltaTime
= mnTimeout
;
67 if( nDeltaTime
< nMinPeriod
)
68 nMinPeriod
= nDeltaTime
;
72 nDeltaTime
= mpSchedulerData
->mnUpdateTime
+ mnTimeout
;
73 if( nDeltaTime
< nNewTime
)
77 nDeltaTime
-= nNewTime
;
78 if( nDeltaTime
< nMinPeriod
)
79 nMinPeriod
= nDeltaTime
;
87 * Initialize the platform specific timer on which all the
88 * platform independent timers are built
90 void Timer::InitSystemTimer()
92 ImplSVData
* pSVData
= ImplGetSVData();
93 if( ! pSVData
->mpSalTimer
)
95 pSVData
->mnTimerPeriod
= MAX_TIMER_PERIOD
;
96 pSVData
->mpSalTimer
= pSVData
->mpDefInst
->CreateSalTimer();
97 pSVData
->mpSalTimer
->SetCallback( CallbackTaskScheduling
);
101 Timer::Timer(const sal_Char
*pDebugName
) : Scheduler(pDebugName
)
105 mePriority
= SchedulerPriority::HIGHEST
;
108 Timer::Timer( const Timer
& rTimer
) : Scheduler(rTimer
)
110 mnTimeout
= rTimer
.mnTimeout
;
111 mbAuto
= rTimer
.mbAuto
;
112 maTimeoutHdl
= rTimer
.maTimeoutHdl
;
117 maTimeoutHdl
.Call( this );
124 ImplSVData
* pSVData
= ImplGetSVData();
125 if ( mnTimeout
< pSVData
->mnTimerPeriod
)
126 Timer::ImplStartTimer( pSVData
, mnTimeout
);
129 void Timer::SetTimeout( sal_uInt64 nNewTimeout
)
131 mnTimeout
= nNewTimeout
;
132 // if timer is active then renew clock
135 ImplSVData
* pSVData
= ImplGetSVData();
136 if ( !pSVData
->mnUpdateStack
&& (mnTimeout
< pSVData
->mnTimerPeriod
) )
137 Timer::ImplStartTimer( pSVData
, mnTimeout
);
141 Timer
& Timer::operator=( const Timer
& rTimer
)
143 Scheduler::operator=(rTimer
);
144 maTimeoutHdl
= rTimer
.maTimeoutHdl
;
145 mnTimeout
= rTimer
.mnTimeout
;
146 mbAuto
= rTimer
.mbAuto
;
150 AutoTimer::AutoTimer()
155 AutoTimer::AutoTimer( const AutoTimer
& rTimer
) : Timer( rTimer
)
160 AutoTimer
& AutoTimer::operator=( const AutoTimer
& rTimer
)
162 Timer::operator=( rTimer
);
165 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */