source: branches/libc-0.6/src/emx/include/mpool.h

Last change on this file was 1506, checked in by bird, 21 years ago

@unixroot. header reviews. ++

  • Property cvs2svn:cvs-rev set to 1.2
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 4.0 KB
Line 
1/* mpool.h,v 1.2 2004/09/14 22:27:34 bird Exp */
2/** @file
3 * FreeBSD 5.1
4 */
5
6/*-
7 * Copyright (c) 1991, 1993, 1994
8 * The Regents of the University of California. All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the University of
21 * California, Berkeley and its contributors.
22 * 4. Neither the name of the University nor the names of its contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
37 *
38 * @(#)mpool.h 8.2 (Berkeley) 7/14/94
39 * $FreeBSD: src/include/mpool.h,v 1.9 2002/03/23 17:24:53 imp Exp $
40 */
41
42#ifndef _MPOOL_H_
43#define _MPOOL_H_
44
45#include <sys/queue.h>
46
47/*
48 * The memory pool scheme is a simple one. Each in-memory page is referenced
49 * by a bucket which is threaded in up to two of three ways. All active pages
50 * are threaded on a hash chain (hashed by page number) and an lru chain.
51 * Inactive pages are threaded on a free chain. Each reference to a memory
52 * pool is handed an opaque MPOOL cookie which stores all of this information.
53 */
54#define HASHSIZE 128
55#define HASHKEY(pgno) ((pgno - 1) % HASHSIZE)
56
57/* The BKT structures are the elements of the queues. */
58typedef struct _bkt {
59 TAILQ_ENTRY(_bkt) hq; /* hash queue */
60 TAILQ_ENTRY(_bkt) q; /* lru queue */
61 void *page; /* page */
62 pgno_t pgno; /* page number */
63
64#define MPOOL_DIRTY 0x01 /* page needs to be written */
65#define MPOOL_PINNED 0x02 /* page is pinned into memory */
66 u_int8_t flags; /* flags */
67} BKT;
68
69typedef struct MPOOL {
70 TAILQ_HEAD(_lqh, _bkt) lqh; /* lru queue head */
71 /* hash queue array */
72 TAILQ_HEAD(_hqh, _bkt) hqh[HASHSIZE];
73 pgno_t curcache; /* current number of cached pages */
74 pgno_t maxcache; /* max number of cached pages */
75 pgno_t npages; /* number of pages in the file */
76 u_long pagesize; /* file page size */
77 int fd; /* file descriptor */
78 /* page in conversion routine */
79 void (*pgin)(void *, pgno_t, void *);
80 /* page out conversion routine */
81 void (*pgout)(void *, pgno_t, void *);
82 void *pgcookie; /* cookie for page in/out routines */
83#ifdef STATISTICS
84 u_long cachehit;
85 u_long cachemiss;
86 u_long pagealloc;
87 u_long pageflush;
88 u_long pageget;
89 u_long pagenew;
90 u_long pageput;
91 u_long pageread;
92 u_long pagewrite;
93#endif
94} MPOOL;
95
96__BEGIN_DECLS
97MPOOL *mpool_open(void *, int, pgno_t, pgno_t);
98void mpool_filter(MPOOL *, void (*)(void *, pgno_t, void *),
99 void (*)(void *, pgno_t, void *), void *);
100void *mpool_new(MPOOL *, pgno_t *);
101void *mpool_get(MPOOL *, pgno_t, u_int);
102int mpool_put(MPOOL *, void *, u_int);
103int mpool_sync(MPOOL *);
104int mpool_close(MPOOL *);
105#ifdef STATISTICS
106void mpool_stat(MPOOL *);
107#endif
108__END_DECLS
109
110#endif
Note: See TracBrowser for help on using the repository browser.