useself::avrt_lib::AvRtLibrary; usecrate::AudioThreadPriorityError; use log::info; use std::sync::OnceLock; use windows_sys::{
w,
Win32::Foundation::{HANDLE, WIN32_ERROR},
};
mod avrt_lib { usesuper::win32_utils::{win32_error_if, OwnedLibrary}; use std::sync::Once; use windows_sys::{
core::PCWSTR,
s, w,
Win32::Foundation::{BOOL, FALSE, HANDLE, WIN32_ERROR},
};
type AvSetMmThreadCharacteristicsWFn = unsafeextern"system"fn(PCWSTR, *mut u32) -> HANDLE; type AvRevertMmThreadCharacteristicsFn = unsafeextern"system"fn(HANDLE) -> BOOL;
#[derive(Debug)] pub(super) struct AvRtLibrary { // This field is never read because only used for its Drop behavior #[allow(dead_code)]
module: OwnedLibrary,
pub(super) fn set_mm_thread_characteristics(
&self,
task_name: PCWSTR,
) -> Result<(u32, HANDLE), WIN32_ERROR> { // Ensure that the first call never runs in parallel with other calls. This // seems necessary to guarantee the success of these other calls. We saw them // fail with an error code of ERROR_PATH_NOT_FOUND in tests, presumably on a // machine where the MMCSS service was initially inactive. static FIRST_CALL: Once = Once::new(); letmut first_call_result = None;
FIRST_CALL.call_once(|| {
first_call_result = Some(self.set_mm_thread_characteristics_internal(task_name))
});
first_call_result
.unwrap_or_else(|| self.set_mm_thread_characteristics_internal(task_name))
}
/// SAFETY: The caller must transmute the value wrapped in a Ok(_) to the correct /// function type, with the correct extern specifier. pub(super) unsafefn get_proc(
&self,
proc_name: PCSTR,
) -> Result<unsafeextern"system"fn() -> isize, WIN32_ERROR> { let proc = unsafe { GetProcAddress(self.raw(), proc_name) };
win32_error_if(proc.is_none())?;
Ok(proc.unwrap())
}
}
impl Drop for OwnedLibrary { fn drop(&mutself) { unsafe {
FreeLibrary(self.raw());
}
}
}
}
#[cfg(test)] mod tests { usesuper::{
avrt, demote_current_thread_from_real_time_internal,
promote_current_thread_to_real_time_internal,
};
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.