Changes: * Implement patty_timer type to store both a struct timeval and a bitfield for indicating timer state; currently, this only holds the PATTY_TIMER_RUNNING flag to indicate whether a timer has been stopped (irrespective of its "expired" status) * Remove 'target' argument from patty_timer_start(); instead, rely on select() polling every 1s to cause events to trigger at a regular interval * Make patty_timer_expired() return false if PATTY_TIMER_RUNNING is not set * Implement patty_timer_stop() to clear the PATTY_TIMER_RUNNING flag of a timer * Make patty_timer_clear() set all fields to zero, including clearing the PATTY_TIMER_RUNNING flag
30 lines
621 B
C
30 lines
621 B
C
#ifndef _PATTY_TIMER_H
|
|
#define _PATTY_TIMER_H
|
|
|
|
#include <stdint.h>
|
|
#include <sys/time.h>
|
|
|
|
enum patty_timer_flags {
|
|
PATTY_TIMER_RUNNING = (1 << 0)
|
|
};
|
|
|
|
typedef struct _patty_timer {
|
|
struct timeval t;
|
|
uint32_t flags;
|
|
} patty_timer;
|
|
|
|
int patty_timer_running(patty_timer *timer);
|
|
|
|
int patty_timer_expired(patty_timer *timer);
|
|
|
|
void patty_timer_clear(patty_timer *timer);
|
|
|
|
void patty_timer_start(patty_timer *timer,
|
|
time_t ms);
|
|
|
|
void patty_timer_stop(patty_timer *timer);
|
|
|
|
void patty_timer_tick(patty_timer *timer,
|
|
struct timeval *elapsed);
|
|
|
|
#endif /* _PATTY_TIMER_H */
|