Again
This commit is contained in:
@@ -3,11 +3,11 @@ use crossbeam_channel::{Receiver, RecvTimeoutError, Sender};
|
||||
use std::cmp::Ordering;
|
||||
use std::collections::BinaryHeap;
|
||||
use std::sync::Arc;
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
|
||||
use super::link::LinkState;
|
||||
use super::sequencer::{set_realtime_priority, AudioCommand, MidiCommand};
|
||||
use super::realtime::{precise_sleep_us, set_realtime_priority};
|
||||
use super::sequencer::{AudioCommand, MidiCommand};
|
||||
use super::timing::SyncTime;
|
||||
|
||||
/// A command scheduled for dispatch at a specific time.
|
||||
@@ -103,23 +103,6 @@ pub fn dispatcher_loop(
|
||||
}
|
||||
}
|
||||
|
||||
/// High-precision sleep using clock_nanosleep on Linux
|
||||
#[cfg(target_os = "linux")]
|
||||
fn precise_sleep(micros: u64) {
|
||||
let duration_ns = micros * 1000;
|
||||
let ts = libc::timespec {
|
||||
tv_sec: (duration_ns / 1_000_000_000) as i64,
|
||||
tv_nsec: (duration_ns % 1_000_000_000) as i64,
|
||||
};
|
||||
unsafe {
|
||||
libc::clock_nanosleep(libc::CLOCK_MONOTONIC, 0, &ts, std::ptr::null_mut());
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
fn precise_sleep(micros: u64) {
|
||||
thread::sleep(Duration::from_micros(micros));
|
||||
}
|
||||
|
||||
/// Wait until the target time for dispatch.
|
||||
/// With RT priority: spin-wait for precision
|
||||
@@ -136,7 +119,7 @@ fn wait_until_dispatch(target_us: SyncTime, link: &LinkState, has_rt: bool) {
|
||||
} else {
|
||||
// Without RT priority: sleep (spin-waiting is counterproductive)
|
||||
if remaining > 0 {
|
||||
precise_sleep(remaining);
|
||||
precise_sleep_us(remaining);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user