timer_proc.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * Copyright (C) 2009 iptelorg GmbH
  3. *
  4. * Permission to use, copy, modify, and distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. /*
  17. * History:
  18. * --------
  19. * 2009-03-10 initial version (andrei)
  20. */
  21. /**
  22. * @file
  23. * @brief SIP-router core :: timer_proc.h - separate process timers
  24. *
  25. * (unrelated to the main fast and slow timers)
  26. * @ingroup core
  27. * Module: @ref core
  28. */
  29. #ifndef __timer_proc_h
  30. #define __timer_proc_h
  31. #include "local_timer.h"
  32. /**
  33. * \brief update internal counters for running new dummy timers
  34. * @param timers number of dummy timer processes
  35. * @return 0 on success; -1 on error
  36. */
  37. int register_dummy_timers(int timers);
  38. /**
  39. * \brief Forks a separate simple sleep() periodic timer
  40. *
  41. * Forks a very basic periodic timer process, that just sleep()s for
  42. * the specified interval and then calls the timer function.
  43. * The new "dummy timer" process execution start immediately, the sleep()
  44. * is called first (so the first call to the timer function will happen
  45. * \<interval\> seconds after the call to fork_dummy_timer)
  46. * @param child_id @see fork_process()
  47. * @param desc @see fork_process()
  48. * @param make_sock @see fork_process()
  49. * @param f timer function/callback
  50. * @param param parameter passed to the timer function
  51. * @param interval interval in seconds.
  52. * @return pid of the new process on success, -1 on error
  53. * (doesn't return anything in the child process)
  54. */
  55. int fork_dummy_timer(int child_id, char* desc, int make_sock,
  56. timer_function* f, void* param, int interval);
  57. /**
  58. * \brief Forks a timer process based on the local timer
  59. *
  60. * Forks a separate timer process running a local_timer.h type of timer
  61. * A pointer to the local_timer handle (allocated in shared memory) is
  62. * returned in lt_h. It can be used to add/delete more timers at runtime
  63. * (via local_timer_add()/local_timer_del() a.s.o).
  64. * If timers are added from separate processes, some form of locking must be
  65. * used (all the calls to local_timer* must be enclosed by locks if it
  66. * cannot be guaranteed that they cannot execute in the same time)
  67. * The timer "engine" must be run manually from the child process. For
  68. * example a very simple local timer process that just runs a single
  69. * periodic timer can be started in the following way:
  70. * struct local_timer* lt_h;
  71. *
  72. * pid=fork_local_timer_process(...., &lt_h);
  73. * if (pid==0){
  74. * timer_init(&my_timer, my_timer_f, 0, 0);
  75. * local_timer_add(&lt_h, &my_timer, S_TO_TICKS(10), get_ticks_raw());
  76. * while(1) { sleep(1); local_timer_run(lt, get_ticks_raw()); }
  77. * }
  78. *
  79. * @param child_id @see fork_process()
  80. * @param desc @see fork_process()
  81. * @param make_sock @see fork_process()
  82. * @param lt_h local_timer handler
  83. * @return pid to the parent, 0 to the child, -1 if error.
  84. */
  85. int fork_local_timer_process(int child_id, char* desc, int make_sock,
  86. struct local_timer** lt_h);
  87. #endif /*__timer_proc_h*/
  88. /* vi: set ts=4 sw=4 tw=79:ai:cindent: */