Difference between revisions of "CXTask"
From cxwiki
Line 1: | Line 1: | ||
− | <div class="mw-parser-output"><div class="mw-parser-output">The CXTask class provides a mechanism for applications to request regular updates in a non-threaded manner. The application derives from CXTask and provides a CXTask::Idle() override which is called once per task update. Each CXTask must be registered with a CXTaskHost in order to receive updates.</div> <div class="mw-parser-output"> </div> <div class="mw-parser-output">Updates occur whenever the CXTaskHost::IdleTasks() function is called, which (with the exception of the main thread task host in an application) is NOT automatic.</div> <div class="mw-parser-output"> </div> | + | <div class="mw-parser-output"><div class="mw-parser-output"><div class="mw-parser-output">The CXTask class provides a mechanism for applications to request regular updates in a non-threaded manner. The application derives from CXTask and provides a CXTask::Idle() override which is called once per task update. Each CXTask must be registered with a CXTaskHost in order to receive updates.</div> <div class="mw-parser-output"> </div> <div class="mw-parser-output">Updates occur whenever the CXTaskHost::IdleTasks() function is called, which (with the exception of the main thread task host in an application) is NOT automatic.</div> <div class="mw-parser-output"> </div> |
= Thread Task Hosts = | = Thread Task Hosts = | ||
Line 9: | Line 9: | ||
<div class="mw-parser-output">Background threads do not automatically receive task hosts. If they will use task host functionality, they must explicitly create, update, and destroy the thread task host as required.</div> | <div class="mw-parser-output">Background threads do not automatically receive task hosts. If they will use task host functionality, they must explicitly create, update, and destroy the thread task host as required.</div> | ||
= Additional Task Hosts = | = Additional Task Hosts = | ||
− | <div class="mw-parser-output">It is also possible to create arbitrary task hosts, and update them on a custom schedule.</div> <div class="mw-parser-output"> </div> <div class="mw-parser-output"> </div> </div> | + | <div class="mw-parser-output">It is also possible to create arbitrary task hosts, and update them on a custom schedule.</div> <div class="mw-parser-output"> </div> |
+ | = CXTaskHost = | ||
+ | <div class="mw-parser-output"><syntaxhighlight lang="c++">// | ||
+ | void IdleTasks(void); | ||
+ | |||
+ | |||
+ | // | ||
+ | void AddTask(CXTask* task); | ||
+ | |||
+ | // | ||
+ | void RemoveTask(CXTask* task); | ||
+ | |||
+ | |||
+ | // | ||
+ | static void InitCurrentThreadTaskHost(void); | ||
+ | |||
+ | // | ||
+ | static void KillCurrentThreadTaskHost(void); | ||
+ | |||
+ | // | ||
+ | static CXTaskHost& GetCurrentThreadTaskHost(void); | ||
+ | |||
+ | // | ||
+ | static CXTaskHost& GetThreadTaskHost(CXThreadID threadID); | ||
+ | |||
+ | // | ||
+ | static bool HasCurrentThreadTaskHost(void); | ||
+ | |||
+ | // | ||
+ | static bool HasThreadTaskHost(CXThreadID threadID);</syntaxhighlight> | ||
+ | |||
+ | | ||
+ | </div> <div class="mw-parser-output"> </div> | ||
+ | = CXTask = | ||
+ | <div class="mw-parser-output"><syntaxhighlight lang="c++">// | ||
+ | explicit CXTask(const char* taskName); | ||
+ | |||
+ | // | ||
+ | virtual void Idle(void) = 0; | ||
+ | |||
+ | // | ||
+ | CXTaskHost* GetTaskHost(void); | ||
+ | |||
+ | // | ||
+ | const char* GetDebugTaskName(void) const;</syntaxhighlight> | ||
+ | |||
+ | | ||
+ | </div> <div class="mw-parser-output"> </div> <div class="mw-parser-output"> </div> <div class="mw-parser-output"> </div> </div> </div> |
Revision as of 18:35, 26 February 2018
The CXTask class provides a mechanism for applications to request regular updates in a non-threaded manner. The application derives from CXTask and provides a CXTask::Idle() override which is called once per task update. Each CXTask must be registered with a CXTaskHost in order to receive updates.
Updates occur whenever the CXTaskHost::IdleTasks() function is called, which (with the exception of the main thread task host in an application) is NOT automatic.
Contents
Thread Task Hosts
Each thread may have a singleton CXTaskHost object. This object is created via CXTaskHost::InitCurrentThreadTaskHost(), accessed via CXTasskHost::GetCurrentThreadTaskHost(), and finally destroyed via CXTaskHost::KillCurrentThreadTaskHost(). The thread may trigger a task update by calling CXTaskHost::GetCurrentThreadTaskHost().IdleTasks().
Main Thread Task Host
The main thread task host is created automatically during cxsource initialisation, and is destroyed automatically during cxsource shutdown. In a standard event-driven application, the main thread task host is updated on a regular basis via the main event loop. In other processes, such as a command-line tool, the application must explicitly update the main thread task host on a regular basis.
Background Thread Task Hosts
Background threads do not automatically receive task hosts. If they will use task host functionality, they must explicitly create, update, and destroy the thread task host as required.
Additional Task Hosts
It is also possible to create arbitrary task hosts, and update them on a custom schedule.
CXTaskHost
//
void IdleTasks(void);
//
void AddTask(CXTask* task);
//
void RemoveTask(CXTask* task);
//
static void InitCurrentThreadTaskHost(void);
//
static void KillCurrentThreadTaskHost(void);
//
static CXTaskHost& GetCurrentThreadTaskHost(void);
//
static CXTaskHost& GetThreadTaskHost(CXThreadID threadID);
//
static bool HasCurrentThreadTaskHost(void);
//
static bool HasThreadTaskHost(CXThreadID threadID);
CXTask
//
explicit CXTask(const char* taskName);
//
virtual void Idle(void) = 0;
//
CXTaskHost* GetTaskHost(void);
//
const char* GetDebugTaskName(void) const;