timer.h 847 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #ifndef SLEEPTIMER_H_
  2. #define SLEEPTIMER_H_
  3. #include "list.h"
  4. #include <time.h>
  5. #include <stdint.h>
  6. #ifdef __cplusplus
  7. extern "C" {
  8. #endif
  9. struct sleeptimer;
  10. typedef void (*sleeptimer_callback_t)(struct sleeptimer *timer);
  11. typedef uint64_t timer_id_t;
  12. struct sleeptimer {
  13. const char *name;
  14. struct timespec timeout;
  15. sleeptimer_callback_t callback;
  16. timer_id_t id;
  17. struct list_head list;
  18. };
  19. void sleeptimer_init(struct sleeptimer *timer,
  20. const char *name,
  21. sleeptimer_callback_t callback);
  22. void sleeptimer_set_timeout_relative(struct sleeptimer *timer,
  23. unsigned int msecs);
  24. void sleeptimer_enqueue(struct sleeptimer *timer);
  25. void sleeptimer_dequeue(struct sleeptimer *timer);
  26. int sleeptimer_system_init(void);
  27. int sleeptimer_wait_next(void);
  28. #ifdef __cplusplus
  29. } /* extern "C" */
  30. #endif
  31. #endif /* TIMER_H_ */