KeSetPriorityThread

KPRIORITY __stdcall KeSetPriorityThread(_ETHREAD *Thread, KPRIORITY Priority){
  UINT8 CurrentIrql; 
  struct _KPRCB *CurrentPrcb; 
  _ETHREAD *CurrentThread; 
  char PriorityDecrement; 
  char v8; 
  KPRIORITY v9; 
  unsigned __int64 CycleTime; 
  unsigned __int64 v11; 
  char BasePriority; 
  _DWORD *SchedulerAssist; 
  UINT64 SpinCount; 
  _SINGLE_LIST_ENTRY ReadyList; 

  if( Thread->Tcb.Process == (_EPROCESS *)&KiInitialProcess )
    return 1;
  ReadyList.Next = 0i64;
  CurrentIrql = KeGetCurrentIrql();
  __writecr8(2ui64);
  CurrentPrcb = KeGetCurrentPrcb();
  LODWORD(SpinCount) = 0;
  CurrentThread = CurrentPrcb->CurrentThread;
  while( _interlockedbittestandset64((volatile signed __int32 *)&Thread->Tcb.ThreadLock, 0i64) )
  {
    do
      KeYieldProcessorEx(&SpinCount);
    while( Thread->Tcb.ThreadLock );
    SchedulerAssist = CurrentPrcb->SchedulerAssist;
    if( SchedulerAssist && CurrentPrcb->NestingLevel <= 1u )
      ++SchedulerAssist[6];
  }
  PriorityDecrement = Thread->Tcb.PriorityDecrement;
  v8 = Thread->Tcb.Priority;
  v9 = v8;
  if( PriorityDecrement )
  {
    if( (PriorityDecrement & 0xF) != 0 )
    {
      Thread->Tcb.ForegroundLossTime = KUSER_SHARED_DATA.TickCount.LowPart;
      v8 = Thread->Tcb.Priority;
    }
    Thread->Tcb.PriorityDecrement = 0;
  }
  if( Priority != v8 )
  {
    if( Thread != CurrentThread || CurrentPrcb->NestingLevel )
    {
      CycleTime = Thread->Tcb.CycleTime;
    }
    else
    {
      _disable();
      CycleTime = KiUpdateTotalCyclesCurrentThread(CurrentPrcb, &Thread->Tcb, 0i64);
      _enable();
    }
    v11 = CycleTime + KiCyclesPerClockQuantum * (unsigned int)Thread->Tcb.SchedulerApc.SpareByte1;
    if( (*(&Thread->Tcb.MiscFlags + 1) & 0x20) != 0 )
      _interlockedbittestandreset((volatile signed __int32 *)&Thread->Tcb.116 + 1, 5u);
    BasePriority = Thread->Tcb.BasePriority;
    Thread->Tcb.QuantumTarget = v11;
    if( BasePriority && !Priority )
      Priority = 1;
    if( BasePriority < 16 || Priority >= 16 )
      KiSetPriorityThread(&Thread->Tcb, &ReadyList, (unsigned int)Priority);
  }
  KiReleaseThreadLockSafe((INT64)Thread);
  KiProcessDeferredReadyList(CurrentPrcb, &ReadyList, CurrentIrql);
  return v9;
}

Referenced by:

CcApplyLowIoPriorityToThread
CcBoostLowPriorityWorkerThread
CmpSetPriorityThread
ExRegisterBootDevice
FsRtlWorkerThread
KeBalanceSetManager
KeGenericProcessorCallback
KeSetThreadSchedulerAssist
KeSwapProcessOrStack
KiExecuteDpc
MiDereferenceSegmentThread
MiMappedPageWriter
MiPartitionWorkingSetManager
MiRebuildLargePagesThread
MiSetIdealProcessorThread
MiZeroInParallel
MiZeroInParallelWorker
NtSetInformationThread
PfTSetTraceWorkerPriority
ViPendingQueuePassiveLevelCompletion