KeWaitForAlertByThreadId

NTSTATUS __stdcall KeWaitForAlertByThreadId(INT8 WaitMode, _LARGE_INTEGER *Interval, VOID *Hint){
  _ETHREAD *CurrentThread; 
  UINT8 v6; 
  NTSTATUS result; 
  _ETHREAD *v8; 
  UINT64 v9; 
  _KDUE_TIME_TYPE v10; 
  unsigned __int8 CurrentIrql; 
  NTSTATUS v12; 
  __int64 DueTime[5]; 
  _KDUE_TIME_TYPE TimeoutType; 

  CurrentThread = (_ETHREAD *)KeGetCurrentThread();
  DueTime[0] = 0i64;
  TimeoutType = DueTimeNone;
  if( _interlockedbittestandreset((volatile signed __int32 *)&CurrentThread->Tcb.116 + 1, 4u) )
    return 257;
  if( !Interval || Interval->QuadPart )
  {
    v6 = KiCheckWaitNext(&CurrentThread->Tcb, Interval, 0, (UINT64 *)DueTime, &TimeoutType);
    while( 1 )
    {
      KiBeginThreadWait(CurrentThread, WaitMode, WrAlertByThreadId, 0);
      if( result )
        return result;
      if( _interlockedbittestandreset((volatile signed __int32 *)&CurrentThread->Tcb.116 + 1, 4u) )
        break;
      if( (unsigned int)KiCheckDueTimeExpired(&CurrentThread->Tcb, TimeoutType, DueTime[0]) )
      {
        v12 = 258;
        goto LABEL_13;
      }
      v10 = TimeoutType;
      CurrentThread->Tcb.WaitBlock[0].Object = Hint;
      CurrentThread->Tcb.WaitBlockFill4[17] = 5;
      CurrentThread->Tcb.WaitBlockCount = 1;
      KiCommitThreadWait(v8, CurrentThread->Tcb.WaitBlock, v10, v9);
      CurrentThread->Tcb.WaitReason = 0;
      if( result != 256 )
        return result;
      v6 = 0;
      CurrentIrql = KeGetCurrentIrql();
      __writecr8(2ui64);
      CurrentThread->Tcb.WaitIrql = CurrentIrql;
    }
    v12 = 257;
LABEL_13:
    CurrentThread->Tcb.WaitReason = 0;
    KiFastExitThreadWait(KeGetCurrentPrcb(), &CurrentThread->Tcb, v6);
    return v12;
  }
  return 258;
}

Referenced by:

NtWaitForAlertByThreadId
PsDispatchIumService
RtlpRunOnceWaitForInit