bottleneck testcase based on rubbos
[bottlenecks.git] / rubbos / app / apache2 / include / apr_mmap.h
1 /* Licensed to the Apache Software Foundation (ASF) under one or more
2  * contributor license agreements.  See the NOTICE file distributed with
3  * this work for additional information regarding copyright ownership.
4  * The ASF licenses this file to You under the Apache License, Version 2.0
5  * (the "License"); you may not use this file except in compliance with
6  * the License.  You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #ifndef APR_MMAP_H
18 #define APR_MMAP_H
19
20 /**
21  * @file apr_mmap.h
22  * @brief APR MMAP routines
23  */
24
25 #include "apr.h"
26 #include "apr_pools.h"
27 #include "apr_errno.h"
28 #include "apr_ring.h"
29 #include "apr_file_io.h"        /* for apr_file_t */
30
31 #ifdef BEOS
32 #include <kernel/OS.h>
33 #endif
34
35 #ifdef __cplusplus
36 extern "C" {
37 #endif /* __cplusplus */
38
39 /**
40  * @defgroup apr_mmap MMAP (Memory Map) Routines
41  * @ingroup APR 
42  * @{
43  */
44
45 /** MMap opened for reading */
46 #define APR_MMAP_READ    1
47 /** MMap opened for writing */
48 #define APR_MMAP_WRITE   2
49
50 /** @see apr_mmap_t */
51 typedef struct apr_mmap_t            apr_mmap_t;
52
53 /**
54  * @remark
55  * As far as I can tell the only really sane way to store an MMAP is as a
56  * void * and a length.  BeOS requires this area_id, but that's just a little
57  * something extra.  I am exposing this type, because it doesn't make much
58  * sense to keep it private, and opening it up makes some stuff easier in
59  * Apache.
60  */
61 /** The MMAP structure */
62 struct apr_mmap_t {
63     /** The pool the mmap structure was allocated out of. */
64     apr_pool_t *cntxt;
65 #ifdef BEOS
66     /** An area ID.  Only valid on BeOS */
67     area_id area;
68 #endif
69 #ifdef WIN32
70     /** The handle of the file mapping */
71     HANDLE mhandle;
72     /** The start of the real memory page area (mapped view) */
73     void *mv;
74     /** The physical start, size and offset */
75     apr_off_t  pstart;
76     apr_size_t psize;
77     apr_off_t  poffset;
78 #endif
79     /** The start of the memory mapped area */
80     void *mm;
81     /** The amount of data in the mmap */
82     apr_size_t size;
83     /** @deprecated this field is no longer used and will be removed
84      * in APR 1.0 */
85     int unused;
86     /** ring of apr_mmap_t's that reference the same
87      * mmap'ed region; acts in place of a reference count */
88     APR_RING_ENTRY(apr_mmap_t) link;
89 };
90
91 #if APR_HAS_MMAP || defined(DOXYGEN)
92
93 /** @def APR_MMAP_THRESHOLD 
94  * Files have to be at least this big before they're mmap()d.  This is to deal
95  * with systems where the expense of doing an mmap() and an munmap() outweighs
96  * the benefit for small files.  It shouldn't be set lower than 1.
97  */
98 #ifdef MMAP_THRESHOLD
99 #  define APR_MMAP_THRESHOLD              MMAP_THRESHOLD
100 #else
101 #  ifdef SUNOS4
102 #    define APR_MMAP_THRESHOLD            (8*1024)
103 #  else
104 #    define APR_MMAP_THRESHOLD            1
105 #  endif /* SUNOS4 */
106 #endif /* MMAP_THRESHOLD */
107
108 /** @def APR_MMAP_LIMIT
109  * Maximum size of MMap region
110  */
111 #ifdef MMAP_LIMIT
112 #  define APR_MMAP_LIMIT                  MMAP_LIMIT
113 #else
114 #  define APR_MMAP_LIMIT                  (4*1024*1024)
115 #endif /* MMAP_LIMIT */
116
117 /** Can this file be MMaped */
118 #define APR_MMAP_CANDIDATE(filelength) \
119     ((filelength >= APR_MMAP_THRESHOLD) && (filelength < APR_MMAP_LIMIT))
120
121 /*   Function definitions */
122
123 /** 
124  * Create a new mmap'ed file out of an existing APR file.
125  * @param newmmap The newly created mmap'ed file.
126  * @param file The file turn into an mmap.
127  * @param offset The offset into the file to start the data pointer at.
128  * @param size The size of the file
129  * @param flag bit-wise or of:
130  * <PRE>
131  *          APR_MMAP_READ       MMap opened for reading
132  *          APR_MMAP_WRITE      MMap opened for writing
133  * </PRE>
134  * @param cntxt The pool to use when creating the mmap.
135  */
136 APR_DECLARE(apr_status_t) apr_mmap_create(apr_mmap_t **newmmap, 
137                                           apr_file_t *file, apr_off_t offset,
138                                           apr_size_t size, apr_int32_t flag,
139                                           apr_pool_t *cntxt);
140
141 /**
142  * Duplicate the specified MMAP.
143  * @param new_mmap The structure to duplicate into. 
144  * @param old_mmap The mmap to duplicate.
145  * @param p The pool to use for new_mmap.
146  * @param transfer_ownership DEPRECATED: this param is now ignored
147  *  and should be removed prior to APR 1.0
148  */         
149 APR_DECLARE(apr_status_t) apr_mmap_dup(apr_mmap_t **new_mmap,
150                                        apr_mmap_t *old_mmap,
151                                        apr_pool_t *p,
152                                        int transfer_ownership);
153
154 #if defined(DOXYGEN)
155 /**
156  * Transfer the specified MMAP to a different pool
157  * @param new_mmap The structure to duplicate into.
158  * @param old_mmap The file to transfer.
159  * @param p The pool to use for new_mmap.
160  * @deprecated Just use apr_mmap_dup().  The transfer_ownership flag will
161  *  go away soon anyway.
162  */
163 APR_DECLARE(apr_status_t) apr_mmap_setaside(apr_mmap_t **new_mmap,
164                                             apr_mmap_t *old_mmap,
165                                             apr_pool_t *p);
166 #else
167 #define apr_mmap_setaside(new_mmap, old_mmap, p) apr_mmap_dup(new_mmap, old_mmap, p, 1)
168 #endif /* DOXYGEN */
169
170 /**
171  * Remove a mmap'ed.
172  * @param mm The mmap'ed file.
173  */
174 APR_DECLARE(apr_status_t) apr_mmap_delete(apr_mmap_t *mm);
175
176 /** 
177  * Move the pointer into the mmap'ed file to the specified offset.
178  * @param addr The pointer to the offset specified.
179  * @param mm The mmap'ed file.
180  * @param offset The offset to move to.
181  */
182 APR_DECLARE(apr_status_t) apr_mmap_offset(void **addr, apr_mmap_t *mm, 
183                                           apr_off_t offset);
184
185 #endif /* APR_HAS_MMAP */
186
187 /** @} */
188
189 #ifdef __cplusplus
190 }
191 #endif
192
193 #endif  /* ! APR_MMAP_H */