Files
XCEngine/docs/api/threading/task-system/task-system.md
ssdfasd 0f0ab8922a docs: fix naming conventions across threading, math, memory, core, and debug modules
threading/:
- Rename 19 camelCase method files to hyphenated names
- task-system: createtaskgroup→create-task-group, etc.
- tasksystemconfig: enabletaskprofiling→enable-task-profiling, etc.
- thread: getcurrentid→get-current-id, etc.
- task: addref→add-ref, getid→get-id, etc.

math/:
- Rename underscore operator files to hyphenated
- vector3: operator_add→operator-add, etc.
- matrix4: gettranslation→get-translation, etc.
- vector4: tovector3→to-vector3, constructor_vector3→constructor-vector3
- sphere: sphere_constructor→sphere-constructor, etc.

memory/:
- Remove duplicate memorymanager/ folder (kept manager/ which was correct)

core/:
- filewriter: Consolidate ctor-default.md and ctor-file.md into constructor.md
- Rename dtor.md→destructor.md

debug/:
- filelogsink: Rename construct.md→constructor.md, ~filelogsink.md→destructor.md

All overview pages updated with new file references.
2026-03-22 23:09:29 +08:00

2.5 KiB
Raw Blame History

TaskSystem

命名空间: XCEngine::Threading

类型: class (singleton)

头文件: XCEngine/Threading/TaskSystem.h

描述: 并行任务调度系统单例,提供优先级任务队列。

概述

TaskSystem 是 XCEngine 的核心并行任务调度系统。它创建多个工作线程,使用优先级队列调度任务。它还提供 ParallelFor 方法用于数据级并行,以及主线程任务队列。

注意: 当前实现的 stealTasks 配置项未生效,任务系统使用单一全局优先级任务队列。

单例访问

方法 描述
Get 获取单例实例

公共方法

方法 描述
TaskSystem() 私有构造函数(单例)
~TaskSystem() 析构函数
Initialize 初始化任务系统
Shutdown 关闭任务系统
Submit(unique_ptr) 提交任务对象
Submit(callback) 提交 lambda 任务
CreateTaskGroup 创建任务组
DestroyTaskGroup 销毁任务组
Wait 等待指定任务完成(当前为空实现)
GetWorkerThreadCount 获取工作线程数量
ParallelFor 并行执行 for 循环
RunOnMainThread 将任务提交到主线程执行
Update 在主线程中处理主线程队列

使用示例

// 初始化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();

相关文档