26
26
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
* Dynamic first in first out positive integer queue.
35
* Possitive integer values only.
34
* Dynamic first in first out positive integer queue.
35
* Possitive integer values only.
38
#ifndef __NET_DYNAMIC_FIFO_H__
39
#define __NET_DYNAMIC_FIFO_H__
38
#ifndef LIBC_DYNAMIC_FIFO_H_
39
#define LIBC_DYNAMIC_FIFO_H_
41
41
/** Type definition of the dynamic fifo queue.
44
44
typedef struct dyn_fifo dyn_fifo_t;
46
/** Type definition of the dynamic fifo queue pointer.
49
typedef dyn_fifo_t * dyn_fifo_ref;
51
46
/** Dynamic first in first out positive integer queue.
52
* Possitive integer values only.
53
* The queue automatically resizes if needed.
47
* Possitive integer values only.
48
* The queue automatically resizes if needed.
56
/** Stored item field.
59
/** Actual field size.
51
/** Stored item field. */
53
/** Actual field size. */
62
/** First item in the queue index.
55
/** First item in the queue index. */
65
/** Last item in the queue index.
57
/** Last item in the queue index. */
68
/** Consistency check magic value.
59
/** Consistency check magic value. */
73
/** Initializes the dynamic queue.
74
* @param[in,out] fifo The dynamic queue.
75
* @param[in] size The initial queue size.
76
* @returns EOK on success.
77
* @returns EINVAL if the queue is not valid.
78
* @returns EBADMEM if the fifo parameter is NULL.
79
* @returns ENOMEM if there is not enough memory left.
81
extern int dyn_fifo_initialize(dyn_fifo_ref fifo, int size);
83
/** Appends a new item to the queue end.
84
* @param[in,out] fifo The dynamic queue.
85
* @param[in] value The new item value. Should be positive.
86
* @param[in] max_size The maximum queue size. The queue is not resized beyound this limit. May be zero or negative (<=0) to indicate no limit.
87
* @returns EOK on success.
88
* @returns EINVAL if the queue is not valid.
89
* @returns ENOMEM if there is not enough memory left.
91
extern int dyn_fifo_push(dyn_fifo_ref fifo, int value, int max_size);
93
/** Returns and excludes the first item in the queue.
94
* @param[in,out] fifo The dynamic queue.
95
* @returns Value of the first item in the queue.
96
* @returns EINVAL if the queue is not valid.
97
* @returns ENOENT if the queue is empty.
99
extern int dyn_fifo_pop(dyn_fifo_ref fifo);
101
/** Returns and keeps the first item in the queue.
102
* @param[in,out] fifo The dynamic queue.
103
* @returns Value of the first item in the queue.
104
* @returns EINVAL if the queue is not valid.
105
* @returns ENOENT if the queue is empty.
107
extern int dyn_fifo_value(dyn_fifo_ref fifo);
109
/** Clears and destroys the queue.
110
* @param[in,out] fifo The dynamic queue.
111
* @returns EOK on success.
112
* @returns EINVAL if the queue is not valid.
114
extern int dyn_fifo_destroy(dyn_fifo_ref fifo);
63
extern int dyn_fifo_initialize(dyn_fifo_t *, int);
64
extern int dyn_fifo_destroy(dyn_fifo_t *);
65
extern int dyn_fifo_push(dyn_fifo_t *, int, int);
66
extern int dyn_fifo_pop(dyn_fifo_t *);
67
extern int dyn_fifo_value(dyn_fifo_t *);