MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / OnCancel

Method OnCancel

Source/Engine/Threading/Task.cpp:200–222  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

198}
199
200void Task::OnCancel()
201{
202 // Set flag
203 Platform::InterlockedIncrement(&_cancelFlag);
204 Platform::MemoryBarrier();
205
206 // If task is active try to wait for a while
207 if (IsRunning())
208 {
209 // Wait for it a little bit
210 constexpr double timeout = 10000.0; // 10s
211 //LOG(Warning, "Cannot cancel \'{0}\' because it's still running, waiting for end with timeout: {1}ms", ToString(), timeout);
212 Wait(timeout);
213 }
214
215 // Don't call OnEnd twice
216 const auto state = GetState();
217 if (state != TaskState::Finished && state != TaskState::Failed)
218 {
219 SetState(TaskState::Canceled);
220 OnEnd();
221 }
222}
223
224void Task::OnEnd()
225{

Callers

nothing calls this directly

Calls 7

SetStateFunction · 0.85
OnEndFunction · 0.85
IsRunningFunction · 0.70
WaitFunction · 0.70
InterlockedIncrementFunction · 0.50
MemoryBarrierFunction · 0.50
GetStateFunction · 0.50

Tested by

no test coverage detected