Files
XCEngine/docs/api/threading/task/task.md
ssdfasd dc850d7739 docs: 重构 API 文档结构并修正源码准确性
- 重组文档目录结构: 每个模块的概述页移动到模块子目录
- 重命名 index.md 为 main.md
- 修正所有模块文档中的错误:
  - math: FromEuler→FromEulerAngles, TransformDirection 包含缩放, Box 是 OBB, Color::ToRGBA 格式
  - containers: 新增 operator==/!= 文档, 补充 std::hash DJB 算法细节
  - core: 修复 types 链接错误
  - debug: LogLevelToString 返回大写, timestamp 是秒, Profiler 空实现标注, Windows API vs ANSI
  - memory: 修复头文件路径, malloc vs operator new, 新增方法文档
  - resources: 修复 Shader/Texture 链接错误
  - threading: TaskSystem::Wait 空实现标注, ReadWriteLock 重入描述, LambdaTask 链接
- 验证: fix_links.py 确认 0 个断裂引用
2026-03-19 00:22:30 +08:00

98 lines
2.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# ITask
**命名空间**: `XCEngine::Threading`
**类型**: `class` (abstract)
**头文件**: `XCEngine/Threading/Task.h`
**描述**: 任务基类抽象接口和任务状态/优先级枚举定义。
## 概述
`ITask` 是任务系统的核心抽象基类。用户需要继承此类并实现 `Execute()` 方法来定义具体的任务逻辑。任务系统通过引用计数自动管理任务生命周期。
## TaskPriority 枚举
任务优先级枚举(数值越小优先级越高)。
| 值 | 描述 |
|----|------|
| `Critical` | 关键优先级0 |
| `High` | 高优先级1 |
| `Normal` | 普通优先级2 |
| `Low` | 低优先级3 |
| `Idle` | 空闲优先级4 |
## TaskStatus 枚举
任务状态枚举。
| 值 | 描述 |
|----|------|
| `Pending` | 等待中 |
| `Scheduled` | 已调度 |
| `Running` | 运行中 |
| `Completed` | 已完成 |
| `Failed` | 失败 |
| `Canceled` | 已取消 |
## ITask 公共方法
### 生命周期
| 方法 | 描述 |
|------|------|
| [`Execute`](execute.md) | 任务执行逻辑(纯虚) |
| [`OnComplete`](oncomplete.md) | 任务完成回调(可重写) |
| [`OnCancel`](oncancel.md) | 任务取消回调(可重写) |
### 属性
| 方法 | 描述 |
|------|------|
| [`GetPriority`](getpriority.md) | 获取优先级 |
| [`GetStatus`](getstatus.md) | 获取状态 |
| [`GetId`](getid.md) | 获取任务 ID |
| [`SetId`](setid.md) | 设置任务 ID |
| [`SetPriority`](setpriority.md) | 设置优先级 |
| [`SetStatus`](setstatus.md) | 设置状态 |
### 引用计数
| 方法 | 描述 |
|------|------|
| [`AddRef`](addref.md) | 增加引用计数 |
| [`Release`](release.md) | 减少引用计数(引用归零时自动 delete |
## 使用示例
```cpp
class MyTask : public ITask {
public:
explicit MyTask(int data) : m_data(data) {}
void Execute() override {
printf("Task executed with data: %d\n", m_data);
}
void OnComplete() override {
printf("Task completed\n");
}
private:
int m_data;
};
auto task = new MyTask(42);
task->SetPriority(TaskPriority::High);
TaskSystem::Get().Submit(std::unique_ptr<ITask>(task));
```
## 相关文档
- [LambdaTask](../lambdatask/lambdatask.md) - Lambda 任务封装
- [TaskGroup](../task-group/task-group.md) - 任务组
- [TaskSystem](../task-system/task-system.md) - 任务系统
- [../threading/threading.md](../threading.md) - 模块总览