timer.h 1.3 KB

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