Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

Diff Revisions 693 vs 714 for /trunk/Source Code/Platform/Threading/Task.cpp

Diff revisions: vs.
  @@ -1,6 +1,6 @@
1 1 #include "Headers/Task.h"
2 2
3 - #include "Core/Headers/Kernel.h"
3 + #include "Core/Headers/TaskPool.h"
4 4 #include "Core/Headers/Console.h"
5 5 #include "Core/Headers/Application.h"
6 6 #include "Core/Time/Headers/ApplicationTimer.h"
  @@ -12,16 +12,22 @@
12 12 const bool g_DebugTaskStartStop = false;
13 13 };
14 14
15 - Task::Task() : GUIDWrapper(),
16 - _tp(nullptr),
17 - _poolIndex(0),
18 - _jobIdentifier(-1),
19 - _priority(TaskPriority::DONT_CARE)
15 + Task::Task()
16 + : GUIDWrapper(),
17 + _taskFlags(0),
18 + _tp(nullptr),
19 + _poolIndex(0),
20 + _jobIdentifier(-1),
21 + _priority(TaskPriority::DONT_CARE)
20 22 {
21 23 _parentTask = nullptr;
22 24 _childTaskCount = 0;
23 25 _done = true;
24 26 _stopRequested = false;
27 +
28 + if (g_DebugTaskStartStop) {
29 + SetBit(_taskFlags, to_const_uint(TaskFlags::PRINT_DEBUG_INFO));
30 + }
25 31 }
26 32
27 33 Task::~Task()
  @@ -45,7 +51,9 @@
45 51 _childTaskCount = 0;
46 52 }
47 53
48 - void Task::startTask(TaskPriority priority) {
54 + void Task::startTask(TaskPriority priority, U32 taskFlags) {
55 + SetBit(_taskFlags, taskFlags);
56 +
49 57 assert(!isRunning());
50 58
51 59 _done = false;
  @@ -105,10 +113,15 @@
105 113
106 114 void Task::run() {
107 115 waitForChildren(true, -1L);
108 - if (g_DebugTaskStartStop) {
116 +
117 + if (BitCompare(_taskFlags, to_const_uint(TaskFlags::PRINT_DEBUG_INFO))) {
109 118 Console::d_printfn(Locale::get(_ID("TASK_RUN_IN_THREAD")), getGUID(), std::this_thread::get_id());
110 119 }
111 120
121 + if (BitCompare(_taskFlags, to_const_uint(TaskFlags::SYNC_WITH_GPU))) {
122 + beginSyncGPU();
123 + }
124 +
112 125 if (!Application::instance().ShutdownRequested()) {
113 126
114 127 if (_callback) {
  @@ -123,14 +136,26 @@
123 136 _parentTask->_childTaskCount -= 1;
124 137 }
125 138
126 - if (g_DebugTaskStartStop) {
127 - Console::d_printfn(Locale::get(_ID("TASK_COMPLETE_IN_THREAD")), getGUID(), std::this_thread::get_id());
128 - }
129 -
130 139 _done = true;
131 140
132 141 std::unique_lock<std::mutex> lk(_taskDoneMutex);
133 142 _taskDoneCV.notify_one();
143 +
144 + if (BitCompare(_taskFlags, to_const_uint(TaskFlags::PRINT_DEBUG_INFO))) {
145 + Console::d_printfn(Locale::get(_ID("TASK_COMPLETE_IN_THREAD")), getGUID(), std::this_thread::get_id());
146 + }
147 +
148 + if (BitCompare(_taskFlags, to_const_uint(TaskFlags::SYNC_WITH_GPU))) {
149 + endSyncGPU();
150 + }
151 + }
152 +
153 + void Task::beginSyncGPU() {
154 + Attorney::ApplicationTask::syncThreadToGPU(std::this_thread::get_id(), true);
155 + }
156 +
157 + void Task::endSyncGPU() {
158 + Attorney::ApplicationTask::syncThreadToGPU(std::this_thread::get_id(), false);
134 159 }
135 160
136 161 };