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 #ifndef INCLUDED_VCL_SCHEDULER_HXX
21 #define INCLUDED_VCL_SCHEDULER_HXX
23 #include <vcl/dllapi.h>
27 class VCL_DLLPUBLIC Scheduler
33 static void ImplStartTimer ( sal_uInt64 nMS
, bool bForce
= false );
36 static constexpr sal_uInt64 ImmediateTimeoutMs
= 1;
37 static constexpr sal_uInt64 InfiniteTimeoutMs
= 1000 * 60 * 60 * 24; // 1 day
39 static void ImplDeInitScheduler();
41 /// Process one pending Timer with highhest priority
42 static void CallbackTaskScheduling( bool ignore
);
43 /// Calculate minimum timeout - and return its value.
44 static sal_uInt64
CalculateMinimumTimeout( bool &bHasActiveIdles
);
45 /// Process one pending task ahead of time with highest priority.
46 static bool ProcessTaskScheduling( bool bIdle
);
48 * Process events until the parameter turns true,
49 * allows processing until a specific event has been processed
51 static void ProcessEventsToIdle();
52 static void ProcessEventsToSignal(bool& bSignal
);
54 /// Control the deterministic mode. In this mode, two subsequent runs of
55 /// LibreOffice fire about the same amount idles.
56 static void SetDeterministicMode(bool bDeterministic
);
57 /// Return the current state of deterministic mode.
58 static bool GetDeterministicMode();
62 struct ImplSchedulerData
;
64 enum class TaskPriority
78 class VCL_DLLPUBLIC Task
80 friend class Scheduler
;
81 friend struct ImplSchedulerData
;
83 ImplSchedulerData
*mpSchedulerData
; /// Pointer to the element in scheduler list
84 const sal_Char
*mpDebugName
; /// Useful for debugging
85 TaskPriority mePriority
; /// Task priority
86 bool mbActive
; /// Currently in the scheduler
89 static void StartTimer( sal_uInt64 nMS
);
91 const ImplSchedulerData
* GetSchedulerData() const { return mpSchedulerData
; }
93 virtual void SetDeletionFlags();
94 /// Is this item ready to be dispatched at nTimeNow
95 virtual bool ReadyForSchedule( bool bIdle
, sal_uInt64 nTimeNow
) const = 0;
96 /// Schedule only when other timers and events are processed
97 virtual bool IsIdle() const = 0;
99 * Adjust nMinPeriod downwards if we want to be notified before
100 * then, nTimeNow is the current time.
102 virtual sal_uInt64
UpdateMinPeriod( sal_uInt64 nMinPeriod
, sal_uInt64 nTimeNow
) const = 0;
105 Task( const sal_Char
*pDebugName
);
106 Task( const Task
& rTask
);
108 Task
& operator=( const Task
& rTask
);
110 void SetPriority(TaskPriority ePriority
) { mePriority
= ePriority
; }
111 TaskPriority
GetPriority() const { return mePriority
; }
113 void SetDebugName( const sal_Char
*pDebugName
) { mpDebugName
= pDebugName
; }
114 const char *GetDebugName() const { return mpDebugName
; }
117 virtual void Invoke() = 0;
119 virtual void Start();
122 bool IsActive() const { return mbActive
; }
125 #endif // INCLUDED_VCL_SCHEDULER_HXX
127 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */