Simplified distributed block storage with strong consistency, like in Ceph
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

39 lines
933 B

  1. // Copyright (c) Vitaliy Filippov, 2019+
  2. // License: VNPL-1.0 or GNU GPL-2.0+ (see README.md for details)
  3. #pragma once
  4. #include <time.h>
  5. #include <vector>
  6. #include <functional>
  7. struct timerfd_timer_t
  8. {
  9. int id;
  10. uint64_t millis;
  11. timespec start, next;
  12. bool repeat;
  13. std::function<void(int)> callback;
  14. };
  15. class timerfd_manager_t
  16. {
  17. int wait_state = 0;
  18. int timerfd;
  19. int nearest = -1;
  20. int id = 1;
  21. std::vector<timerfd_timer_t> timers;
  22. void inc_timer(timerfd_timer_t & t);
  23. void set_nearest();
  24. void trigger_nearest();
  25. void handle_readable();
  26. public:
  27. std::function<void(int, bool, std::function<void(int, int)>)> set_fd_handler;
  28. timerfd_manager_t(std::function<void(int, bool, std::function<void(int, int)>)> set_fd_handler);
  29. ~timerfd_manager_t();
  30. int set_timer(uint64_t millis, bool repeat, std::function<void(int)> callback);
  31. void clear_timer(int timer_id);
  32. };