[client] ll: add new method ll_peek_tail

This commit is contained in:
Geoffrey McRae 2021-01-06 22:11:10 +11:00
parent 67022d664f
commit 271276a0a9
2 changed files with 20 additions and 2 deletions

View File

@ -25,7 +25,8 @@ void ll_free (struct ll * list);
void ll_push (struct ll * list, void * data);
bool ll_shift (struct ll * list, void ** data);
bool ll_peek_head(struct ll * list, void ** data);
bool ll_peek_tail(struct ll * list, void ** data);
unsigned int ll_count (struct ll * list);
void ll_reset (struct ll * list);
bool ll_walk (struct ll * list, void ** data);
bool ll_walk (struct ll * list, void ** data);

View File

@ -92,8 +92,10 @@ bool ll_shift(struct ll * list, void ** data)
--list->count;
struct ll_item * item = list->head;
list->head = item->next;
list->pos = NULL;
if (list->tail == item)
list->tail = NULL;
list->pos = NULL;
LG_UNLOCK(list->lock);
if (data)
@ -118,6 +120,21 @@ bool ll_peek_head(struct ll * list, void ** data)
return true;
}
bool ll_peek_tail(struct ll * list, void ** data)
{
LG_LOCK(list->lock);
if (!list->tail)
{
LG_UNLOCK(list->lock);
return false;
}
*data = list->tail->data;
LG_UNLOCK(list->lock);
return true;
}
unsigned int ll_count(struct ll * list)
{
return list->count;