CX Framework
Cross-platform C utility framework
Loading...
Searching...
No Matches
basictask.cxh
1/// @brief Bare minimum task object (base class)
2/// @defgroup basictask BasicTask
3/// @ingroup tq_task
4/// @{
5///
6/// BasicTask is the bare minimum for a task object. It provides only:
7/// - Atomic state tracking (created, waiting, running, succeeded, failed)
8/// - A run() method to implement task logic
9/// - A runCancelled() callback for cleanup when cancelled
10/// - Cancel and reset functionality
11///
12/// BasicTask does not support:
13/// - Task names or timing information (see Task)
14/// - Dependencies or scheduling (see ComplexTask)
15/// - Completion callbacks (see Task)
16///
17/// Derive from BasicTask when you need the absolute minimum overhead for simple
18/// tasks that just need to run on a worker thread with no dependencies.
19#include <cx/taskqueue/taskqueue_shared.h>
20
21class TaskQueue;
22class TQWorker;
23struct TaskControl;
24
25/// Return values from BasicTask::run()
26enum BasicTaskRunResultEnum {
27 TASK_Result_Failure, ///< Task failed, will transition to TASK_Failed state
28 TASK_Result_Success, ///< Task succeeded, will transition to TASK_Succeeded state
29 TASK_Result_Basic_Count,
30};
31
32/// Bare minimum task object with state tracking and run method.
33[methodprefix btask] abstract class BasicTask {
34 atomic:uint32 state; ///< Current task state and flags
35 /// Abstract method that derived classes must implement to define task behavior.
36 ///
37 /// This method is called by the task queue system when the task is ready to execute.
38 /// Do not call this method directly. Derived classes must implement this to provide
39 /// the actual task logic.
40 /// @param tq Task queue this task is running on
41 /// @param worker Worker thread executing this task
42 /// @param tcon TaskControl structure for output parameters
43 /// @return TASK_Result_Success or TASK_Result_Failure
44 [abstract] uint32 run([in] TaskQueue *tq, [in] TQWorker *worker, [inout] TaskControl *tcon);
45 /// Called when task is cancelled before it can run.
46 /// @param tq Task queue the task was on
47 /// @param worker Worker that picked up the cancelled task
48 void runCancelled([in] TaskQueue *tq, [in] TQWorker *worker);
49 unbound bool _setState(uint32 newstate);
50 /// Request cancellation of this task.
51 /// @return true if cancellation was set
52 bool cancel();
53 /// Reset task to initial state so it can be run again.
54 /// @return true if reset was successful
55 bool reset();
56}
57/// @}