1 /* 2 * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 3 * Use is subject to license terms. 4 */ 5 6 #ifndef _KRB5_DB2_MPOOL_MPOOL_H 7 #define _KRB5_DB2_MPOOL_MPOOL_H 8 9 #ifdef __cplusplus 10 extern "C" { 11 #endif 12 13 /* 14 * Copyright (c) 1991, 1993, 1994 15 * The Regents of the University of California. All rights reserved. 16 * 17 * Redistribution and use in source and binary forms, with or without 18 * modification, are permitted provided that the following conditions 19 * are met: 20 * 1. Redistributions of source code must retain the above copyright 21 * notice, this list of conditions and the following disclaimer. 22 * 2. Redistributions in binary form must reproduce the above copyright 23 * notice, this list of conditions and the following disclaimer in the 24 * documentation and/or other materials provided with the distribution. 25 * 3. All advertising materials mentioning features or use of this software 26 * must display the following acknowledgement: 27 * This product includes software developed by the University of 28 * California, Berkeley and its contributors. 29 * 4. Neither the name of the University nor the names of its contributors 30 * may be used to endorse or promote products derived from this software 31 * without specific prior written permission. 32 * 33 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 34 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 35 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 36 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 37 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 38 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 39 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 40 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 41 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 42 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 43 * SUCH DAMAGE. 44 * 45 * @(#)mpool.h 8.4 (Berkeley) 11/2/95 46 */ 47 48 #include "db-queue.h" 49 50 /* 51 * The memory pool scheme is a simple one. Each in-memory page is referenced 52 * by a bucket which is threaded in up to two of three ways. All active pages 53 * are threaded on a hash chain (hashed by page number) and an lru chain. 54 * Inactive pages are threaded on a free chain. Each reference to a memory 55 * pool is handed an opaque MPOOL cookie which stores all of this information. 56 */ 57 #define HASHSIZE 128 58 #define HASHKEY(pgno) ((pgno - 1) % HASHSIZE) 59 60 /* The BKT structures are the elements of the queues. */ 61 typedef struct _bkt { 62 CIRCLEQ_ENTRY(_bkt) hq; /* hash queue */ 63 CIRCLEQ_ENTRY(_bkt) q; /* lru queue */ 64 void *page; /* page */ 65 db_pgno_t pgno; /* page number */ 66 67 #define MPOOL_DIRTY 0x01 /* page needs to be written */ 68 #define MPOOL_PINNED 0x02 /* page is pinned into memory */ 69 #define MPOOL_INUSE 0x04 /* page address is valid */ 70 u_int8_t flags; /* flags */ 71 } BKT; 72 73 typedef struct MPOOL { 74 CIRCLEQ_HEAD(_lqh, _bkt) lqh; /* lru queue head */ 75 /* hash queue array */ 76 CIRCLEQ_HEAD(_hqh, _bkt) hqh[HASHSIZE]; 77 db_pgno_t curcache; /* current number of cached pages */ 78 db_pgno_t maxcache; /* max number of cached pages */ 79 db_pgno_t npages; /* number of pages in the file */ 80 u_long pagesize; /* file page size */ 81 int fd; /* file descriptor */ 82 /* page in conversion routine */ 83 void (*pgin) __P((void *, db_pgno_t, void *)); 84 /* page out conversion routine */ 85 void (*pgout) __P((void *, db_pgno_t, void *)); 86 void *pgcookie; /* cookie for page in/out routines */ 87 #ifdef STATISTICS 88 u_long cachehit; 89 u_long cachemiss; 90 u_long pagealloc; 91 u_long pageflush; 92 u_long pageget; 93 u_long pagenew; 94 u_long pageput; 95 u_long pageread; 96 u_long pagewrite; 97 #endif 98 } MPOOL; 99 100 #define MPOOL_IGNOREPIN 0x01 /* Ignore if the page is pinned. */ 101 #define MPOOL_PAGE_REQUEST 0x01 /* Allocate a new page with a 102 specific page number. */ 103 #define MPOOL_PAGE_NEXT 0x02 /* Allocate a new page with the next 104 page number. */ 105 106 #define mpool_open kdb2_mpool_open 107 #define mpool_filter kdb2_mpool_filter 108 #define mpool_new kdb2_mpool_new 109 #define mpool_get kdb2_mpool_get 110 #define mpool_delete kdb2_mpool_delete 111 #define mpool_put kdb2_mpool_put 112 #define mpool_sync kdb2_mpool_sync 113 #define mpool_close kdb2_mpool_close 114 #define mpool_stat kdb2_mpool_stat 115 116 __BEGIN_DECLS 117 MPOOL *mpool_open __P((void *, int, db_pgno_t, db_pgno_t)); 118 void mpool_filter __P((MPOOL *, void (*)(void *, db_pgno_t, void *), 119 void (*)(void *, db_pgno_t, void *), void *)); 120 void *mpool_new __P((MPOOL *, db_pgno_t *, u_int)); 121 void *mpool_get __P((MPOOL *, db_pgno_t, u_int)); 122 int mpool_delete __P((MPOOL *, void *)); 123 int mpool_put __P((MPOOL *, void *, u_int)); 124 int mpool_sync __P((MPOOL *)); 125 int mpool_close __P((MPOOL *)); 126 #ifdef STATISTICS 127 void mpool_stat __P((MPOOL *)); 128 #endif 129 __END_DECLS 130 131 #ifdef __cplusplus 132 } 133 #endif 134 135 #endif /* !_KRB5_DB2_MPOOL_MPOOL_H */ 136