MCPcopy Create free account
hub / github.com/Pagghiu/SaneCppLibraries / addActiveHandle

Method addActiveHandle

Libraries/Async/Async.cpp:2399–2494  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2397}
2398
2399void SC::AsyncEventLoop::Internal::addActiveHandle(AsyncRequest& async)
2400{
2401 SC_ASYNC_ASSERT_RELEASE(async.state == AsyncRequest::State::Submitting);
2402 async.state = AsyncRequest::State::Active;
2403
2404 if ((async.flags & Internal::Flag_ManualCompletion) != 0)
2405 {
2406 numberOfManualCompletions += 1;
2407 return; // Async flagged to be manually completed, are not added to active handles
2408 }
2409
2410 numberOfActiveHandles += 1;
2411 if ((async.flags & Internal::Flag_ExcludeFromActiveCount) != 0)
2412 {
2413 numberOfExternals -= 1;
2414 }
2415
2416 if (async.sequence)
2417 {
2418 trackSequence(*async.sequence);
2419 async.sequence->runningAsync = true;
2420 async.sequence->runningRequest = &async;
2421 }
2422
2423 if (async.sequence and async.type != AsyncRequest::Type::LoopTimeout)
2424 {
2425 // Sequenced non-timeout requests complete through sequence/manual-completion paths and are not
2426 // tracked in typed active lists. LoopTimeout is the exception: invokeExpiredTimers() scans
2427 // activeLoopTimeouts, so sequenced timers must still be tracked there.
2428 return;
2429 }
2430 switch (async.type)
2431 {
2432 case AsyncRequest::Type::LoopTimeout: {
2433 // Timeouts needs to be ordered
2434 AsyncLoopTimeout& timeout = *static_cast<AsyncLoopTimeout*>(&async);
2435
2436 AsyncLoopTimeout* iterator = activeLoopTimeouts.front;
2437 // TODO: Replace code below with a heap or some sorted data structure...
2438 while (iterator)
2439 {
2440 // It's important to compare with '>' and not '>=' to allow timers with same expiration time to be
2441 // sub-ordered by their scheduling order
2442 if (iterator->expirationTime.milliseconds > timeout.expirationTime.milliseconds)
2443 {
2444 // middle
2445 timeout.prev = iterator->prev;
2446 timeout.next = iterator;
2447 if (timeout.prev)
2448 {
2449 timeout.prev->next = &timeout;
2450 }
2451 else
2452 {
2453 activeLoopTimeouts.front = &timeout;
2454 }
2455 if (timeout.next)
2456 {

Callers 1

reactivateRequestMethod · 0.80

Calls 1

queueBackMethod · 0.45

Tested by

no test coverage detected