thread_priority::unix

Trait ThreadExt

Source
pub trait ThreadExt {
    // Required method
    fn get_native_id(&self) -> Result<ThreadId, Error>;

    // Provided methods
    fn get_priority(&self) -> Result<ThreadPriority, Error> { ... }
    fn set_priority(&self, priority: ThreadPriority) -> Result<(), Error> { ... }
    fn get_schedule_policy(&self) -> Result<ThreadSchedulePolicy, Error> { ... }
    fn get_schedule_policy_param(
        &self,
    ) -> Result<(ThreadSchedulePolicy, ScheduleParams), Error> { ... }
    fn set_priority_and_policy(
        &self,
        policy: ThreadSchedulePolicy,
        priority: ThreadPriority,
    ) -> Result<(), Error> { ... }
}
Expand description

A helper trait for other threads to implement to be able to call methods on threads themselves.

use thread_priority::*;

assert!(std::thread::current().get_priority().is_ok());

let join_handle = std::thread::spawn(|| println!("Hello world!"));
assert!(join_handle.thread().get_priority().is_ok());

join_handle.join();

Required Methods§

Source

fn get_native_id(&self) -> Result<ThreadId, Error>

Returns native unix thread id. For more info read thread_native_id.

use thread_priority::*;

assert!(std::thread::current().get_native_id().unwrap() > 0);

Provided Methods§

Source

fn get_priority(&self) -> Result<ThreadPriority, Error>

Gets the current thread’s priority. For more info read get_current_thread_priority.

use thread_priority::*;

assert!(std::thread::current().get_priority().is_ok());
Source

fn set_priority(&self, priority: ThreadPriority) -> Result<(), Error>

Sets the current thread’s priority. For more info see ThreadPriority::set_for_current.

use thread_priority::*;

assert!(std::thread::current().set_priority(ThreadPriority::Min).is_ok());
Source

fn get_schedule_policy(&self) -> Result<ThreadSchedulePolicy, Error>

Gets the current thread’s schedule policy. For more info read thread_schedule_policy.

Source

fn get_schedule_policy_param( &self, ) -> Result<(ThreadSchedulePolicy, ScheduleParams), Error>

Returns current thread’s schedule policy and parameters. For more info read thread_schedule_policy_param.

Source

fn set_priority_and_policy( &self, policy: ThreadSchedulePolicy, priority: ThreadPriority, ) -> Result<(), Error>

Sets current thread’s schedule policy. For more info read set_thread_priority_and_policy.

Implementations on Foreign Types§

Source§

impl ThreadExt for Thread

Auto-implementation of this trait for the std::thread::Thread.

Implementors§