my_timer.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /* Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
  2. This program is free software; you can redistribute it and/or modify
  3. it under the terms of the GNU General Public License, version 2.0,
  4. as published by the Free Software Foundation.
  5. This program is also distributed with certain software (including
  6. but not limited to OpenSSL) that is licensed under separate terms,
  7. as designated in a particular file or component or in included license
  8. documentation. The authors of MySQL hereby grant you an additional
  9. permission to link the program and your derivative works with the
  10. separately licensed software that they have included with MySQL.
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. GNU General Public License, version 2.0, for more details.
  15. You should have received a copy of the GNU General Public License
  16. along with this program; if not, write to the Free Software
  17. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
  18. #ifndef MY_TIMER_H
  19. #define MY_TIMER_H
  20. /**
  21. @file include/my_timer.h
  22. */
  23. #include "my_config.h"
  24. /* POSIX timers API. */
  25. #ifdef HAVE_POSIX_TIMERS
  26. #include <time.h> /* timer_t */
  27. typedef timer_t os_timer_t;
  28. #elif defined(HAVE_KQUEUE_TIMERS)
  29. #include <sys/types.h> /* uintptr_t */
  30. typedef uintptr_t os_timer_t;
  31. #elif defined(_WIN32)
  32. struct os_timer_t {
  33. HANDLE timer_handle;
  34. bool timer_state;
  35. };
  36. #endif
  37. /* Non-copyable timer object. */
  38. struct my_timer_t {
  39. /* Timer ID used to identify the timer in timer requests. */
  40. os_timer_t id;
  41. /** Timer expiration notification function. */
  42. void (*notify_function)(my_timer_t *);
  43. };
  44. /* Initialize internal components. */
  45. int my_timer_initialize();
  46. /* Release any resources acquired. */
  47. void my_timer_deinitialize();
  48. /* Create a timer object. */
  49. int my_timer_create(my_timer_t *timer);
  50. /* Set the time (in milliseconds) until the next expiration of the timer. */
  51. int my_timer_set(my_timer_t *timer, unsigned long time);
  52. /* Cancel the timer */
  53. int my_timer_cancel(my_timer_t *timer, int *state);
  54. /* Delete a timer object. */
  55. void my_timer_delete(my_timer_t *timer);
  56. #endif /* MY_TIMER_H */