summaryrefslogtreecommitdiff
path: root/mru.c
blob: 8f3f34c5ba91dae7dea4b9fb2a72dc63581f4e78 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include "cache.h"
#include "mru.h"

void mru_append(struct mru *head, void *item)
{
	struct mru *cur = xmalloc(sizeof(*cur));
	cur->item = item;
	list_add_tail(&cur->list, &head->list);
}

void mru_mark(struct mru *head, struct mru *entry)
{
	/* To mark means to put at the front of the list. */
	list_del(&entry->list);
	list_add(&entry->list, &head->list);
}

void mru_clear(struct mru *head)
{
	struct list_head *pos;
	struct list_head *tmp;

	list_for_each_safe(pos, tmp, &head->list) {
		free(list_entry(pos, struct mru, list));
	}
	INIT_LIST_HEAD(&head->list);
}