1 /*****************************************************************************
2 * vlc_fifo_helper.h: Basic FIFO helper functions
3 *****************************************************************************
4 * Copyright (C) 2017 VLC authors and VideoLAN
6 * Authors: Steve Lhomme <robux4@gmail.com>
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation; either version 2.1 of the License, or
11 * (at your option) any later version.
13 * This program 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 Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this program; if not, write to the Free Software Foundation,
20 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
21 *****************************************************************************/
23 #ifndef VLC_FIFO_HELPER_H
24 #define VLC_FIFO_HELPER_H 1
26 typedef struct FIFO_ITEM
{
27 struct FIFO_ITEM
*p_next
;
33 fifo_item_t
**pp_last
;
37 static inline void fifo_Init(fifo_t
*p_fifo
)
39 p_fifo
->p_first
= NULL
;
40 p_fifo
->pp_last
= &p_fifo
->p_first
;
44 static inline void fifo_Release(fifo_t
*fifo
)
46 assert(fifo
->i_depth
== 0); /* we should have poped all the items */
49 static inline size_t fifo_GetCount(fifo_t
*fifo
)
54 static inline fifo_item_t
*fifo_Show(fifo_t
*p_fifo
)
58 assert(p_fifo
->p_first
!= NULL
);
64 static inline fifo_item_t
*fifo_Get(fifo_t
*fifo
)
66 fifo_item_t
*block
= fifo
->p_first
;
69 return NULL
; /* Nothing to do */
71 fifo
->p_first
= block
->p_next
;
72 if (block
->p_next
== NULL
)
73 fifo
->pp_last
= &fifo
->p_first
;
76 assert(fifo
->i_depth
> 0);
82 static inline void fifo_Put(fifo_t
*fifo
, fifo_item_t
*p_item
)
84 *(fifo
->pp_last
) = p_item
;
86 while (p_item
!= NULL
)
88 fifo
->pp_last
= &p_item
->p_next
;
91 p_item
= p_item
->p_next
;
95 /* macro to get the proper item type in/out of the FIFO
96 * The item type must have a field fifo_item_t named fifo
98 #define TYPED_FIFO(type, prefix) \
99 static inline void prefix ## _fifo_Init(fifo_t *p_fifo) \
103 static inline void prefix ## _fifo_Release(fifo_t *p_fifo) \
105 fifo_Release(p_fifo); \
107 static inline void prefix ## _fifo_Put(fifo_t *p_fifo, type *p_item) \
109 fifo_Put(p_fifo, &p_item->fifo); \
111 static inline type *prefix ## _fifo_Get(fifo_t *p_fifo) \
113 return (type*)fifo_Get(p_fifo); \
115 static inline type *prefix ## _fifo_Show(fifo_t *p_fifo) \
117 return (type*)fifo_Show(p_fifo); \
119 static inline size_t prefix ## _fifo_GetCount(fifo_t *fifo) \
121 return fifo->i_depth; \
125 #endif /* VLC_FIFO_HELPER_H */