use core::sync::atomic::{self, Ordering};
use std::process;

#[inline(never)]
pub fn terminate_by_specified_method(termination_method: &str, exit_code: Option<i32>) {
    match termination_method.to_ascii_lowercase().as_str() {
        "abort" => process::abort(),
        "exit" => process::exit(exit_code.unwrap_or(101_i32)),
        "loop" => loop {
            atomic::compiler_fence(Ordering::SeqCst);
        },
        _ => {
            println!("No termination method specified! Exiting with status code 101.");
            process::exit(exit_code.unwrap_or(101_i32));
        }
    }
}
