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