xref: /csrg-svn/lib/libc/db/btree/lrucache.h (revision 46140)
1*46140Smao /*-
2*46140Smao  * Copyright (c) 1990 The Regents of the University of California.
3*46140Smao  * All rights reserved.
4*46140Smao  *
5*46140Smao  * This code is derived from software contributed to Berkeley by
6*46140Smao  * Mike Olson.
7*46140Smao  *
8*46140Smao  * %sccs.include.redist.c%
9*46140Smao  */
10*46140Smao 
11*46140Smao /*
12*46140Smao  * @(#)lrucache.h	5.1 (Berkeley) 01/23/91
13*46140Smao  */
14*46140Smao 
15*46140Smao /*
16*46140Smao  *  LRU list entries.  The head of the list is the most-recently requested
17*46140Smao  *  block; the tail is the least-recently requested one.
18*46140Smao  */
19*46140Smao 
20*46140Smao typedef struct LRU_ENT {
21*46140Smao 	char	*l_buffer;		/* buffer we return to user */
22*46140Smao 	int	l_pgno;			/* logical page number */
23*46140Smao 	int	l_flags;		/* FREE and DIRTY bits */
24*46140Smao 	struct LRU_ENT	*l_prev;	/* predecessor in LRU list */
25*46140Smao 	struct LRU_ENT	*l_next;	/* successor in LRU list */
26*46140Smao } LRU_ENT;
27*46140Smao 
28*46140Smao /*
29*46140Smao  *  Cache entries.  We use a hash table to avoid a linear walk of the LRU
30*46140Smao  *  list when we need to look up blocks by number.  The hash table is
31*46140Smao  *  chained.
32*46140Smao  */
33*46140Smao 
34*46140Smao typedef struct CACHE_ENT {
35*46140Smao 	int			c_pgno;
36*46140Smao 	LRU_ENT			*c_lruent;
37*46140Smao 	struct CACHE_ENT	*c_chain;
38*46140Smao } CACHE_ENT;
39*46140Smao 
40*46140Smao /*
41*46140Smao  *  The LRU cache structure.  The cache size (lru_csize) is the largest size
42*46140Smao  *  the user wants us to grow to; current size (lru_cursz) is always less than
43*46140Smao  *  or equal to lru_csize.  Note that we will grow the cache (lru_csize) if
44*46140Smao  *  it's the only way that we can satisfy a user's block request.
45*46140Smao  */
46*46140Smao 
47*46140Smao typedef struct LRUCACHE {
48*46140Smao 	int		lru_fd;
49*46140Smao 	int		lru_csize;
50*46140Smao 	int		lru_psize;
51*46140Smao 	int		lru_cursz;
52*46140Smao 	char		*lru_opaque;		/* passed to inproc, outproc */
53*46140Smao 	int		(*lru_inproc)();
54*46140Smao 	int		(*lru_outproc)();
55*46140Smao 	LRU_ENT		*lru_head;
56*46140Smao 	LRU_ENT		*lru_tail;
57*46140Smao 	CACHE_ENT	**lru_cache;
58*46140Smao } LRUCACHE;
59*46140Smao 
60*46140Smao #ifndef NULL
61*46140Smao #define NULL	0
62*46140Smao #endif /* ndef NULL */
63*46140Smao 
64*46140Smao /* this is the opaque type we return for LRU caches */
65*46140Smao typedef	char	*LRU;
66*46140Smao 
67*46140Smao /* bits for l_flags in LRU_ENT structure */
68*46140Smao #define	F_DIRTY		(1 << 0)
69*46140Smao #define F_FREE		(1 << 1)
70*46140Smao 
71*46140Smao /* lru module routines */
72*46140Smao extern CACHE_ENT	*lruhashget();
73*46140Smao extern CACHE_ENT	*lruhashput();
74*46140Smao extern int 		lruhashdel();
75*46140Smao extern void		lruhead();
76*46140Smao extern int 		lrugrow();
77*46140Smao extern LRU		lruinit();
78*46140Smao extern int		lruwrite();
79*46140Smao extern int		lrusync();
80*46140Smao extern char		*lruget();
81*46140Smao extern char		*lrugetnew();
82*46140Smao extern char		*lrugetpg();
83*46140Smao extern int		lrurelease();
84*46140Smao extern void		lrufree();
85