| 198 | } |
| 199 | |
| 200 | void 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 | |
| 224 | void Task::OnEnd() |
| 225 | { |
nothing calls this directly
no test coverage detected