runtime_timer.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 LIB_BASE_RUNTIME_TIMER_H_
  17. #define LIB_BASE_RUNTIME_TIMER_H_
  18. #include "bh_platform.h"
  19. #ifdef __cplusplus
  20. extern "C" {
  21. #endif
  22. uint32 bh_get_elpased_ms(uint32 * last_system_clock);
  23. struct _timer_ctx;
  24. typedef struct _timer_ctx * timer_ctx_t;
  25. typedef void (*timer_callback_f)(uint32 id, unsigned int owner);
  26. typedef void (*check_timer_expiry_f)(timer_ctx_t ctx);
  27. timer_ctx_t create_timer_ctx(timer_callback_f timer_handler,
  28. check_timer_expiry_f, int prealloc_num, unsigned int owner);
  29. void destroy_timer_ctx(timer_ctx_t);
  30. void timer_ctx_set_lock(timer_ctx_t ctx, bool lock);
  31. void * timer_ctx_get_lock(timer_ctx_t ctx);
  32. unsigned int timer_ctx_get_owner(timer_ctx_t ctx);
  33. uint32 sys_create_timer(timer_ctx_t ctx, int interval, bool is_period,
  34. bool auto_start);
  35. bool sys_timer_destroy(timer_ctx_t ctx, uint32 timer_id);
  36. bool sys_timer_cancel(timer_ctx_t ctx, uint32 timer_id);
  37. bool sys_timer_restart(timer_ctx_t ctx, uint32 timer_id, int interval);
  38. void cleanup_app_timers(timer_ctx_t ctx);
  39. int check_app_timers(timer_ctx_t ctx);
  40. int get_expiry_ms(timer_ctx_t ctx);
  41. void wakeup_timer_thread(timer_ctx_t ctx);
  42. void * thread_timer_check(void * arg);
  43. #ifdef __cplusplus
  44. }
  45. #endif
  46. #endif /* LIB_BASE_RUNTIME_TIMER_H_ */