KeWaitForAlertByThreadId

NTSTATUS __stdcall KeWaitForAlertByThreadId(INT8 WaitMode, LARGE_INTEGER *Interval, PVOID HINT){
  _ETHREAD *CurrentThread; 
  char v6; 
  NTSTATUS result; 
  __int64 v8; 
  __int64 v9; 
  int v10; 
  unsigned __int8 CurrentIrql; 
  NTSTATUS v12; 
  __int64 v13[5]; 
  int v14; 
  CurrentThread = (_ETHREAD *)KeGetCurrentThread();
  v13[0] = 0i64;
  v14 = 0;
  if( _interlockedbittestandreset((volatile signed __int32 *)CurrentThread + 30, 4u) )
    return 257;
  if( !Interval || Interval->QuadPart )
  {
    v6 = KiCheckWaitNext((__int64)CurrentThread, (__int64)Interval, 0, v13, &v14);
    while( 1 )
    {
      KiBeginThreadWait(CurrentThread, WaitMode, WrAlertByThreadId, 0);
      if( result )
        return result;
      if( _interlockedbittestandreset((volatile signed __int32 *)CurrentThread + 30, 4u) )
        break;
      if( KiCheckDueTimeExpired((__int64)CurrentThread, v14, v13[0]) )
      {
        v12 = 258;
        goto LABEL_13;
      }
      v10 = v14;
      *((_QWORD *)CurrentThread + 44) = HINT;
      *((_BYTE *)CurrentThread + 337) = 5;
      *((_BYTE *)CurrentThread + 587) = 1;
      result = KiCommitThreadWait(v8, (__int64 *)CurrentThread + 40, v10, v9, 0i64);
      *((_BYTE *)CurrentThread + 643) = 0;
      if( result != 256 )
        return result;
      v6 = 0;
      CurrentIrql = KeGetCurrentIrql();
      __writecr8(2ui64);
      *((_BYTE *)CurrentThread + 390) = CurrentIrql;
    }
    v12 = 257;
LABEL_13:
    *((_BYTE *)CurrentThread + 643) = 0;
    KiFastExitThreadWait((__int64)KeGetCurrentPrcb(), (__int64)CurrentThread, v6);
    return v12;
  }
  return 258;
}

Referenced by:

NtWaitForAlertByThreadId
PsDispatchIumService
RtlpRunOnceWaitForInit