enhance ordq

This commit is contained in:
Rongsong Shen 2025-12-17 12:14:52 +08:00
parent e85ce0e5ad
commit 48ab2e60a2
4 changed files with 119 additions and 14 deletions

View file

@ -80,28 +80,48 @@ void ordq_fini(ordq_t* q)
mylock_fini(&(q->lock));
}
ordq_item_t* ordq_get(ordq_t* q)
static ordq_item_t* ordq_get_(ordq_t* q, ordq_skip_fn_t skipfn)
{
ordq_item_t** p = &(q->head);
while ((*p) != NULL) {
if ((skipfn == NULL) || !skipfn(q->ctx, (*p))) {
ordq_item_t* it = (*p);
*p = it->next;
it->next = NULL;
return it;
}
p = &((*p)->next);
}
return NULL;
}
ordq_item_t* ordq_get(ordq_t* q, ordq_skip_fn_t skipfn)
{
ordq_item_t* it;
mylock_lock(&(q->lock));
it = q->head;
if (it != NULL) {
q->head = it->next;
}
it = ordq_get_(q, skipfn);
mylock_unlock(&(q->lock));
return it;
}
ordq_item_t* ordq_peek(ordq_t* q)
ordq_item_t* ordq_peek(ordq_t* q, ordq_skip_fn_t skipfn)
{
ordq_item_t* it = NULL;
mylock_lock(&(q->lock));
it = q->head;
while (it != NULL) {
if ((skipfn == NULL) || !skipfn(q->ctx, it)) {
break;
}
it = it->next;
}
mylock_unlock(&(q->lock));
return it;