xref: /freebsd/sys/contrib/openzfs/include/sys/bqueue.h (revision 61145dc2b94f12f6a47344fb9aac702321880e43)
1 // SPDX-License-Identifier: CDDL-1.0
2 /*
3  * CDDL HEADER START
4  *
5  * This file and its contents are supplied under the terms of the
6  * Common Development and Distribution License ("CDDL"), version 1.0.
7  * You may only use this file in accordance with the terms of version
8  * 1.0 of the CDDL.
9  *
10  * A full copy of the text of the CDDL should have accompanied this
11  * source.  A copy of the CDDL is also available via the Internet at
12  * http://www.illumos.org/license/CDDL.
13  *
14  * CDDL HEADER END
15  */
16 /*
17  * Copyright (c) 2014, 2018 by Delphix. All rights reserved.
18  */
19 
20 #ifndef	_BQUEUE_H
21 #define	_BQUEUE_H
22 
23 #ifdef	__cplusplus
24 extern "C" {
25 #endif
26 
27 #include	<sys/zfs_context.h>
28 
29 typedef struct bqueue {
30 	list_t bq_list;
31 	size_t bq_size;
32 	list_t bq_dequeuing_list;
33 	size_t bq_dequeuing_size;
34 	list_t bq_enqueuing_list;
35 	size_t bq_enqueuing_size;
36 	kmutex_t bq_lock;
37 	kcondvar_t bq_add_cv;
38 	kcondvar_t bq_pop_cv;
39 	size_t bq_maxsize;
40 	uint_t bq_fill_fraction;
41 	size_t bq_node_offset;
42 } bqueue_t;
43 
44 typedef struct bqueue_node {
45 	list_node_t bqn_node;
46 	size_t bqn_size;
47 } bqueue_node_t;
48 
49 
50 int bqueue_init(bqueue_t *, uint_t, size_t, size_t);
51 void bqueue_destroy(bqueue_t *);
52 void bqueue_enqueue(bqueue_t *, void *, size_t);
53 void bqueue_enqueue_flush(bqueue_t *, void *, size_t);
54 void *bqueue_dequeue(bqueue_t *);
55 
56 #ifdef	__cplusplus
57 }
58 #endif
59 
60 #endif	/* _BQUEUE_H */
61