time-internal.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * Copyright (c) 2000-2007 Niels Provos <provos@citi.umich.edu>
  3. * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. * 3. The name of the author may not be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  17. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  18. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  19. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  20. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  21. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  22. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  23. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  25. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. #ifndef TIME_INTERNAL_H_INCLUDED_
  28. #define TIME_INTERNAL_H_INCLUDED_
  29. #include "event2/event-config.h"
  30. #include "evconfig-private.h"
  31. #ifdef EVENT__HAVE_MACH_MACH_TIME_H
  32. /* For mach_timebase_info */
  33. #include <mach/mach_time.h>
  34. #endif
  35. #include <time.h>
  36. #include "event2/util.h"
  37. #ifdef __cplusplus
  38. extern "C" {
  39. #endif
  40. #if defined(EVENT__HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC)
  41. #define HAVE_POSIX_MONOTONIC
  42. #elif defined(EVENT__HAVE_MACH_ABSOLUTE_TIME)
  43. #define HAVE_MACH_MONOTONIC
  44. #elif defined(_WIN32)
  45. #define HAVE_WIN32_MONOTONIC
  46. #else
  47. #define HAVE_FALLBACK_MONOTONIC
  48. #endif
  49. long evutil_tv_to_msec_(const struct timeval *tv);
  50. EVENT2_EXPORT_SYMBOL
  51. void evutil_usleep_(const struct timeval *tv);
  52. #ifdef _WIN32
  53. typedef ULONGLONG (WINAPI *ev_GetTickCount_func)(void);
  54. #endif
  55. struct evutil_monotonic_timer {
  56. #ifdef HAVE_MACH_MONOTONIC
  57. struct mach_timebase_info mach_timebase_units;
  58. #endif
  59. #ifdef HAVE_POSIX_MONOTONIC
  60. int monotonic_clock;
  61. #endif
  62. #ifdef HAVE_WIN32_MONOTONIC
  63. ev_GetTickCount_func GetTickCount64_fn;
  64. ev_GetTickCount_func GetTickCount_fn;
  65. ev_uint64_t last_tick_count;
  66. ev_uint64_t adjust_tick_count;
  67. ev_uint64_t first_tick;
  68. ev_uint64_t first_counter;
  69. double usec_per_count;
  70. int use_performance_counter;
  71. #endif
  72. struct timeval adjust_monotonic_clock;
  73. struct timeval last_time;
  74. };
  75. EVENT2_EXPORT_SYMBOL
  76. int evutil_configure_monotonic_time_(struct evutil_monotonic_timer *mt,
  77. int flags);
  78. EVENT2_EXPORT_SYMBOL
  79. int evutil_gettime_monotonic_(struct evutil_monotonic_timer *mt, struct timeval *tv);
  80. #ifdef __cplusplus
  81. }
  82. #endif
  83. #endif /* EVENT_INTERNAL_H_INCLUDED_ */