summaryrefslogtreecommitdiffstats
path: root/src/mpq.h
blob: ff401b0c266d180c3ab3f78d8136df6a7f240578 (plain) (blame)
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
#ifndef _MPQ_H_
#define _MPQ_H_

#include <sys/mutex.h>
#include <sys/task.h>
#include <sys/queue.h>

struct mpq_item {
	TAILQ_ENTRY(mpq_item) i_worker;
	TAILQ_ENTRY(mpq_item) i_serial;
	struct cond i_cond;
	enum mpq_istate {
		MPQ_ITEM_WAITING,
		MPQ_ITEM_PROCESSED,
		MPQ_ITEM_BARRIER,
	} i_state;
	void *i_val;
};

struct mpq {
	struct mutex q_mtx;
	struct taskq *q_taskq;
	struct rwlock q_serial_lock;

	size_t q_max;
	size_t q_len;

	struct task q_worker_task;
	struct task q_serial_task;

	void (*q_worker_fn)(void *);
	void (*q_serial_fn)(void *);

	TAILQ_HEAD(, mpq_item) q_worker_items;
	TAILQ_HEAD(, mpq_item) q_serial_items;
};

void mpq_init(struct mpq *, struct taskq *, int ipl, void (*)(void *), void (*)(void *), size_t);
int mpq_add(struct mpq *, void *);
int mpq_active(struct mpq *);
size_t mpq_len(struct mpq *);

#endif /* _MPQ_H_ */