<commit_before>use libc::{uint32_t, c_void};
use std::mem;
use sys::timer as ll;

pub fn get_ticks() -> u32 {
    unsafe { ll::SDL_GetTicks() }
}

pub fn get_performance_counter() -> u64 {
    unsafe { ll::SDL_GetPerformanceCounter() }
}

pub fn get_performance_frequency() -> u64 {
    unsafe { ll::SDL_GetPerformanceFrequency() }
}

pub fn delay(ms: u32) {
    unsafe { ll::SDL_Delay(ms) }
}

#[unstable = "Unstable because of move to unboxed closures and `box` syntax"]
pub struct Timer<F> {
    callback: Option<Box<F>>,
    _delay: usize,
    raw: ll::SDL_TimerID,
}

impl<F> Timer<F> {
    /// Constructs a new timer using the boxed closure `callback`.
    /// The timer is started immediately, it will be cancelled either:
    ///   * when the timer is dropped
    ///   * or when the callback returns a non-positive continuation interval
    pub fn new(delay: usize, callback: Box<F>) -> Timer<F>
    where F: Fn() -> u32, F: Send {

        let timer = unsafe {
            let timer_id = ll::SDL_AddTimer(delay as u32,
                                            Some(c_timer_callback::<F>),
                                            mem::transmute_copy(&callback));

            Timer {
                callback: Some(callback),
                _delay: delay,
                raw: timer_id,
            }
        };

        return timer;
    }

    pub fn into_inner(mut self) -> Box<F> { self.callback.take().unwrap() }
}

#[unsafe_destructor]
impl<F> Drop for Timer<F> {
    fn drop(&mut self) {
        let ret = unsafe { ll::SDL_RemoveTimer(self.raw) };
        if ret != 1 {
            println!("error dropping timer {}, maybe already removed.", self.raw);
        }<commit_msg>(style fixes)<commit_after>use libc::{uint32_t, c_void};
use std::mem;
use sys::timer as ll;

pub fn get_ticks() -> u32 {
    unsafe { ll::SDL_GetTicks() }
}

pub fn get_performance_counter() -> u64 {
    unsafe { ll::SDL_GetPerformanceCounter() }
}

pub fn get_performance_frequency() -> u64 {
    unsafe { ll::SDL_GetPerformanceFrequency() }
}

pub fn delay(ms: u32) {
    unsafe { ll::SDL_Delay(ms) }
}

#[unstable = "Unstable because of move to unboxed closures and `box` syntax"]
pub struct Timer<F> {
    callback: Option<Box<F>>,
    _delay: u32,
    raw: ll::SDL_TimerID,
}

impl<F> Timer<F> {
    /// Constructs a new timer using the boxed closure `callback`.
    /// The timer is started immediately, it will be cancelled either:
    ///   * when the timer is dropped
    ///   * or when the callback returns a non-positive continuation interval
    pub fn new(delay: u32, callback: Box<F>) -> Timer<F>
    where F: Fn() -> u32, F: Send {
        unsafe {
            let timer_id = ll::SDL_AddTimer(delay,
                                            Some(c_timer_callback::<F>),
                                            mem::transmute_copy(&callback));

            Timer {
                callback: Some(callback),
                _delay: delay,
                raw: timer_id,
            }
        }
    }

    pub fn into_inner(mut self) -> Box<F> { self.callback.take().unwrap() }
}

#[unsafe_destructor]
impl<F> Drop for Timer<F> {
    fn drop(&mut self) {
        let ret = unsafe { ll::SDL_RemoveTimer(self.raw) };
        if ret != 1 {
            println!("error dropping timer {}, maybe already removed.", self.raw);
        }
{'fraction_non_alphanumeric': 0.12992831541218638, 'fraction_numerical': 0.009557945041816009, 'mean_word_length': 2.1684011352885526, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6391795', 'n_tokens_mistral': 1084, 'n_tokens_neox': 1015, 'n_words': 291}