KiInsertSchedulingGroupQueue

VOID __stdcall KiInsertSchedulingGroupQueue(_KPRCB *Prcb, _KSCB *Scb, UINT8 UpdateInsertionTime){
  _KSCB *Parent; 
  _RTL_RB_TREE *p_ScbQueue; 
  _RTL_RB_TREE *p_ChildScbQueue; 
  UINT64 Root; 
  BOOL v9; 
  unsigned int Rank; 
  int v11; 
  unsigned int ReadySummary; 
  UINT64 v13; 
  unsigned int v14; 
  int v15; 
  int v16; 

  Parent = Scb->Parent;
  p_ScbQueue = &Prcb->ScbQueue;
  *((_BYTE *)Scb + 112) |= 1u;
  p_ChildScbQueue = &Parent->ChildScbQueue;
  if( !Parent )
    p_ChildScbQueue = p_ScbQueue;
  Root = (UINT64)p_ChildScbQueue->Root;
  if( (p_ChildScbQueue->_bf_0 & 1) != 0 && Root )
    Root ^= (unsigned __int64)p_ChildScbQueue;
  v9 = 0;
  if( Root )
  {
    Rank = Scb->Rank;
    while( 1 )
    {
      v11 = Rank - *(_DWORD *)(Root + 28);
      if( Rank != *(_DWORD *)(Root + 28) )
        goto LABEL_11;
      ReadySummary = Scb->ReadySummary;
      if( (_WORD)ReadySummary )
        break;
      if( Rank )
      {
        v11 = 1;
        goto LABEL_11;
      }
      if( Scb->GenerationCycles <= *(_QWORD *)(Root - 88) )
      {
LABEL_17:
        v13 = *(_QWORD *)Root;
        if( (p_ChildScbQueue->_bf_0 & 1) != 0 )
        {
          if( !v13 )
            goto LABEL_21;
          v13 ^= Root;
        }
        if( !v13 )
        {
LABEL_21:
          v9 = 0;
          goto LABEL_22;
        }
        goto LABEL_16;
      }
LABEL_12:
      v13 = *(_QWORD *)(Root + 8);
      if( (p_ChildScbQueue->_bf_0 & 1) != 0 )
      {
        if( !v13 )
          goto LABEL_31;
        v13 ^= Root;
      }
      if( !v13 )
      {
LABEL_31:
        v9 = 1;
        goto LABEL_22;
      }
LABEL_16:
      Root = v13;
    }
    v14 = *(unsigned __int16 *)(Root + 26);
    _BitScanReverse((unsigned int *)&v15, ReadySummary);
    v16 = 0;
    if( (_WORD)v14 )
      _BitScanReverse((unsigned int *)&v16, v14);
    v11 = v16 - v15;
LABEL_11:
    if( v11 < 0 )
      goto LABEL_17;
    goto LABEL_12;
  }
LABEL_22:
  RtlRbInsertNodeEx((UINT64 *)p_ChildScbQueue, Root, v9, (UINT64)&Scb->QueueNode);
  if( UpdateInsertionTime )
    Scb->InsertTime = *(_QWORD *)&KUSER_SHARED_DATA.InterruptTime.LowPart;
}

Referenced by:

KiInsertNonMaxOverQuotaScb
KiResortScbQueue