1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/security/nss/lib/dbm/include/mpool.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,97 @@ 1.4 +/*- 1.5 + * Copyright (c) 1991, 1993, 1994 1.6 + * The Regents of the University of California. All rights reserved. 1.7 + * 1.8 + * Redistribution and use in source and binary forms, with or without 1.9 + * modification, are permitted provided that the following conditions 1.10 + * are met: 1.11 + * 1. Redistributions of source code must retain the above copyright 1.12 + * notice, this list of conditions and the following disclaimer. 1.13 + * 2. Redistributions in binary form must reproduce the above copyright 1.14 + * notice, this list of conditions and the following disclaimer in the 1.15 + * documentation and/or other materials provided with the distribution. 1.16 + * 3. ***REMOVED*** - see 1.17 + * ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change 1.18 + * 4. Neither the name of the University nor the names of its contributors 1.19 + * may be used to endorse or promote products derived from this software 1.20 + * without specific prior written permission. 1.21 + * 1.22 + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 1.23 + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1.24 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1.25 + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 1.26 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1.27 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 1.28 + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 1.29 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 1.30 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 1.31 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 1.32 + * SUCH DAMAGE. 1.33 + * 1.34 + * @(#)mpool.h 8.2 (Berkeley) 7/14/94 1.35 + */ 1.36 + 1.37 +#include <sys/queue.h> 1.38 + 1.39 +/* 1.40 + * The memory pool scheme is a simple one. Each in-memory page is referenced 1.41 + * by a bucket which is threaded in up to two of three ways. All active pages 1.42 + * are threaded on a hash chain (hashed by page number) and an lru chain. 1.43 + * Inactive pages are threaded on a free chain. Each reference to a memory 1.44 + * pool is handed an opaque MPOOL cookie which stores all of this information. 1.45 + */ 1.46 +#define HASHSIZE 128 1.47 +#define HASHKEY(pgno) ((pgno - 1) % HASHSIZE) 1.48 + 1.49 +/* The BKT structures are the elements of the queues. */ 1.50 +typedef struct _bkt { 1.51 + CIRCLEQ_ENTRY(_bkt) hq; /* hash queue */ 1.52 + CIRCLEQ_ENTRY(_bkt) q; /* lru queue */ 1.53 + void *page; /* page */ 1.54 + pgno_t pgno; /* page number */ 1.55 + 1.56 +#define MPOOL_DIRTY 0x01 /* page needs to be written */ 1.57 +#define MPOOL_PINNED 0x02 /* page is pinned into memory */ 1.58 + uint8 flags; /* flags */ 1.59 +} BKT; 1.60 + 1.61 +typedef struct MPOOL { 1.62 + CIRCLEQ_HEAD(_lqh, _bkt) lqh; /* lru queue head */ 1.63 + /* hash queue array */ 1.64 + CIRCLEQ_HEAD(_hqh, _bkt) hqh[HASHSIZE]; 1.65 + pgno_t curcache; /* current number of cached pages */ 1.66 + pgno_t maxcache; /* max number of cached pages */ 1.67 + pgno_t npages; /* number of pages in the file */ 1.68 + uint32 pagesize; /* file page size */ 1.69 + int fd; /* file descriptor */ 1.70 + /* page in conversion routine */ 1.71 + void (*pgin) (void *, pgno_t, void *); 1.72 + /* page out conversion routine */ 1.73 + void (*pgout) (void *, pgno_t, void *); 1.74 + void *pgcookie; /* cookie for page in/out routines */ 1.75 +#ifdef STATISTICS 1.76 + uint32 cachehit; 1.77 + uint32 cachemiss; 1.78 + uint32 pagealloc; 1.79 + uint32 pageflush; 1.80 + uint32 pageget; 1.81 + uint32 pagenew; 1.82 + uint32 pageput; 1.83 + uint32 pageread; 1.84 + uint32 pagewrite; 1.85 +#endif 1.86 +} MPOOL; 1.87 + 1.88 +__BEGIN_DECLS 1.89 +MPOOL *mpool_open (void *, int, pgno_t, pgno_t); 1.90 +void mpool_filter (MPOOL *, void (*)(void *, pgno_t, void *), 1.91 + void (*)(void *, pgno_t, void *), void *); 1.92 +void *mpool_new (MPOOL *, pgno_t *); 1.93 +void *mpool_get (MPOOL *, pgno_t, uint); 1.94 +int mpool_put (MPOOL *, void *, uint); 1.95 +int mpool_sync (MPOOL *); 1.96 +int mpool_close (MPOOL *); 1.97 +#ifdef STATISTICS 1.98 +void mpool_stat (MPOOL *); 1.99 +#endif 1.100 +__END_DECLS