Lines Matching defs:q
23 obj2node(bqueue_t *q, void *data)
25 return ((bqueue_node_t *)((char *)data + q->bq_node_offset));
35 bqueue_init(bqueue_t *q, uint64_t size, size_t node_offset)
37 list_create(&q->bq_list, node_offset + sizeof (bqueue_node_t),
39 cv_init(&q->bq_add_cv, NULL, CV_DEFAULT, NULL);
40 cv_init(&q->bq_pop_cv, NULL, CV_DEFAULT, NULL);
41 mutex_init(&q->bq_lock, NULL, MUTEX_DEFAULT, NULL);
42 q->bq_node_offset = node_offset;
43 q->bq_size = 0;
44 q->bq_maxsize = size;
54 bqueue_destroy(bqueue_t *q)
56 ASSERT0(q->bq_size);
57 cv_destroy(&q->bq_add_cv);
58 cv_destroy(&q->bq_pop_cv);
59 mutex_destroy(&q->bq_lock);
60 list_destroy(&q->bq_list);
64 * Add data to q, consuming size units of capacity. If there is insufficient
69 bqueue_enqueue(bqueue_t *q, void *data, uint64_t item_size)
72 ASSERT3U(item_size, <, q->bq_maxsize);
73 mutex_enter(&q->bq_lock);
74 obj2node(q, data)->bqn_size = item_size;
75 while (q->bq_size + item_size > q->bq_maxsize) {
76 cv_wait(&q->bq_add_cv, &q->bq_lock);
78 q->bq_size += item_size;
79 list_insert_tail(&q->bq_list, data);
80 cv_signal(&q->bq_pop_cv);
81 mutex_exit(&q->bq_lock);
84 * Take the first element off of q. If there are no elements on the queue, wait
88 bqueue_dequeue(bqueue_t *q)
92 mutex_enter(&q->bq_lock);
93 while (q->bq_size == 0) {
94 cv_wait(&q->bq_pop_cv, &q->bq_lock);
96 ret = list_remove_head(&q->bq_list);
97 item_size = obj2node(q, ret)->bqn_size;
98 q->bq_size -= item_size;
99 mutex_exit(&q->bq_lock);
100 cv_signal(&q->bq_add_cv);
108 bqueue_empty(bqueue_t *q)
110 return (q->bq_size == 0);