haileys / bark

live sync audio streaming for local networks
GNU Affero General Public License v3.0
663 stars 11 forks source link

work around sched_param having more members on some platforms #7

Open nekopsykose opened 9 months ago

nekopsykose commented 9 months ago

closes #4


i don't know how to write this without unsafe. normally Default::default() exists but it's not implemented in this case..

nekopsykose commented 9 months ago

technically, this is slightly incorrect because if the extra fields are actually used (outside of linux i guess lol), it would just setschedparam and overwrite the other fields with 0's. a correct solution would be to sched_getscheduler() first and change the priority on that object. but from what i can tell not everyone does that either for linux code:

a proper version would be

    let sched_param = unsafe {
        let mut param = std::mem::MaybeUninit::uninit();
        if -1 == libc::sched_getparam(0, param.as_mut_ptr()) {
            panic!("failed to sched_getparam");
        }
        (*param.as_mut_ptr()).sched_priority = 99;
        param.assume_init()
    };

these interfaces are 'fun'