cache-node.h 3.39 KB
Newer Older
Per Cederqvist's avatar
Per Cederqvist committed
1
/*
2
3
 * $Id: cache-node.h,v 0.13 1999/05/24 09:34:19 ceder Exp $
 * Copyright (C) 1991, 1993-1995, 1997, 1999  Lysator Academic Computer Association.
Linus Tolke's avatar
Linus Tolke committed
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
 *
 * This file is part of the LysKOM server.
 * 
 * LysKOM is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by 
 * the Free Software Foundation; either version 1, or (at your option) 
 * any later version.
 * 
 * LysKOM is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with LysKOM; see the file COPYING.  If not, write to
 * Lysator, c/o ISY, Linkoping University, S-581 83 Linkoping, SWEDEN,
 * or the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, 
 * MA 02139, USA.
 *
 * Please mail bug reports to bug-lyskom@lysator.liu.se. 
 */
/*
26
 * $Id: cache-node.h,v 0.13 1999/05/24 09:34:19 ceder Exp $
Per Cederqvist's avatar
Per Cederqvist committed
27
 *
Per Cederqvist's avatar
Per Cederqvist committed
28
29
30
31
32
 * cache-node.h
 */

typedef struct cache_node {
    struct {
Per Cederqvist's avatar
Per Cederqvist committed
33
	unsigned int	exists : 1;
David Byers's avatar
David Byers committed
34
35
	unsigned int	dirty : 1;    /* Is *ptr modified? */
        unsigned int    snapshot : 1; /* We have a valid snapshot */
Per Cederqvist's avatar
Per Cederqvist committed
36
37
38
39
40
41
    } s;
    void   *snap_shot;		/* Dirty data to be written to file B. */
				/* (Dirty relative to file A). */
    void   *ptr;		/* In-core data. */
    long   pos;			/* Position to element in file A. */
    long   size;		/* Size on disk. */
David Byers's avatar
David Byers committed
42
43
44
45
#ifdef FASTSAVE
    long   saved_pos;           /* Position saved in case of recover */
    long   saved_size;          /* Size saved in case of recover */
#else
Per Cederqvist's avatar
Per Cederqvist committed
46
47
    long   pos_b;		/* Position to element in file B. */
    long   size_b;		/* Size in file B. */
David Byers's avatar
David Byers committed
48
#endif
Per Cederqvist's avatar
Per Cederqvist committed
49
50
    struct cache_node *prev;	/* Points towards most recently used. */
    struct cache_node *next;	/* Points towards least recently used. */
Per Cederqvist's avatar
Per Cederqvist committed
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
    int	lock_cnt;
} Cache_node;

extern const Cache_node EMPTY_CACHE_NODE;


typedef struct cache_node_block {
    int next_free;
    Cache_node *nodes;		/* Pointer to an array with
				   mcb_size elements. */
    struct cache_node_block *link; /* Points to previous block. */
} Cache_node_block;

extern const Cache_node_block EMPTY_CACHE_NODE_BLOCK;
	  

typedef struct cache_node_mcb {
    int mcb_size;		/* Number of cache_nodes in each block. */
    Cache_node_block *last_block; /* The block where new cache_nodes
				   * can be allocated. */
Per Cederqvist's avatar
Per Cederqvist committed
71
72
    unsigned long hits;
    unsigned long misses;
Per Cederqvist's avatar
Per Cederqvist committed
73
74
    Cache_node	*mru;
    Cache_node	*lru;
Per Cederqvist's avatar
Per Cederqvist committed
75
    unsigned long lookup_table_size;
Per Cederqvist's avatar
Per Cederqvist committed
76
    Cache_node	**lookup_table;	/* Easy to implement, but memory expensive. */
Per Cederqvist's avatar
Per Cederqvist committed
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
} Cache_node_mcb;


extern const Cache_node_mcb EMPTY_CACHE_NODE_MCB;

extern  void
unlink_lru(Cache_node *node,
	   Cache_node **lru,
	   Cache_node **mru);


extern Cache_node_mcb *
create_cache_node_mcb(int mcb_size, 
		      int table_size);


Per Cederqvist's avatar
Per Cederqvist committed
93
94
extern void
destruct_cache_node(Cache_node_mcb  *control,
Per Cederqvist's avatar
Per Cederqvist committed
95
		    unsigned long           key);
Per Cederqvist's avatar
Per Cederqvist committed
96

Per Cederqvist's avatar
Per Cederqvist committed
97
98
extern Cache_node *
get_cache_node (Cache_node_mcb *control,
Per Cederqvist's avatar
Per Cederqvist committed
99
		unsigned long          key);
Per Cederqvist's avatar
Per Cederqvist committed
100
101
102
103


extern  void
create_cache_node (Cache_node_mcb *control,
Per Cederqvist's avatar
Per Cederqvist committed
104
		   unsigned long          key);
Per Cederqvist's avatar
Per Cederqvist committed
105
106


Per Cederqvist's avatar
Per Cederqvist committed
107
108
extern  void
zero_init_cache_node (Cache_node_mcb *control,
Per Cederqvist's avatar
Per Cederqvist committed
109
		      unsigned long          key);
Per Cederqvist's avatar
Per Cederqvist committed
110

Per Cederqvist's avatar
Per Cederqvist committed
111
112
extern void
set_mru(Cache_node_mcb *mcb,
Per Cederqvist's avatar
Per Cederqvist committed
113
	unsigned long         key);
Per Cederqvist's avatar
Per Cederqvist committed
114
115


Per Cederqvist's avatar
Per Cederqvist committed
116
117
extern void
free_cache_node_mcb(Cache_node_mcb *control);