blob: 655c94b057a07025e54826375c5245cc3b134996 [file] [log] [blame]
SE Android8c48de12012-01-24 05:27:18 -08001
2/* Author : Stephen Smalley, <sds@epoch.ncsc.mil> */
3
4/* FLASK */
5
6/*
7 * A double-ended queue is a singly linked list of
8 * elements of arbitrary type that may be accessed
9 * at either end.
10 */
11
12#ifndef _QUEUE_H_
13#define _QUEUE_H_
14
15typedef void *queue_element_t;
16
17typedef struct queue_node *queue_node_ptr_t;
18
19typedef struct queue_node {
20 queue_element_t element;
21 queue_node_ptr_t next;
22} queue_node_t;
23
24typedef struct queue_info {
25 queue_node_ptr_t head;
26 queue_node_ptr_t tail;
27} queue_info_t;
28
29typedef queue_info_t *queue_t;
30
31queue_t queue_create(void);
32int queue_insert(queue_t, queue_element_t);
33int queue_push(queue_t, queue_element_t);
34queue_element_t queue_remove(queue_t);
35queue_element_t queue_head(queue_t);
36void queue_destroy(queue_t);
37
38/*
39 Applies the specified function f to each element in the
40 specified queue.
41
42 In addition to passing the element to f, queue_map
43 passes the specified void* pointer to f on each invocation.
44
45 If f returns a non-zero status, then queue_map will cease
46 iterating through the hash table and will propagate the error
47 return to its caller.
48 */
49int queue_map(queue_t, int (*f) (queue_element_t, void *), void *);
50
51/*
52 Same as queue_map, except that if f returns a non-zero status,
53 then the element will be removed from the queue and the g
54 function will be applied to the element.
55 */
56void queue_map_remove_on_error(queue_t,
57 int (*f) (queue_element_t, void *),
58 void (*g) (queue_element_t, void *), void *);
59
60#endif
61
62/* FLASK */