summaryrefslogtreecommitdiff
path: root/include/queue.h
blob: 9213b3dd35e3ea0dd07c17d40f77a2ad274c0aba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#ifndef _QUEUE_H_
#define _QUEUE_H_

#include <stdint.h>
#include "linux_list.h"

struct queue_node {
	struct list_head	head;
	uint32_t		type;
	struct queue		*owner;
	size_t 			size;
};

enum {
	Q_ELEM_OBJ = 0,
	Q_ELEM_CTL = 1
};

void queue_node_init(struct queue_node *n, int type);
void *queue_node_data(struct queue_node *n);

struct queue_object {
	struct queue_node	qnode;
	char			data[0];
};

struct queue_object *queue_object_new(int type, size_t size);
void queue_object_free(struct queue_object *obj);

struct evfd;

struct queue {
	unsigned int		max_elems;
	unsigned int		num_elems;
	uint32_t		flags;
	struct list_head	head;
	struct evfd		*evfd;
};

#define QUEUE_F_EVFD (1U << 0)

struct queue *queue_create(int max_objects, unsigned int flags);
void queue_destroy(struct queue *b);
unsigned int queue_len(const struct queue *b);
int queue_add(struct queue *b, struct queue_node *n);
int queue_del(struct queue_node *n);
struct queue_node *queue_del_head(struct queue *b);
int queue_in(struct queue *b, struct queue_node *n);
void queue_iterate(struct queue *b,
		   const void *data,
		   int (*iterate)(struct queue_node *n, const void *data2));
int queue_get_eventfd(struct queue *b);

#endif