2017-02-02 17:21:23 +01:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following license notice:
|
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef INCLUDED_VCL_TASK_HXX
|
|
|
|
#define INCLUDED_VCL_TASK_HXX
|
|
|
|
|
|
|
|
#include <vcl/dllapi.h>
|
|
|
|
|
|
|
|
struct ImplSchedulerData;
|
|
|
|
|
|
|
|
enum class TaskPriority
|
|
|
|
{
|
Reorganize Scheduler priority classes
This is based on glibs classification of tasks, but while glib uses
an int for more fine grained priority, we stay with our enum.
1. Timers start with DEFAULT priority, which directly corresponds
with the previous HIGH priority
2. Idles start with DEFAULT_IDLE priority instead of the previous
HIGH priority, so idle default becomes "really run when idle".
As RESIZE and REPAINT are special, and the DEFAULTS are set, there
is just one primary decision for the programmer: should my idle
run before paint (AKA HIGH_IDLE)?
If we really need a more fine-grained classification, we can add it
later, or also switch to a real int. As a result, this drops many
classifications from the code and drastically changes behaviour,
AKA a mail merge from KDE is now as fast as Gtk+ again.
Change-Id: I498a73fd02d5fb6f5d7e9f742f3bce972de9b1f9
2016-08-10 12:00:53 +02:00
|
|
|
HIGHEST, ///< These events should run very fast!
|
|
|
|
DEFAULT, ///< Default priority used, e.g. the default timer priority
|
|
|
|
HIGH_IDLE, ///< Important idle events to be run before processing drawing events
|
|
|
|
RESIZE, ///< Resize runs before repaint, so we won't paint twice
|
|
|
|
REPAINT, ///< All repaint events should go in here
|
|
|
|
POST_PAINT, ///< Everything running directly after painting
|
|
|
|
DEFAULT_IDLE, ///< Default idle priority
|
|
|
|
LOWEST ///< Low, very idle cleanup tasks
|
2017-02-02 17:21:23 +01:00
|
|
|
};
|
|
|
|
|
2018-09-16 19:17:31 +00:00
|
|
|
#define PRIO_COUNT (static_cast<int>(TaskPriority::LOWEST) + 1)
|
|
|
|
|
2017-02-02 17:21:23 +01:00
|
|
|
class VCL_DLLPUBLIC Task
|
|
|
|
{
|
|
|
|
friend class Scheduler;
|
|
|
|
friend struct ImplSchedulerData;
|
|
|
|
|
|
|
|
ImplSchedulerData *mpSchedulerData; ///< Pointer to the element in scheduler list
|
2019-12-24 10:47:38 +02:00
|
|
|
const char *mpDebugName; ///< Useful for debugging
|
2017-02-02 17:21:23 +01:00
|
|
|
TaskPriority mePriority; ///< Task priority
|
|
|
|
bool mbActive; ///< Currently in the scheduler
|
2017-08-23 16:07:50 +02:00
|
|
|
bool mbStatic; ///< Is a static object
|
2017-02-02 17:21:23 +01:00
|
|
|
|
|
|
|
protected:
|
|
|
|
static void StartTimer( sal_uInt64 nMS );
|
|
|
|
|
|
|
|
const ImplSchedulerData* GetSchedulerData() const { return mpSchedulerData; }
|
|
|
|
|
|
|
|
virtual void SetDeletionFlags();
|
2017-01-29 17:12:25 +01:00
|
|
|
|
2017-02-02 17:21:23 +01:00
|
|
|
/**
|
2017-01-29 17:12:25 +01:00
|
|
|
* How long (in MS) until the Task is ready to be dispatched?
|
|
|
|
*
|
|
|
|
* Simply return Scheduler::ImmediateTimeoutMs if you're ready, like an
|
|
|
|
* Idle. If you have to return Scheduler::InfiniteTimeoutMs, you probably
|
2018-08-15 14:18:38 +02:00
|
|
|
* need another mechanism to wake up the Scheduler or rely on other
|
2017-01-29 17:12:25 +01:00
|
|
|
* Tasks to be scheduled, or simply use a polling Timer.
|
|
|
|
*
|
|
|
|
* @param nTimeNow the current time
|
|
|
|
* @return the sleep time of the Task to become ready
|
2017-02-02 17:21:23 +01:00
|
|
|
*/
|
2019-10-17 16:17:45 +02:00
|
|
|
virtual sal_uInt64 UpdateMinPeriod( sal_uInt64 nTimeNow ) const = 0;
|
2017-02-02 17:21:23 +01:00
|
|
|
|
|
|
|
public:
|
2019-12-24 10:47:38 +02:00
|
|
|
Task( const char *pDebugName );
|
2017-02-02 17:21:23 +01:00
|
|
|
Task( const Task& rTask );
|
|
|
|
virtual ~Task() COVERITY_NOEXCEPT_FALSE;
|
|
|
|
Task& operator=( const Task& rTask );
|
|
|
|
|
2019-03-13 01:23:36 +01:00
|
|
|
void SetPriority(TaskPriority ePriority);
|
2017-02-02 17:21:23 +01:00
|
|
|
TaskPriority GetPriority() const { return mePriority; }
|
|
|
|
|
2019-12-24 10:47:38 +02:00
|
|
|
void SetDebugName( const char *pDebugName ) { mpDebugName = pDebugName; }
|
2017-02-02 17:21:23 +01:00
|
|
|
const char *GetDebugName() const { return mpDebugName; }
|
|
|
|
|
|
|
|
// Call handler
|
|
|
|
virtual void Invoke() = 0;
|
|
|
|
|
|
|
|
virtual void Start();
|
|
|
|
void Stop();
|
|
|
|
|
|
|
|
bool IsActive() const { return mbActive; }
|
2017-08-23 16:07:50 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This function must be called for static tasks, so the Task destructor
|
|
|
|
* ignores the SchedulerMutex, as it may not be available anymore.
|
|
|
|
* The cleanup is still correct, as it has already happened in
|
|
|
|
* DeInitScheduler call well before the static destructor calls.
|
|
|
|
*/
|
|
|
|
void SetStatic() { mbStatic = true; }
|
|
|
|
bool IsStatic() const { return mbStatic; }
|
2017-02-02 17:21:23 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // INCLUDED_VCL_TASK_HXX
|
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|