programmers should use these timers rather than using signals or looping threads to be thread safe. and do not forget that these timers are not real-time.
// this is the timer callback void timer_cb (s_window_t *window, s_timer_t *timer) { // do what ever you want // use s_timer_* functions to change anything on timer, s_timer_timeval(window, timeval, new_timeval); s_timer_del(window, timer); s_timer_uninit(timer); // or to work directly on time struct s_thread_mutex_lock(window->timers->mut); // do anything on window->timers->*, or timer->* s_thread_mutex_unlock(window->timers->mut); } s_timer_t *tmr; s_window_t *window; // initialize a timer, and set a callback function s_timer_init(&tmr); timer->timeval = 2000; timer->cb = timer_cb; s_timer_add(window, timer); // timeval timer can be changed any time s_timer_timeval(window, timer, 3000); // delete the timer from window, and uninitialize s_timer_del(window, timer); s_timer_uninit(tmr);
Data Structures | |
| struct | s_timer_s |
| timer struct More... | |
| struct | s_timers_s |
| timers struct More... | |
Functions | |
| int | s_timer_init (s_timer_t **timer) |
| initialize the timer struct. | |
| int | s_timer_timeval (s_window_t *window, s_timer_t *timer, int timeval) |
| updates/sets the timeval for the given timer | |
| int | s_timer_uninit (s_timer_t *timer) |
| uninitialize the timer struct | |
| int | s_timer_del (s_window_t *window, s_timer_t *timer) |
| deletes a timer from windows` timers list | |
| int | s_timer_add (s_window_t *window, s_timer_t *timer) |
| adds a timer to windows` timers list | |
| int | s_timers_init (s_window_t *window) |
| initialize the timers struct for given window | |
| int | s_timers_uninit (s_window_t *window) |
| uninitialize the timers struct for given window | |
| int s_timer_add | ( | s_window_t * | window, | |
| s_timer_t * | timer | |||
| ) |
adds a timer to windows` timers list
| *window | - window to attach the timer | |
| *timer | - the timer |
| int s_timer_del | ( | s_window_t * | window, | |
| s_timer_t * | timer | |||
| ) |
deletes a timer from windows` timers list
| *window | - window that holds the timer | |
| *timer | - timer |
| int s_timer_init | ( | s_timer_t ** | timer | ) |
initialize the timer struct.
| **timer | - address of the timer pointer. |
| int s_timer_timeval | ( | s_window_t * | window, | |
| s_timer_t * | timer, | |||
| int | timeval | |||
| ) |
updates/sets the timeval for the given timer
| *window | - window that holds the timer | |
| *timer | - the timer | |
| timeval | - timeval to set the timer |
| int s_timer_uninit | ( | s_timer_t * | timer | ) |
uninitialize the timer struct
| *timer | - the timer |
| int s_timers_init | ( | s_window_t * | window | ) |
initialize the timers struct for given window
| *window | - window |
| int s_timers_uninit | ( | s_window_t * | window | ) |
uninitialize the timers struct for given window
| *window | - window |
1.4.7