comparison nss/lib/dbm/include/mpool.h @ 3:150b72113545

Add DBM and legacydb support
author Andre Heinecke <andre.heinecke@intevation.de>
date Tue, 05 Aug 2014 18:32:02 +0200
parents
children
comparison
equal deleted inserted replaced
2:a945361df361 3:150b72113545
1 /*-
2 * Copyright (c) 1991, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. ***REMOVED*** - see
14 * ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change
15 * 4. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 *
31 * @(#)mpool.h 8.2 (Berkeley) 7/14/94
32 */
33
34 #include <sys/queue.h>
35
36 /*
37 * The memory pool scheme is a simple one. Each in-memory page is referenced
38 * by a bucket which is threaded in up to two of three ways. All active pages
39 * are threaded on a hash chain (hashed by page number) and an lru chain.
40 * Inactive pages are threaded on a free chain. Each reference to a memory
41 * pool is handed an opaque MPOOL cookie which stores all of this information.
42 */
43 #define HASHSIZE 128
44 #define HASHKEY(pgno) ((pgno - 1) % HASHSIZE)
45
46 /* The BKT structures are the elements of the queues. */
47 typedef struct _bkt {
48 CIRCLEQ_ENTRY(_bkt) hq; /* hash queue */
49 CIRCLEQ_ENTRY(_bkt) q; /* lru queue */
50 void *page; /* page */
51 pgno_t pgno; /* page number */
52
53 #define MPOOL_DIRTY 0x01 /* page needs to be written */
54 #define MPOOL_PINNED 0x02 /* page is pinned into memory */
55 uint8 flags; /* flags */
56 } BKT;
57
58 typedef struct MPOOL {
59 CIRCLEQ_HEAD(_lqh, _bkt) lqh; /* lru queue head */
60 /* hash queue array */
61 CIRCLEQ_HEAD(_hqh, _bkt) hqh[HASHSIZE];
62 pgno_t curcache; /* current number of cached pages */
63 pgno_t maxcache; /* max number of cached pages */
64 pgno_t npages; /* number of pages in the file */
65 uint32 pagesize; /* file page size */
66 int fd; /* file descriptor */
67 /* page in conversion routine */
68 void (*pgin) (void *, pgno_t, void *);
69 /* page out conversion routine */
70 void (*pgout) (void *, pgno_t, void *);
71 void *pgcookie; /* cookie for page in/out routines */
72 #ifdef STATISTICS
73 uint32 cachehit;
74 uint32 cachemiss;
75 uint32 pagealloc;
76 uint32 pageflush;
77 uint32 pageget;
78 uint32 pagenew;
79 uint32 pageput;
80 uint32 pageread;
81 uint32 pagewrite;
82 #endif
83 } MPOOL;
84
85 __BEGIN_DECLS
86 MPOOL *mpool_open (void *, int, pgno_t, pgno_t);
87 void mpool_filter (MPOOL *, void (*)(void *, pgno_t, void *),
88 void (*)(void *, pgno_t, void *), void *);
89 void *mpool_new (MPOOL *, pgno_t *);
90 void *mpool_get (MPOOL *, pgno_t, uint);
91 int mpool_put (MPOOL *, void *, uint);
92 int mpool_sync (MPOOL *);
93 int mpool_close (MPOOL *);
94 #ifdef STATISTICS
95 void mpool_stat (MPOOL *);
96 #endif
97 __END_DECLS
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)