1/// @brief Bare minimum task object (base class)
2/// @defgroup basictask BasicTask
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
12/// BasicTask does not support:
13/// - Task names or timing information (see Task)
14/// - Dependencies or scheduling (see ComplexTask)
15/// - Completion callbacks (see Task)
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>
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,
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 /// Log context captured when the task was added to a queue and restored around run(), so
36 /// records written on the worker thread still carry the submitter's log context.
37 /// Owned; use logCtx* to touch it.
39 /// Abstract method that derived classes must implement to define task behavior.
41 /// This method is called by the task queue system when the task is ready to execute.
42 /// Do not call this method directly. Derived classes must implement this to provide
43 /// the actual task logic.
44 /// @param tq Task queue this task is running on
45 /// @param worker Worker thread executing this task
46 /// @param tcon TaskControl structure for output parameters
47 /// @return TASK_Result_Success or TASK_Result_Failure
48 [abstract] uint32 run([in] TaskQueue *tq, [in] TQWorker *worker, [inout] TaskControl *tcon);
49 /// Called when task is cancelled before it can run.
50 /// @param tq Task queue the task was on
51 /// @param worker Worker that picked up the cancelled task
52 void runCancelled([in] TaskQueue *tq, [in] TQWorker *worker);
53 unbound bool _setState(uint32 newstate);
54 /// Request cancellation of this task.
55 /// @return true if cancellation was set
57 /// Reset task to initial state so it can be run again.
58 /// @return true if reset was successful
60 // declared explicitly because logctx is a plain pointer with an owned reference on it,
61 // which is not something the generator can clean up on its own