Debian Codegraph @

terps/tads/tads2/mcs.h

raw symbols SCIP
1 /*
2 $Header: d:/cvsroot/tads/TADS2/MCS.H,v 1.2 1999/05/17 02:52:12 MJRoberts Exp $
3 */
4
5 /*
6 * Copyright (c) 1991, 2002 Michael J. Roberts. All Rights Reserved.
7 *
8 * Please see the accompanying license file, LICENSE.TXT, for information
9 * on using and copying this software.
10 */
11 /*
12 Name
13 mcs.h - memory cache swap manager
14 Function
15 Definitions for memory cache swap manager
16 Notes
17 The cache swap manager provides swap file services to the memory
18 cache manager. The cache manager calls the swap manager to write
19 objects to the swap file and read in previously swapped-out objects.
20 Modified
21 08/03/91 MJRoberts - creation
22 */
23
24 #ifndef MCS_INCLUDED
25 #define MCS_INCLUDED
26
27 #ifndef STD_INCLUDED
28 # include "std.h"
29 #endif
30 #ifndef ERR_INCLUDED
31 # include "err.h"
32 #endif
33
34
35 /* swap segment descriptor */
36 typedef struct mcsdsdef mcsdsdef;
37 struct mcsdsdef
38 {
39 ulong mcsdsptr; /* seek pointer in swap file */
40 ushort mcsdssiz; /* size of this swap segment */
41 ushort mcsdsosz; /* size of object written to segment */
42 uint mcsdsobj; /* client object ID */
43 ushort mcsdsflg; /* flags */
44 # define MCSDSFINUSE 0x01 /* segment is in use */
45 };
46
47
48 /*
49 * mcsseg - swap segment handle. All swap-file segments are addressed
50 * through this handle type.
51 */
52 typedef ushort mcsseg;
53
54 /* swap manager context */
55 typedef struct mcscxdef mcscxdef;
56 struct mcscxdef
57 {
58 osfildef *mcscxfp; /* swap file handle */
59 char *mcscxfname; /* name of swap file */
60 errcxdef *mcscxerr; /* error handling context */
61 ulong mcscxtop; /* top of swap file allocated so far */
62 ulong mcscxmax; /* maximum size of swap file we're allowed */
63 mcsdsdef **mcscxtab; /* swap descriptor page table */
64 mcsseg mcscxmsg; /* maximum segment allocated so far */
65 struct mcmcx1def *mcscxmem; /* memory manager context */
66 };
67
68 #define MCSSEGINV ((mcsseg)~0) /* invalid segment ID - error indicator */
69
70 /* initialize swapper - returns 0 for success, other for error */
71 void mcsini(struct mcscxdef *ctx, struct mcmcx1def *gmemctx, ulong maxsiz,
72 osfildef *fp, char *swapfilename, struct errcxdef *errctx);
73
74 /* close swapper (release memory areas) */
75 void mcsclose(struct mcscxdef *ctx);
76
77 /*
78 * Swap an object out. The caller specifies the location and size of
79 * the object, as well as a unique handle (arbitrary, up to the caller;
80 * the only requirement is that it be unique among all caller objects
81 * and always the same for a particular caller's object) and the
82 * previous swap handle if the object ever had one. If the object is
83 * not dirty (it hasn't been written since being swapped in), and the
84 * swap manager hasn't reused the swap slot, the swap manager doesn't
85 * need to write the memory, since it already has a copy on disk;
86 * instead, it can just mark the slot as back in use. If the caller
87 * doesn't wish to take advantage of this optimization, always pass in
88 * dirty == TRUE, which will force a write regardless of the object ID.
89 */
90 mcsseg mcsout(struct mcscxdef *ctx, uint objid, uchar *objptr,
91 ushort objsize, mcsseg oldswapseg, int dirty);
92
93 /* Swap an object in */
94 void mcsin(struct mcscxdef *ctx, mcsseg swapseg, uchar *objptr, ushort size);
95
96
97 /* number of page pointers in page table (max number of pages) */
98 #define MCSPAGETAB 256
99
100 /* number of swap descriptors in a page */
101 #define MCSPAGECNT 256
102
103 /* find swap descriptor corresponding to swap segment number */
104 #define mcsdsc(ctx,seg) (&(ctx)->mcscxtab[(seg)>>8][(seg)&255])
105
106 /* write out a swap segment */
107 void mcswrt(mcscxdef *ctx, mcsdsdef *desc, uchar *buf, ushort bufl);
108
109 #endif /* MCS_INCLUDED */