[1] | 1 | // Copyright (c) Athena Dev Teams - Licensed under GNU GPL |
---|
| 2 | // For more information, see LICENCE in the main folder |
---|
| 3 | |
---|
| 4 | #ifndef _TIMER_H_ |
---|
| 5 | #define _TIMER_H_ |
---|
| 6 | |
---|
| 7 | #ifndef _CBASETYPES_H_ |
---|
| 8 | #include "../common/cbasetypes.h" |
---|
| 9 | #endif |
---|
| 10 | |
---|
| 11 | #define DIFF_TICK(a,b) ((int)((a)-(b))) |
---|
| 12 | |
---|
| 13 | #define INVALID_TIMER -1 |
---|
| 14 | |
---|
| 15 | // timer flags |
---|
| 16 | #define TIMER_ONCE_AUTODEL 0x01 |
---|
| 17 | #define TIMER_INTERVAL 0x02 |
---|
| 18 | #define TIMER_REMOVE_HEAP 0x10 |
---|
| 19 | |
---|
| 20 | // Struct declaration |
---|
| 21 | |
---|
| 22 | typedef int (*TimerFunc)(int tid, unsigned int tick, int id, intptr data); |
---|
| 23 | |
---|
| 24 | struct TimerData { |
---|
| 25 | unsigned int tick; |
---|
| 26 | TimerFunc func; |
---|
| 27 | int type; |
---|
| 28 | int interval; |
---|
| 29 | int heap_pos; |
---|
| 30 | |
---|
| 31 | // general-purpose storage |
---|
| 32 | int id; |
---|
| 33 | intptr data; |
---|
| 34 | }; |
---|
| 35 | |
---|
| 36 | // Function prototype declaration |
---|
| 37 | |
---|
| 38 | unsigned int gettick(void); |
---|
| 39 | unsigned int gettick_nocache(void); |
---|
| 40 | |
---|
| 41 | int add_timer(unsigned int tick, TimerFunc func, int id, intptr data); |
---|
| 42 | int add_timer_interval(unsigned int tick, TimerFunc func, int id, intptr data, int interval); |
---|
| 43 | struct TimerData* get_timer(int tid); |
---|
| 44 | int delete_timer(int tid, TimerFunc func); |
---|
| 45 | |
---|
| 46 | int addtick_timer(int tid, unsigned int tick); |
---|
| 47 | int settick_timer(int tid, unsigned int tick); |
---|
| 48 | |
---|
| 49 | int add_timer_func_list(TimerFunc func, char* name); |
---|
| 50 | |
---|
| 51 | unsigned long get_uptime(void); |
---|
| 52 | |
---|
| 53 | int do_timer(unsigned int tick); |
---|
| 54 | void timer_init(void); |
---|
| 55 | void timer_final(void); |
---|
| 56 | |
---|
| 57 | #endif /* _TIMER_H_ */ |
---|