osip_fifo.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. The oSIP library implements the Session Initiation Protocol (SIP -rfc3261-)
  3. Copyright (C) 2001-2020 Aymeric MOIZARD amoizard@antisip.com
  4. This library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. This library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with this library; if not, write to the Free Software
  14. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  15. */
  16. #ifndef _FIFO_H_
  17. #define _FIFO_H_
  18. #ifndef OSIP_MONOTHREAD
  19. #include <osip2/osip_mt.h>
  20. #endif
  21. #include <osipparser2/osip_list.h>
  22. /**
  23. * @file osip_fifo.h
  24. * @brief oSIP fifo Routines
  25. *
  26. * This is a very simple implementation of a fifo.
  27. * <BR>There is not much to say about it...
  28. */
  29. /**
  30. * @defgroup oSIP_FIFO oSIP fifo Handling
  31. * @ingroup osip2_port
  32. * @{
  33. */
  34. #ifdef __cplusplus
  35. extern "C" {
  36. #endif
  37. #ifndef DOXYGEN
  38. typedef enum { osip_ok, osip_empty } osip_fifo_state;
  39. #endif
  40. /**
  41. * Structure for referencing a fifo.
  42. * @var osip_fifo_t
  43. */
  44. typedef struct osip_fifo osip_fifo_t;
  45. /**
  46. * Structure for referencing a fifo.
  47. * @struct osip_fifo
  48. */
  49. struct osip_fifo {
  50. #ifndef OSIP_MONOTHREAD
  51. struct osip_mutex *qislocked; /**< mutex for fifo */
  52. struct osip_sem *qisempty; /**< semaphore for fifo */
  53. #endif
  54. osip_list_t queue; /**< list of nodes containing elements */
  55. int nb_elt; /**< nb of elements */
  56. osip_fifo_state state; /**< state of the fifo */
  57. };
  58. /**
  59. * Initialise a osip_fifo_t element.
  60. * NOTE: this element MUST be previously allocated with
  61. * osip_malloc(). The osip_free() call on the fifo is
  62. * still automatically done by osip_fifo_free(). This
  63. * also means you can't use a static osip_fifo_t variable
  64. * if you want to use osip_fifo_free().
  65. * @param ff The element to initialise.
  66. */
  67. void osip_fifo_init(osip_fifo_t *ff);
  68. /**
  69. * Free a fifo element.
  70. * @param ff The element to work on.
  71. */
  72. void osip_fifo_free(osip_fifo_t *ff);
  73. /**
  74. * Insert an element in a fifo (at the beginning).
  75. * @param ff The element to work on.
  76. * @param element The pointer on the element to insert.
  77. */
  78. int osip_fifo_insert(osip_fifo_t *ff, void *element);
  79. /**
  80. * Add an element in a fifo.
  81. * @param ff The element to work on.
  82. * @param element The pointer on the element to add.
  83. */
  84. int osip_fifo_add(osip_fifo_t *ff, void *element);
  85. /**
  86. * Get the number of element in a fifo.
  87. * @param ff The element to work on.
  88. */
  89. int osip_fifo_size(osip_fifo_t *ff);
  90. #ifndef OSIP_MONOTHREAD
  91. /**
  92. * Get an element from a fifo or block until one is added.
  93. * @param ff The element to work on.
  94. */
  95. void *osip_fifo_get(osip_fifo_t *ff);
  96. #endif
  97. /**
  98. * Try to get an element from a fifo, but do not block if there is no element.
  99. * @param ff The element to work on.
  100. */
  101. void *osip_fifo_tryget(osip_fifo_t *ff);
  102. /** @} */
  103. #ifdef __cplusplus
  104. }
  105. #endif
  106. #endif