@@ -5637,7 +5637,9 @@ struct VM {
56375637
56385638 const HANDLE current_thread = reinterpret_cast<HANDLE>(-2LL);
56395639 const HANDLE current_process = reinterpret_cast<HANDLE>(-1LL);
5640- SetThreadAffinityMask(current_thread, 1);
5640+ const DWORD_PTR old_affinity = SetThreadAffinityMask(current_thread, 1);
5641+ const int old_thread_priority = GetThreadPriority(current_thread);
5642+ const DWORD old_process_priority = GetPriorityClass(current_process);
56415643 SetPriorityClass(current_process, ABOVE_NORMAL_PRIORITY_CLASS); // ABOVE_NORMAL_PRIORITY_CLASS + THREAD_PRIORITY_HIGHEST = 12 base priority
56425644 SetThreadPriority(current_thread, THREAD_PRIORITY_HIGHEST);
56435645 SetThreadPriorityBoost(current_thread, TRUE); // disable dynamic boosts
@@ -5728,9 +5730,13 @@ struct VM {
57285730 }
57295731 }
57305732
5733+ // cleanup
5734+ SetThreadPriorityBoost(current_thread, FALSE);
5735+ SetThreadPriority(current_thread, old_thread_priority);
5736+ SetPriorityClass(current_process, old_process_priority);
5737+ SetThreadAffinityMask(current_thread, old_affinity);
57315738 VirtualUnlock(vm_samples.data(), BATCH_SIZE * sizeof(u64));
57325739 VirtualUnlock(ref_samples.data(), BATCH_SIZE * sizeof(u64));
5733- SetPriorityClass(current_process, NORMAL_PRIORITY_CLASS);
57345740 };
57355741
57365742 std::thread t1(counter_thread);
0 commit comments