bh_time.h 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * Copyright (C) 2019 Intel Corporation. All rights reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef _BH_TIME_H
  17. #define _BH_TIME_H
  18. #ifdef __cplusplus
  19. extern "C" {
  20. #endif
  21. #include "bh_config.h"
  22. #include "bh_types.h"
  23. #include "bh_platform.h"
  24. /*
  25. * This function returns milliseconds per tick.
  26. * @return milliseconds per tick.
  27. */
  28. extern uint64 _bh_time_get_tick_millisecond(void);
  29. #ifdef _INSTRUMENT_TEST_ENABLED
  30. extern uint64 bh_time_get_tick_millisecond_instr(const char*func_name);
  31. #define bh_time_get_tick_millisecond() bh_time_get_tick_millisecond_instr(__FUNCTION__)
  32. #else
  33. #define bh_time_get_tick_millisecond _bh_time_get_tick_millisecond
  34. #endif
  35. /*
  36. * This function returns milliseconds after boot.
  37. * @return milliseconds after boot.
  38. */
  39. extern uint64 _bh_time_get_boot_millisecond(void);
  40. #ifdef _INSTRUMENT_TEST_ENABLED
  41. extern uint64 bh_time_get_boot_millisecond_instr(const char*func_name);
  42. #define bh_time_get_boot_millisecond() bh_time_get_boot_millisecond_instr(__FUNCTION__)
  43. #else
  44. #define bh_time_get_boot_millisecond _bh_time_get_boot_millisecond
  45. #endif
  46. extern uint32 bh_get_tick_sec();
  47. #define bh_get_tick_ms _bh_time_get_boot_millisecond
  48. /*
  49. * This function returns GMT milliseconds since from 1970.1.1, AKA UNIX time.
  50. * @return milliseconds since from 1970.1.1.
  51. */
  52. extern uint64 _bh_time_get_millisecond_from_1970(void);
  53. #ifdef _INSTRUMENT_TEST_ENABLED
  54. extern uint64 bh_time_get_millisecond_from_1970_instr(const char*func_name);
  55. #define bh_time_get_millisecond_from_1970() bh_time_get_millisecond_from_1970_instr(__FUNCTION__)
  56. #else
  57. #define bh_time_get_millisecond_from_1970 _bh_time_get_millisecond_from_1970
  58. #endif
  59. /**
  60. * This function sets timezone with specific hours.
  61. *
  62. * @param hours represents the deviation (in hours) of the local time from GMT (can be a positive or a negative number)
  63. * @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.
  64. * @param daylight_save if true, applies the daylight saving scheme when calculating the local time (adds one hour to the local time calculation)
  65. */
  66. extern void bh_set_timezone(int hours, int half_hour, int daylight_save);
  67. /**
  68. * This functions returns the offset in seconds which needs to be added GMT to get the local time.
  69. *
  70. *
  71. * @return offset in secords which needs to be added GMT to get the local time.
  72. */
  73. extern int bh_get_timezone_offset(void);
  74. size_t bh_time_strftime(char *s, size_t max, const char *format, int64 time);
  75. #ifdef _INSTRUMENT_TEST_ENABLED
  76. size_t bh_time_strftime_instr(char *s, size_t max, const char *format, int64 time, const char*func_name);
  77. #define bh_time_strftime(s, max, format, time) bh_time_strftime_instr(s, max, format, time, __FUNCTION__)
  78. #else
  79. #define bh_time_strftime _bh_time_strftime
  80. #endif
  81. #ifdef __cplusplus
  82. }
  83. #endif
  84. #endif