periodic.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. /* Copyright (c) 2015-2016, The Tor Project, Inc. */
  2. /* See LICENSE for licensing information */
  3. #ifndef TOR_PERIODIC_H
  4. #define TOR_PERIODIC_H
  5. #define PERIODIC_EVENT_NO_UPDATE (-1)
  6. /** Callback function for a periodic event to take action. The return value
  7. * influences the next time the function will get called. Return
  8. * PERIODIC_EVENT_NO_UPDATE to not update <b>last_action_time</b> and be polled
  9. * again in the next second. If a positive value is returned it will update the
  10. * interval time. */
  11. typedef int (*periodic_event_helper_t)(time_t now,
  12. const or_options_t *options);
  13. struct event;
  14. /** A single item for the periodic-events-function table. */
  15. typedef struct periodic_event_item_t {
  16. periodic_event_helper_t fn; /**< The function to run the event */
  17. time_t last_action_time; /**< The last time the function did something */
  18. struct event *ev; /**< Libevent callback we're using to implement this */
  19. const char *name; /**< Name of the function -- for debug */
  20. } periodic_event_item_t;
  21. /** events will get their interval from first execution */
  22. #define PERIODIC_EVENT(fn) { fn##_callback, 0, NULL, #fn }
  23. #define END_OF_PERIODIC_EVENTS { NULL, 0, NULL, NULL }
  24. void periodic_event_launch(periodic_event_item_t *event);
  25. void periodic_event_setup(periodic_event_item_t *event);
  26. void periodic_event_destroy(periodic_event_item_t *event);
  27. void periodic_event_reschedule(periodic_event_item_t *event);
  28. #endif