Lines Matching refs:fqp

46     struct mkuz_fifo_queue *fqp;  in mkuz_fqueue_ctor()  local
48 fqp = mkuz_safe_zmalloc(sizeof(struct mkuz_fifo_queue)); in mkuz_fqueue_ctor()
49 fqp->wakeup_len = wakeup_len; in mkuz_fqueue_ctor()
50 if (pthread_mutex_init(&fqp->mtx, NULL) != 0) { in mkuz_fqueue_ctor()
53 if (pthread_cond_init(&fqp->cvar, NULL) != 0) { in mkuz_fqueue_ctor()
56 return (fqp); in mkuz_fqueue_ctor()
60 mkuz_fqueue_enq(struct mkuz_fifo_queue *fqp, struct mkuz_blk *bp) in mkuz_fqueue_enq() argument
67 pthread_mutex_lock(&fqp->mtx); in mkuz_fqueue_enq()
68 if (fqp->first != NULL) { in mkuz_fqueue_enq()
69 fqp->first->prev = ip; in mkuz_fqueue_enq()
71 fqp->last = ip; in mkuz_fqueue_enq()
73 fqp->first = ip; in mkuz_fqueue_enq()
74 fqp->length += 1; in mkuz_fqueue_enq()
75 if (fqp->length >= fqp->wakeup_len) { in mkuz_fqueue_enq()
76 pthread_cond_signal(&fqp->cvar); in mkuz_fqueue_enq()
78 pthread_mutex_unlock(&fqp->mtx); in mkuz_fqueue_enq()
83 mkuz_fqueue_enq_all(struct mkuz_fifo_queue *fqp, struct mkuz_bchain_link *cip_f, in mkuz_fqueue_enq_all() argument
88 pthread_mutex_lock(&fqp->mtx); in mkuz_fqueue_enq_all()
89 if (fqp->first != NULL) { in mkuz_fqueue_enq_all()
90 fqp->first->prev = cip_l; in mkuz_fqueue_enq_all()
92 fqp->last = cip_l; in mkuz_fqueue_enq_all()
94 fqp->first = cip_f; in mkuz_fqueue_enq_all()
95 fqp->length += clen; in mkuz_fqueue_enq_all()
96 rval = fqp->length; in mkuz_fqueue_enq_all()
97 if (fqp->length >= fqp->wakeup_len) { in mkuz_fqueue_enq_all()
98 pthread_cond_signal(&fqp->cvar); in mkuz_fqueue_enq_all()
100 pthread_mutex_unlock(&fqp->mtx); in mkuz_fqueue_enq_all()
106 mkuz_fqueue_check(struct mkuz_fifo_queue *fqp, cmp_cb_t cmp_cb, void *cap) in mkuz_fqueue_check() argument
110 for (ip = fqp->last; ip != NULL; ip = ip->prev) { in mkuz_fqueue_check()
119 mkuz_fqueue_deq_when(struct mkuz_fifo_queue *fqp, cmp_cb_t cmp_cb, void *cap) in mkuz_fqueue_deq_when() argument
124 pthread_mutex_lock(&fqp->mtx); in mkuz_fqueue_deq_when()
125 while (fqp->last == NULL || !mkuz_fqueue_check(fqp, cmp_cb, cap)) { in mkuz_fqueue_deq_when()
126 pthread_cond_wait(&fqp->cvar, &fqp->mtx); in mkuz_fqueue_deq_when()
128 if (cmp_cb(fqp->last->this, cap)) { in mkuz_fqueue_deq_when()
129 mip = fqp->last; in mkuz_fqueue_deq_when()
130 fqp->last = mip->prev; in mkuz_fqueue_deq_when()
131 if (fqp->last == NULL) { in mkuz_fqueue_deq_when()
133 assert(fqp->length == 1); in mkuz_fqueue_deq_when()
135 fqp->first = NULL; in mkuz_fqueue_deq_when()
139 assert(fqp->length > 1); in mkuz_fqueue_deq_when()
141 newfirst = newlast = fqp->last; in mkuz_fqueue_deq_when()
143 for (ip = fqp->last->prev; ip != NULL; ip = ip->prev) { in mkuz_fqueue_deq_when()
152 fqp->first = newfirst; in mkuz_fqueue_deq_when()
153 fqp->last = newlast; in mkuz_fqueue_deq_when()
155 fqp->length -= 1; in mkuz_fqueue_deq_when()
156 pthread_mutex_unlock(&fqp->mtx); in mkuz_fqueue_deq_when()
164 mkuz_fqueue_deq(struct mkuz_fifo_queue *fqp) in mkuz_fqueue_deq() argument
169 pthread_mutex_lock(&fqp->mtx); in mkuz_fqueue_deq()
170 while (fqp->last == NULL) { in mkuz_fqueue_deq()
171 pthread_cond_wait(&fqp->cvar, &fqp->mtx); in mkuz_fqueue_deq()
174 assert(fqp->length > 0); in mkuz_fqueue_deq()
176 ip = fqp->last; in mkuz_fqueue_deq()
177 fqp->last = ip->prev; in mkuz_fqueue_deq()
178 if (fqp->last == NULL) { in mkuz_fqueue_deq()
180 assert(fqp->length == 1); in mkuz_fqueue_deq()
182 fqp->first = NULL; in mkuz_fqueue_deq()
184 fqp->length -= 1; in mkuz_fqueue_deq()
185 pthread_mutex_unlock(&fqp->mtx); in mkuz_fqueue_deq()
194 mkuz_fqueue_deq_all(struct mkuz_fifo_queue *fqp, int *rclen) in mkuz_fqueue_deq_all() argument
198 pthread_mutex_lock(&fqp->mtx); in mkuz_fqueue_deq_all()
199 while (fqp->last == NULL) { in mkuz_fqueue_deq_all()
200 pthread_cond_wait(&fqp->cvar, &fqp->mtx); in mkuz_fqueue_deq_all()
203 assert(fqp->length > 0); in mkuz_fqueue_deq_all()
205 rchain = fqp->last; in mkuz_fqueue_deq_all()
206 fqp->first = fqp->last = NULL; in mkuz_fqueue_deq_all()
207 *rclen = fqp->length; in mkuz_fqueue_deq_all()
208 fqp->length = 0; in mkuz_fqueue_deq_all()
209 pthread_mutex_unlock(&fqp->mtx); in mkuz_fqueue_deq_all()