/src/libreoffice/include/vcl/task.hxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
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/. |
8 | | * |
9 | | * This file incorporates work covered by the following license notice: |
10 | | * |
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 . |
18 | | */ |
19 | | |
20 | | #ifndef INCLUDED_VCL_TASK_HXX |
21 | | #define INCLUDED_VCL_TASK_HXX |
22 | | |
23 | | #include <vcl/dllapi.h> |
24 | | |
25 | | struct ImplSchedulerData; |
26 | | |
27 | | enum class TaskPriority |
28 | | { |
29 | | HIGHEST, ///< These events should run very fast! |
30 | | DEFAULT, ///< Default priority used, e.g. the default timer priority |
31 | | // Input from the OS event queue is processed before HIGH_IDLE tasks. |
32 | | HIGH_IDLE, ///< Important idle events to be run before processing drawing events |
33 | | RESIZE, ///< Resize runs before repaint, so we won't paint twice |
34 | | REPAINT, ///< All repaint events should go in here |
35 | | SKIA_FLUSH, ///< tdf#165277 Skia needs to flush immediately before POST_PAINT tasks on macOS |
36 | | POST_PAINT, ///< Everything running directly after painting |
37 | | DEFAULT_IDLE, ///< Default idle priority |
38 | | LOWEST, ///< Low, very idle cleanup tasks |
39 | | TOOLKIT_DEBUG ///< Do not use. Solely for IdleTask::waitUntilIdleDispatched |
40 | | }; |
41 | | |
42 | 71.9k | #define PRIO_COUNT (static_cast<int>(TaskPriority::TOOLKIT_DEBUG) + 1) |
43 | | |
44 | | class VCL_DLLPUBLIC Task |
45 | | { |
46 | | friend class Scheduler; |
47 | | friend struct ImplSchedulerData; |
48 | | |
49 | | ImplSchedulerData *mpSchedulerData; ///< Pointer to the element in scheduler list |
50 | | const char *mpDebugName; ///< Useful for debugging |
51 | | TaskPriority mePriority; ///< Task priority |
52 | | bool mbActive; ///< Currently in the scheduler |
53 | | bool mbStatic; ///< Is a static object |
54 | | |
55 | | protected: |
56 | | static void StartTimer( sal_uInt64 nMS ); |
57 | | |
58 | 6.13k | const ImplSchedulerData* GetSchedulerData() const { return mpSchedulerData; } |
59 | | |
60 | | virtual void SetDeletionFlags(); |
61 | | |
62 | | /** |
63 | | * How long (in MS) until the Task is ready to be dispatched? |
64 | | * |
65 | | * Simply return Scheduler::ImmediateTimeoutMs if you're ready, like an |
66 | | * Idle. If you have to return Scheduler::InfiniteTimeoutMs, you probably |
67 | | * need another mechanism to wake up the Scheduler or rely on other |
68 | | * Tasks to be scheduled, or simply use a polling Timer. |
69 | | * |
70 | | * @param nTimeNow the current time |
71 | | * @return the sleep time of the Task to become ready |
72 | | */ |
73 | | virtual sal_uInt64 UpdateMinPeriod( sal_uInt64 nTimeNow ) const = 0; |
74 | | |
75 | | public: |
76 | | Task( const char *pDebugName ); |
77 | | Task( const Task& rTask ); |
78 | | virtual ~Task(); |
79 | | Task& operator=( const Task& rTask ); |
80 | | |
81 | | void SetPriority(TaskPriority ePriority); |
82 | 55.6k | TaskPriority GetPriority() const { return mePriority; } |
83 | | |
84 | 7.75k | const char *GetDebugName() const { return mpDebugName; } |
85 | | |
86 | | virtual bool DecideTransferredExecution(); |
87 | | |
88 | | // Call handler |
89 | | virtual void Invoke() = 0; |
90 | | |
91 | | /** |
92 | | * Schedules the task for execution |
93 | | * |
94 | | * If the timer is already active, it's reset! |
95 | | * Check with Task::IsActive() to prevent reset. |
96 | | * |
97 | | * If you unset bStartTimer, the Task must call Task::StartTimer(...) to be correctly scheduled! |
98 | | * Otherwise it might just be picked up when the Scheduler runs the next time. |
99 | | * |
100 | | * @param bStartTimer if false, don't schedule the Task by calling Task::StartTimer(0). |
101 | | */ |
102 | | virtual void Start(bool bStartTimer = true); |
103 | | void Stop(); |
104 | | |
105 | 4.58M | bool IsActive() const { return mbActive; } |
106 | | |
107 | | /** |
108 | | * This function must be called for static tasks, so the Task destructor |
109 | | * ignores the scheduler mutex, as it may not be available anymore. |
110 | | * The cleanup is still correct, as it has already happened in |
111 | | * DeInitScheduler call well before the static destructor calls. |
112 | | */ |
113 | 55 | void SetStatic() { mbStatic = true; } |
114 | 4.06M | bool IsStatic() const { return mbStatic; } |
115 | | }; |
116 | | |
117 | | #endif // INCLUDED_VCL_TASK_HXX |
118 | | |
119 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |