fix: improve doc link navigation and tree display
- Fix link resolution with proper relative/absolute path handling - Improve link styling with underline decoration - Hide leaf nodes from tree, only show directories - Fix log file path for packaged app
This commit is contained in:
82
docs/api/threading/task-system/task-system.md
Normal file
82
docs/api/threading/task-system/task-system.md
Normal file
@@ -0,0 +1,82 @@
|
||||
# TaskSystem
|
||||
|
||||
**命名空间**: `XCEngine::Threading`
|
||||
|
||||
**类型**: `class` (singleton)
|
||||
|
||||
**头文件**: `XCEngine/Threading/TaskSystem.h`
|
||||
|
||||
**描述**: 并行任务调度系统单例,提供优先级任务队列。
|
||||
|
||||
## 概述
|
||||
|
||||
`TaskSystem` 是 XCEngine 的核心并行任务调度系统。它创建多个工作线程,使用优先级队列调度任务。它还提供 `ParallelFor` 方法用于数据级并行,以及主线程任务队列。
|
||||
|
||||
**注意:** 当前实现的 `stealTasks` 配置项未生效,任务系统使用单一全局任务队列而非工作窃取模式。
|
||||
|
||||
## 单例访问
|
||||
|
||||
| 方法 | 描述 |
|
||||
|------|------|
|
||||
| [`Get`](get.md) | 获取单例实例 |
|
||||
|
||||
## 公共方法
|
||||
|
||||
| 方法 | 描述 |
|
||||
|------|------|
|
||||
| [`Get`](get.md) | 获取单例实例 |
|
||||
| [`Initialize`](initialize.md) | 初始化任务系统 |
|
||||
| [`Shutdown`](shutdown.md) | 关闭任务系统 |
|
||||
| [`Submit(unique_ptr)`](submit.md) | 提交任务对象 |
|
||||
| [`Submit(callback)`](submit.md) | 提交 lambda 任务 |
|
||||
| [`CreateTaskGroup`](createtaskgroup.md) | 创建任务组 |
|
||||
| [`DestroyTaskGroup`](destroytaskgroup.md) | 销毁任务组 |
|
||||
| [`Wait`](wait.md) | 等待指定任务完成(当前为空实现) |
|
||||
| [`GetWorkerThreadCount`](getworkerthreadcount.md) | 获取工作线程数量 |
|
||||
| [`ParallelFor`](parallelfor.md) | 并行执行 for 循环 |
|
||||
| [`RunOnMainThread`](runonmainthread.md) | 将任务提交到主线程执行 |
|
||||
| [`Update`](update.md) | 在主线程中处理主线程队列 |
|
||||
|
||||
## 使用示例
|
||||
|
||||
```cpp
|
||||
// 初始化(4 个工作线程)
|
||||
TaskSystemConfig config;
|
||||
config.workerThreadCount = 4;
|
||||
TaskSystem::Get().Initialize(config);
|
||||
|
||||
// 提交任务
|
||||
TaskSystem::Get().Submit([]() {
|
||||
printf("Task 1 running\n");
|
||||
});
|
||||
|
||||
TaskSystem::Get().Submit([]() {
|
||||
printf("Task 2 running\n");
|
||||
}, TaskPriority::High);
|
||||
|
||||
// 并行 for
|
||||
TaskSystem::Get().ParallelFor(0, 1000, [](int32_t i) {
|
||||
process(i);
|
||||
});
|
||||
|
||||
// 主线程任务
|
||||
TaskSystem::Get().RunOnMainThread([]() {
|
||||
// 更新 UI 或其他主线程操作
|
||||
});
|
||||
|
||||
// 主循环中调用 Update
|
||||
while (running) {
|
||||
TaskSystem::Get().Update(); // 处理主线程任务
|
||||
}
|
||||
|
||||
// 关闭
|
||||
TaskSystem::Get().Shutdown();
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [ITask](../task/task.md) - 任务基类
|
||||
- [LambdaTask](../lambdatask/lambdatask.md) - Lambda 任务
|
||||
- [TaskGroup](../task-group/task-group.md) - 任务组
|
||||
- [TaskSystemConfig](../tasksystemconfig/tasksystemconfig.md) - 配置
|
||||
- [../threading/threading.md](../threading.md) - 模块总览
|
||||
Reference in New Issue
Block a user