timer_ticks.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * timer frequency and ticks conversions
  3. *
  4. * Copyright (C) 2005 iptelorg GmbH
  5. *
  6. * This file is part of Kamailio, a free SIP server.
  7. *
  8. * Kamailio is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version
  12. *
  13. * Kamailio is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. */
  22. /**
  23. * @file
  24. * @brief Kamailio core :: timer frequency and ticks conversions
  25. * @ingroup core
  26. * Module: @ref core
  27. */
  28. #ifndef _timer_ticks_h
  29. #define _timer_ticks_h
  30. /** @brief how many ticks per second (must >1 and < 100 (on linux x86))
  31. * recomended values >=8, <=32 (a 2^k value is better/faster)*/
  32. #define TIMER_TICKS_HZ 16U
  33. /** @brief how many ticks per m milliseconds? (rounded up) */
  34. #define MS_TO_TICKS(m) (((m)*TIMER_TICKS_HZ+999U)/1000U)
  35. /** @brief how many ticks per s seconds? */
  36. #define S_TO_TICKS(s) ((s)*TIMER_TICKS_HZ)
  37. /** @brief how many s pe per t ticks, integer value */
  38. #define TICKS_TO_S(t) ((t)/TIMER_TICKS_HZ)
  39. /** @brief how many ms per t ticks, integer value */
  40. #define TICKS_TO_MS(t) (((t)*1000U)/TIMER_TICKS_HZ)
  41. /** @brief ticks comparison operations: t1 OP t2, where OP can be <, >, <=, >= */
  42. #define TICKS_CMP_OP(t1, t2, OP) \
  43. (((s_ticks_t)((ticks_t)(t1)-(ticks_t)(t2))) OP (s_ticks_t)0)
  44. /** @brief t1 < t2 */
  45. #define TICKS_LT(t1, t2) TICKS_CMP_OP(t1, t2, <)
  46. /** @brief t1 <= t2 */
  47. #define TICKS_LE(t1, t2) TICKS_CMP_OP(t1, t2, <=)
  48. /** @brief t1 > t2 */
  49. #define TICKS_GT(t1, t2) TICKS_CMP_OP(t1, t2, >)
  50. /** @brief t1 >= t2 */
  51. #define TICKS_GE(t1, t2) TICKS_CMP_OP(t1, t2, >=)
  52. typedef unsigned int ticks_t;/* type used to keep the ticks (must be 32 bits)*/
  53. typedef signed int s_ticks_t; /* signed ticks type */
  54. #endif