80a589eb4c0ebef4d65351418673379fbd6fcc7c
   1#ifndef MRU_H
   2#define MRU_H
   3
   4#include "list.h"
   5
   6/**
   7 * A simple most-recently-used cache, backed by a doubly-linked list.
   8 *
   9 * Usage is roughly:
  10 *
  11 *   // Create a list.  Zero-initialization is required.
  12 *   static struct mru cache;
  13 *   INIT_LIST_HEAD(&cache.list);
  14 *
  15 *   // Add new item to the end of the list.
  16 *   void *item;
  17 *   ...
  18 *   mru_append(&cache, item);
  19 *
  20 *   // Mark an item as used, moving it to the front of the list.
  21 *   mru_mark(&cache, item);
  22 *
  23 *   // Reset the list to empty, cleaning up all resources.
  24 *   mru_clear(&cache);
  25 *
  26 * Note that you SHOULD NOT call mru_mark() and then continue traversing the
  27 * list; it reorders the marked item to the front of the list, and therefore
  28 * you will begin traversing the whole list again.
  29 */
  30
  31struct mru {
  32        struct list_head list;
  33        void *item;
  34};
  35
  36void mru_append(struct mru *head, void *item);
  37void mru_mark(struct mru *head, struct mru *entry);
  38void mru_clear(struct mru *head);
  39
  40#endif /* MRU_H */