| 2397 | break; |
| 2398 | case AsyncRequest::State::Free: |
| 2399 | // TODO: Not sure if we should error out here |
| 2400 | return SC::Result::Error(AsyncResultCategory, AsyncError::RequestNotActive); |
| 2401 | case AsyncRequest::State::Cancelling: |
| 2402 | // Already Cancelling, but now we update the stop function |
| 2403 | break; |
| 2404 | } |
| 2405 | return Result(true); |
| 2406 | } |
| 2407 | |
| 2408 | SC::Result SC::AsyncEventLoop::Internal::unscheduleLoopTimeout(AsyncLoopTimeout& timeout) |
| 2409 | { |
| 2410 | if (timeout.sequence != nullptr) |
| 2411 | return Result::Error(AsyncResultCategory, AsyncError::SequencedTimeout); |
| 2412 | switch (timeout.state) |
| 2413 | { |
| 2414 | case AsyncRequest::State::Free: timeout.closeCallback = nullptr; return Result(true); |
| 2415 | case AsyncRequest::State::Setup: |
| 2416 | timeout.closeCallback = nullptr; |
| 2417 | submissions.remove(timeout); |
| 2418 | numberOfSubmissions -= 1; |
| 2419 | timeout.markAsFree(); |
| 2420 | return Result(true); |
| 2421 | case AsyncRequest::State::Active: |
| 2422 | timeout.closeCallback = nullptr; |
| 2423 | removeActiveHandle(timeout); |
| 2424 | return Result(true); |
| 2425 | case AsyncRequest::State::Submitting: |
| 2426 | case AsyncRequest::State::Reactivate: |
| 2427 | case AsyncRequest::State::Cancelling: |
| 2428 | return Result::Error(AsyncResultCategory, AsyncError::TimeoutTransitionInProgress); |
| 2429 | } |
| 2430 | return Result::Error(AsyncResultCategory, AsyncError::InvalidState); |
| 2431 | } |
| 2432 | |
| 2433 | void SC::AsyncEventLoop::Internal::updateTime() |
| 2434 | { |
| 2435 | #if SC_PLATFORM_WINDOWS |
| 2436 | LARGE_INTEGER queryPerformanceFrequency; |
| 2437 | LARGE_INTEGER performanceCounter; |
| 2438 | // Since WinXP this is guaranteed to succeed |
| 2439 | QueryPerformanceFrequency(&queryPerformanceFrequency); |
| 2440 | QueryPerformanceCounter(&performanceCounter); |
| 2441 | TimeMs newTime = {static_cast<int64_t>(performanceCounter.QuadPart * 1000 / queryPerformanceFrequency.QuadPart)}; |
| 2442 | |
| 2443 | #else |
| 2444 | struct timespec nowTimeSpec; |
| 2445 | clock_gettime(CLOCK_MONOTONIC, &nowTimeSpec); |
| 2446 | int64_t ms = static_cast<int64_t>(nowTimeSpec.tv_sec) * 1000; |
| 2447 | ms += static_cast<int64_t>(nowTimeSpec.tv_nsec / (1000 * 1000)); |
| 2448 | TimeMs newTime = {ms}; |
| 2449 | #endif |
| 2450 | SC_ASYNC_ASSERT_RELEASE(newTime.milliseconds >= loopTime.milliseconds); |
| 2451 | loopTime = newTime; |
| 2452 | } |
| 2453 | |
| 2454 | SC::Result SC::AsyncEventLoop::wakeUpFromExternalThread(AsyncLoopWakeUp& async) |
| 2455 | { |
| 2456 | SC_ASYNC_ASSERT_DEBUG(async.type == AsyncRequest::Type::LoopWakeUp); |
no test coverage detected