bh_time.h 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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_definition.h"
  23. #include "bh_types.h"
  24. #include "bh_platform.h"
  25. /*
  26. * This function returns milliseconds per tick.
  27. * @return milliseconds per tick.
  28. */
  29. extern uint64 _bh_time_get_tick_millisecond(void);
  30. #ifdef _INSTRUMENT_TEST_ENABLED
  31. extern uint64 bh_time_get_tick_millisecond_instr(const char*func_name);
  32. #define bh_time_get_tick_millisecond() bh_time_get_tick_millisecond_instr(__FUNCTION__)
  33. #else
  34. #define bh_time_get_tick_millisecond _bh_time_get_tick_millisecond
  35. #endif
  36. /*
  37. * This function returns milliseconds after boot.
  38. * @return milliseconds after boot.
  39. */
  40. extern uint64 _bh_time_get_boot_millisecond(void);
  41. #ifdef _INSTRUMENT_TEST_ENABLED
  42. extern uint64 bh_time_get_boot_millisecond_instr(const char*func_name);
  43. #define bh_time_get_boot_millisecond() bh_time_get_boot_millisecond_instr(__FUNCTION__)
  44. #else
  45. #define bh_time_get_boot_millisecond _bh_time_get_boot_millisecond
  46. #endif
  47. extern uint32 bh_get_tick_sec();
  48. #define bh_get_tick_ms _bh_time_get_boot_millisecond
  49. /*
  50. * This function returns GMT milliseconds since from 1970.1.1, AKA UNIX time.
  51. * @return milliseconds since from 1970.1.1.
  52. */
  53. extern uint64 _bh_time_get_millisecond_from_1970(void);
  54. #ifdef _INSTRUMENT_TEST_ENABLED
  55. extern uint64 bh_time_get_millisecond_from_1970_instr(const char*func_name);
  56. #define bh_time_get_millisecond_from_1970() bh_time_get_millisecond_from_1970_instr(__FUNCTION__)
  57. #else
  58. #define bh_time_get_millisecond_from_1970 _bh_time_get_millisecond_from_1970
  59. #endif
  60. /**
  61. * This function sets timezone with specific hours.
  62. *
  63. * @param hours represents the deviation (in hours) of the local time from GMT (can be a positive or a negative number)
  64. * @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.
  65. * @param daylight_save if true, applies the daylight saving scheme when calculating the local time (adds one hour to the local time calculation)
  66. */
  67. extern void bh_set_timezone(int hours, int half_hour, int daylight_save);
  68. /**
  69. * This functions returns the offset in seconds which needs to be added GMT to get the local time.
  70. *
  71. *
  72. * @return offset in secords which needs to be added GMT to get the local time.
  73. */
  74. extern int bh_get_timezone_offset(void);
  75. size_t bh_time_strftime(char *s, size_t max, const char *format, int64 time);
  76. #ifdef _INSTRUMENT_TEST_ENABLED
  77. size_t bh_time_strftime_instr(char *s, size_t max, const char *format, int64 time, const char*func_name);
  78. #define bh_time_strftime(s, max, format, time) bh_time_strftime_instr(s, max, format, time, __FUNCTION__)
  79. #else
  80. #define bh_time_strftime _bh_time_strftime
  81. #endif
  82. #ifdef __cplusplus
  83. }
  84. #endif
  85. #endif