mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-04-26 04:36:20 +00:00
ptp-helper: Set thread priority to time-critical on Windows
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3889>
This commit is contained in:
parent
3fdfcdf2f6
commit
572d344482
3 changed files with 43 additions and 0 deletions
|
@ -546,6 +546,8 @@ pub mod windows {
|
||||||
pub const FILE_TYPE_CHAR: u32 = 0x0002;
|
pub const FILE_TYPE_CHAR: u32 = 0x0002;
|
||||||
pub const FILE_TYPE_PIPE: u32 = 0x0003;
|
pub const FILE_TYPE_PIPE: u32 = 0x0003;
|
||||||
|
|
||||||
|
pub const THREAD_PRIORITY_TIME_CRITICAL: i32 = 15;
|
||||||
|
|
||||||
#[link(name = "kernel32")]
|
#[link(name = "kernel32")]
|
||||||
extern "system" {
|
extern "system" {
|
||||||
pub fn GetStdHandle(nstdhandle: i32) -> HANDLE;
|
pub fn GetStdHandle(nstdhandle: i32) -> HANDLE;
|
||||||
|
@ -597,6 +599,9 @@ pub mod windows {
|
||||||
lpmem: *mut c_void,
|
lpmem: *mut c_void,
|
||||||
dwbytes: usize,
|
dwbytes: usize,
|
||||||
) -> *mut c_void;
|
) -> *mut c_void;
|
||||||
|
|
||||||
|
pub fn SetThreadPriority(pthread: HANDLE, npriority: i32) -> i32;
|
||||||
|
pub fn GetCurrentThread() -> HANDLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const BCRYPT_USE_SYSTEM_PREFERRED_RNG: u32 = 0x00000002;
|
pub const BCRYPT_USE_SYSTEM_PREFERRED_RNG: u32 = 0x00000002;
|
||||||
|
|
|
@ -29,6 +29,7 @@ mod io;
|
||||||
mod net;
|
mod net;
|
||||||
mod privileges;
|
mod privileges;
|
||||||
mod rand;
|
mod rand;
|
||||||
|
mod thread;
|
||||||
|
|
||||||
use error::{Context, Error};
|
use error::{Context, Error};
|
||||||
use rand::rand;
|
use rand::rand;
|
||||||
|
@ -127,6 +128,8 @@ fn main() -> Result<(), Error> {
|
||||||
let general_socket =
|
let general_socket =
|
||||||
create_socket(PTP_GENERAL_PORT).context("Failed creating general socket")?;
|
create_socket(PTP_GENERAL_PORT).context("Failed creating general socket")?;
|
||||||
|
|
||||||
|
thread::set_priority().context("Failed to set thread priority")?;
|
||||||
|
|
||||||
privileges::drop().context("Failed dropping privileges")?;
|
privileges::drop().context("Failed dropping privileges")?;
|
||||||
|
|
||||||
let clock_id = join_multicast(&args, &event_socket, &general_socket)
|
let clock_id = join_multicast(&args, &event_socket, &general_socket)
|
||||||
|
|
35
subprojects/gstreamer/libs/gst/helpers/ptp/thread.rs
Normal file
35
subprojects/gstreamer/libs/gst/helpers/ptp/thread.rs
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
// GStreamer
|
||||||
|
//
|
||||||
|
// Copyright (C) 2015-2023 Sebastian Dröge <sebastian@centricular.com>
|
||||||
|
//
|
||||||
|
// This Source Code Form is subject to the terms of the Mozilla Public License, v2.0.
|
||||||
|
// If a copy of the MPL was not distributed with this file, You can obtain one at
|
||||||
|
// <https://mozilla.org/MPL/2.0/>.
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: MPL-2.0
|
||||||
|
|
||||||
|
use crate::error::Error;
|
||||||
|
|
||||||
|
pub fn set_priority() -> Result<(), Error> {
|
||||||
|
#[cfg(windows)]
|
||||||
|
{
|
||||||
|
use std::io;
|
||||||
|
|
||||||
|
use crate::{bail, ffi::windows::*};
|
||||||
|
|
||||||
|
// SAFETY: Getting a handle to the current thread is safe at any time
|
||||||
|
let thread = unsafe { GetCurrentThread() };
|
||||||
|
|
||||||
|
// SAFETY: SetThreadPriority() requires a valid thread handle, which was given above,
|
||||||
|
// and will return 0 on errors.
|
||||||
|
unsafe {
|
||||||
|
if SetThreadPriority(thread, THREAD_PRIORITY_TIME_CRITICAL) == 0 {
|
||||||
|
bail!(
|
||||||
|
source: io::Error::last_os_error(),
|
||||||
|
"Failed to set thread priority"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
Loading…
Reference in a new issue