Skip to main content

Crate audio_thread_priority

Crate audio_thread_priority 

Source
Expand description

§audio_thread_priority

Promote the current thread, or another thread (possibly in another process), to real-time priority, suitable for low-latency audio processing.

§Platforms

  • macOS: the Mach time-constraint scheduling policy.
  • Windows: the Multimedia Class Scheduler Service (MMCSS), “Pro Audio” task.
  • Linux (default, dbus feature enabled): rtkit, over D-Bus. This suits unprivileged, sandboxed desktop processes, since rtkit performs the privileged scheduling change on their behalf.
  • Linux (dbus feature disabled): direct promotion with pthread_setschedparam and the SCHED_FIFO policy. This needs no D-Bus daemon, and works whenever the process may request real-time scheduling: running as root, holding CAP_SYS_NICE, or with an RLIMIT_RTPRIO limit configured (e.g. systemd LimitRTPRIO or /etc/security/limits.conf). The requested priority defaults to 10 and can be changed with set_rt_priority (Linux, no-dbus only).
  • Other platforms: a no-op that reports success.

§Example


use audio_thread_priority::{promote_current_thread_to_real_time, demote_current_thread_from_real_time};

// ... on a thread that will compute audio and has to be real-time:
match promote_current_thread_to_real_time(512, 44100) {
  Ok(h) => {
    println!("this thread is now bumped to real-time priority.");

    // Do some real-time work...

    match demote_current_thread_from_real_time(h) {
      Ok(_) => {
        println!("this thread is now bumped back to normal.")
      }
      Err(_) => {
        println!("Could not bring the thread back to normal priority.")
      }
    };
  }
  Err(e) => {
    eprintln!("Error promoting thread to real-time: {}", e);
  }
}

Structs§

AudioThreadPriorityError
The OS-specific issue is available as inner
atp_handle
Opaque handle for the C API
atp_thread_info
Opaque info to a particular thread.

Statics§

ATP_THREAD_INFO_SIZE
Size of a RtPriorityThreadInfo or atp_thread_info struct, for use in FFI.

Functions§

atp_demote_current_thread_from_real_time
Demotes the calling thread from real-time priority, with a C API.
atp_demote_thread_from_real_time
Demote a thread promoted to from real-time, with a C API.
atp_deserialize_thread_info
From a byte buffer, return a RtPriorityThreadInfo, with a C API.
atp_free_handle
Frees a handle, with a C API.
atp_free_thread_info
Frees a thread info, with a c api.
atp_get_current_thread_info
Get the calling thread’s information, to promote it from another process or thread, with a C API.
atp_promote_current_thread_to_real_time
Promote the calling thread to real-time priority, with a C API.
atp_promote_thread_to_real_time
Promote a specific thread to real-time, with a C API.
atp_serialize_thread_info
Return a byte buffer containing serialized information about a thread, to promote it to real-time from elsewhere, with a C API.
atp_set_real_time_limit
Set a real-time limit for the calling thread.
demote_current_thread_from_real_time
Demotes the calling thread from real-time priority.
demote_thread_from_real_time
Demotes a thread from real-time priority.
get_current_thread_info
Get the calling thread’s information, to be able to promote it to real-time from somewhere else, later.
promote_current_thread_to_real_time
Promote the calling thread to real-time priority.
promote_thread_to_real_time
Promote a particular thread to real-time priority.
thread_info_deserialize
From a byte buffer, return a RtPriorityThreadInfo.
thread_info_serialize
Return a byte buffer containing serialized information about a thread, to promote it to real-time from elsewhere.

Type Aliases§

RtPriorityHandle
Opaque handle to a thread handle structure.
RtPriorityThreadInfo
Opaque handle to a thread’s scheduling information.