ext/pf2/src/session.rs in pf2-0.5.0 vs ext/pf2/src/session.rs in pf2-0.5.1

- old
+ new

@@ -14,11 +14,14 @@ use self::configuration::Configuration; use self::new_thread_watcher::NewThreadWatcher; use crate::profile::Profile; use crate::scheduler::Scheduler; +#[cfg(target_os = "linux")] use crate::signal_scheduler::SignalScheduler; +#[cfg(not(target_os = "linux"))] +use crate::signal_scheduler_unsupported_platform::SignalScheduler; use crate::timer_thread_scheduler::TimerThreadScheduler; use crate::util::*; pub struct Session { pub configuration: Configuration, @@ -174,18 +177,30 @@ let specified_scheduler = unsafe { let mut str = rb_funcall(value, rb_intern(cstr!("to_s")), 0); let ptr = rb_string_value_ptr(&mut str); CStr::from_ptr(ptr).to_str().unwrap() }; - configuration::Scheduler::from_str(specified_scheduler).unwrap_or_else(|_| { - // Raise an ArgumentError if the mode is invalid + let scheduler = + configuration::Scheduler::from_str(specified_scheduler).unwrap_or_else(|_| { + // Raise an ArgumentError if the mode is invalid + unsafe { + rb_raise( + rb_eArgError, + cstr!("Invalid scheduler. Valid values are ':signal' and ':timer_thread'."), + ) + } + }); + + // Raise an ArgumentError if the scheduler is not supported on the current platform + if !cfg!(target_os = "linux") && scheduler == configuration::Scheduler::Signal { unsafe { rb_raise( rb_eArgError, - cstr!("Invalid scheduler. Valid values are ':signal' and ':timer_thread'."), + cstr!("Signal scheduler is not supported on this platform."), ) } - }) + } + scheduler } pub fn start(&mut self) -> VALUE { self.running.store(true, Ordering::Relaxed); self.start_profile_buffer_flusher_thread();