Skip to content

Commit

Permalink
Try using an invalid task name for warmup
Browse files Browse the repository at this point in the history
  • Loading branch information
yjugl committed Mar 13, 2024
1 parent 87e90c7 commit 0bdd83d
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/rt_win.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::sync::Once;

use windows_sys::core::PCSTR;
use windows_sys::s;
use windows_sys::Win32::Foundation::GetLastError;
use windows_sys::Win32::Foundation::FALSE;
Expand Down Expand Up @@ -52,17 +53,17 @@ pub fn promote_current_thread_to_real_time_internal(
) -> Result<RtPriorityHandleInternal, AudioThreadPriorityError> {
static WARMUP: Once = Once::new();
WARMUP.call_once(|| {
if let Ok(handle) = promote_current_thread() {
if let Ok(handle) = promote_current_thread(s!("InvalidTaskNameJustForWarmup")) {
let _ = demote_current_thread_from_real_time_internal(handle);
}
});
promote_current_thread()
promote_current_thread(s!("Audio"))
}

fn promote_current_thread() -> Result<RtPriorityHandleInternal, AudioThreadPriorityError> {
fn promote_current_thread(task_name: PCSTR) -> Result<RtPriorityHandleInternal, AudioThreadPriorityError> {
let mut task_index = 0u32;

let handle = unsafe { AvSetMmThreadCharacteristicsA(s!("Audio"), &mut task_index) };
let handle = unsafe { AvSetMmThreadCharacteristicsA(task_name, &mut task_index) };
let handle = RtPriorityHandleInternal::new(task_index, handle);

if handle.task_handle == 0 {
Expand Down

0 comments on commit 0bdd83d

Please sign in to comment.