bh_time.h 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * Copyright (C) 2019 Intel Corporation. All rights reserved.
  3. * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. */
  5. #ifndef _BH_TIME_H
  6. #define _BH_TIME_H
  7. #ifdef __cplusplus
  8. extern "C" {
  9. #endif
  10. #include "bh_config.h"
  11. #include "bh_types.h"
  12. #include "bh_platform.h"
  13. /*
  14. * This function returns milliseconds per tick.
  15. * @return milliseconds per tick.
  16. */
  17. extern uint64 _bh_time_get_tick_millisecond(void);
  18. #ifdef _INSTRUMENT_TEST_ENABLED
  19. extern uint64 bh_time_get_tick_millisecond_instr(const char*func_name);
  20. #define bh_time_get_tick_millisecond() bh_time_get_tick_millisecond_instr(__FUNCTION__)
  21. #else
  22. #define bh_time_get_tick_millisecond _bh_time_get_tick_millisecond
  23. #endif
  24. /*
  25. * This function returns milliseconds after boot.
  26. * @return milliseconds after boot.
  27. */
  28. extern uint64 _bh_time_get_boot_millisecond(void);
  29. #ifdef _INSTRUMENT_TEST_ENABLED
  30. extern uint64 bh_time_get_boot_millisecond_instr(const char*func_name);
  31. #define bh_time_get_boot_millisecond() bh_time_get_boot_millisecond_instr(__FUNCTION__)
  32. #else
  33. #define bh_time_get_boot_millisecond _bh_time_get_boot_millisecond
  34. #endif
  35. extern uint32 bh_get_tick_sec();
  36. #define bh_get_tick_ms _bh_time_get_boot_millisecond
  37. /*
  38. * This function returns GMT milliseconds since from 1970.1.1, AKA UNIX time.
  39. * @return milliseconds since from 1970.1.1.
  40. */
  41. extern uint64 _bh_time_get_millisecond_from_1970(void);
  42. #ifdef _INSTRUMENT_TEST_ENABLED
  43. extern uint64 bh_time_get_millisecond_from_1970_instr(const char*func_name);
  44. #define bh_time_get_millisecond_from_1970() bh_time_get_millisecond_from_1970_instr(__FUNCTION__)
  45. #else
  46. #define bh_time_get_millisecond_from_1970 _bh_time_get_millisecond_from_1970
  47. #endif
  48. /**
  49. * This function sets timezone with specific hours.
  50. *
  51. * @param hours represents the deviation (in hours) of the local time from GMT (can be a positive or a negative number)
  52. * @param half_hour if true, adds half an hour to the local time calculation. For example, if hours=(+5) then the time will be GMT +5:30; if hours=(-5) then the time will be GMT -4:30.
  53. * @param daylight_save if true, applies the daylight saving scheme when calculating the local time (adds one hour to the local time calculation)
  54. */
  55. extern void bh_set_timezone(int hours, int half_hour, int daylight_save);
  56. /**
  57. * This functions returns the offset in seconds which needs to be added GMT to get the local time.
  58. *
  59. *
  60. * @return offset in secords which needs to be added GMT to get the local time.
  61. */
  62. extern int bh_get_timezone_offset(void);
  63. size_t bh_time_strftime(char *s, size_t max, const char *format, int64 time);
  64. #ifdef _INSTRUMENT_TEST_ENABLED
  65. size_t bh_time_strftime_instr(char *s, size_t max, const char *format, int64 time, const char*func_name);
  66. #define bh_time_strftime(s, max, format, time) bh_time_strftime_instr(s, max, format, time, __FUNCTION__)
  67. #else
  68. #define bh_time_strftime _bh_time_strftime
  69. #endif
  70. #ifdef __cplusplus
  71. }
  72. #endif
  73. #endif