CXTask

From cxwiki

Revision as of 23:23, 26 February 2018 by Windwalkr (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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.
 

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

// Causes this CXTaskHost to call Idle() for each registered CXTask.
void IdleTasks(void);


// Registers the specified task with this host. A task must be registered
// with only one host at a time.
void AddTask(CXTask* task);

// Unregisters the specified task from this host.
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;