~jakub/helenos/ia64-revival

« back to all changes in this revision

Viewing changes to uspace/lib/c/include/adt/dynamic_fifo.h

  • Committer: Jakub Jermar
  • Date: 2011-04-13 14:45:41 UTC
  • mfrom: (527.1.397 main-clone)
  • Revision ID: jakub@jermar.eu-20110413144541-x0j3r1zxqhsljx1o
MergeĀ mainlineĀ changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
27
 */
28
28
 
29
 
/** @addtogroup net
 
29
/** @addtogroup libc
30
30
 *  @{
31
31
 */
32
32
 
33
33
/** @file
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.
36
36
 */
37
37
 
38
 
#ifndef __NET_DYNAMIC_FIFO_H__
39
 
#define __NET_DYNAMIC_FIFO_H__
 
38
#ifndef LIBC_DYNAMIC_FIFO_H_
 
39
#define LIBC_DYNAMIC_FIFO_H_
40
40
 
41
41
/** Type definition of the dynamic fifo queue.
42
 
 *  @see dyn_fifo
 
42
 * @see dyn_fifo
43
43
 */
44
44
typedef struct dyn_fifo dyn_fifo_t;
45
45
 
46
 
/** Type definition of the dynamic fifo queue pointer.
47
 
 *  @see dyn_fifo
48
 
 */
49
 
typedef dyn_fifo_t *    dyn_fifo_ref;
50
 
 
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.
54
49
 */
55
 
struct dyn_fifo{
56
 
        /** Stored item field.
57
 
         */
58
 
        int *   items;
59
 
        /** Actual field size.
60
 
         */
 
50
struct dyn_fifo {
 
51
        /** Stored item field. */
 
52
        int *items;
 
53
        /** Actual field size. */
61
54
        int size;
62
 
        /** First item in the queue index.
63
 
         */
 
55
        /** First item in the queue index. */
64
56
        int head;
65
 
        /** Last item in the queue index.
66
 
         */
 
57
        /** Last item in the queue index. */
67
58
        int tail;
68
 
        /** Consistency check magic value.
69
 
         */
 
59
        /** Consistency check magic value. */
70
60
        int magic_value;
71
61
};
72
62
 
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.
80
 
 */
81
 
extern int dyn_fifo_initialize(dyn_fifo_ref fifo, int size);
82
 
 
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.
90
 
 */
91
 
extern int dyn_fifo_push(dyn_fifo_ref fifo, int value, int max_size);
92
 
 
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.
98
 
 */
99
 
extern int dyn_fifo_pop(dyn_fifo_ref fifo);
100
 
 
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.
106
 
 */
107
 
extern int dyn_fifo_value(dyn_fifo_ref fifo);
108
 
 
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.
113
 
 */
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 *);
115
68
 
116
69
#endif
117
70