bottleneck testcase based on rubbos
[bottlenecks.git] / rubbos / app / tomcat-connectors-1.2.32-src / native / common / jk_pool.h
1 /*
2  *  Licensed to the Apache Software Foundation (ASF) under one or more
3  *  contributor license agreements.  See the NOTICE file distributed with
4  *  this work for additional information regarding copyright ownership.
5  *  The ASF licenses this file to You under the Apache License, Version 2.0
6  *  (the "License"); you may not use this file except in compliance with
7  *  the License.  You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  */
17
18 /***************************************************************************
19  * Description: Memory Pool object header file                             *
20  * Author:      Gal Shachor <shachor@il.ibm.com>                           *
21  * Version:     $Revision: 466585 $                                           *
22  ***************************************************************************/
23 #ifndef _JK_POOL_H
24 #define _JK_POOL_H
25
26 #include "jk_global.h"
27
28 #ifdef __cplusplus
29 extern "C"
30 {
31 #endif                          /* __cplusplus */
32
33 /**
34  * @file jk_pool.h
35  * @brief Jk memory allocation
36  *
37  * Similar with apr_pools, but completely unsynchronized.
38  * XXX use same names
39  * 
40  */
41
42 /*
43  * The pool atom (basic pool alocation unit) is an 8 byte long. 
44  * Each allocation (even for 1 byte) will return a round up to the 
45  * number of atoms. 
46  * 
47  * This is to help in alignment of 32/64 bit machines ...
48  * G.S
49  */
50 #ifdef WIN32
51     typedef __int64 jk_pool_atom_t;
52 #elif defined(AIX)
53     typedef long long jk_pool_atom_t;
54 #elif defined(SOLARIS)
55     typedef long long jk_pool_atom_t;
56 #elif defined(LINUX)
57     typedef long long jk_pool_atom_t;
58 #elif defined(FREEBSD)
59     typedef long long jk_pool_atom_t;
60 #elif defined(OS2)
61     typedef long long jk_pool_atom_t;
62 #elif defined(NETWARE)
63     typedef long long jk_pool_atom_t;
64 #elif defined(HPUX11)
65     typedef long long jk_pool_atom_t;
66 #elif defined(IRIX)
67     typedef long long jk_pool_atom_t;
68 #elif defined(AS400)
69     typedef void *jk_pool_atom_t;
70 #else
71     typedef long long jk_pool_atom_t;
72 #endif
73
74 /**
75  * Alignment macros
76  */
77
78 /* JK_ALIGN() is only to be used to align on a power of 2 boundary */
79 #define JK_ALIGN(size, boundary) \
80     (((size) + ((boundary) - 1)) & ~((boundary) - 1))
81
82 /** Default alignment */
83 #ifdef AS400
84 #define JK_ALIGN_DEFAULT(size) JK_ALIGN(size, 16)
85 #else
86 #define JK_ALIGN_DEFAULT(size) JK_ALIGN(size, 8)
87 #endif
88
89 /* 
90  * Pool size in number of pool atoms.
91  */
92 #define TINY_POOL_SIZE 256      /* Tiny 1/4K atom pool. */
93 #define SMALL_POOL_SIZE 512     /* Small 1/2K atom pool. */
94 #define BIG_POOL_SIZE   2*SMALL_POOL_SIZE       /* Bigger 1K atom pool. */
95 #define HUGE_POOL_SIZE  2*BIG_POOL_SIZE /* Huge 2K atom pool. */
96
97 /** jk pool structure */
98 struct jk_pool
99 {
100     size_t size;
101     size_t pos;
102     char *buf;
103     size_t dyn_size;
104     size_t dyn_pos;
105     void **dynamic;
106 };
107
108 typedef struct jk_pool jk_pool_t;
109
110 void jk_open_pool(jk_pool_t *p, jk_pool_atom_t *buf, size_t size);
111
112 void jk_close_pool(jk_pool_t *p);
113
114 void jk_reset_pool(jk_pool_t *p);
115
116 void *jk_pool_alloc(jk_pool_t *p, size_t sz);
117
118 void *jk_pool_realloc(jk_pool_t *p,
119                       size_t sz, const void *old, size_t old_sz);
120
121 void *jk_pool_strdup(jk_pool_t *p, const char *s);
122
123 #ifdef __cplusplus
124 }
125 #endif                          /* __cplusplus */
126 #endif                          /* _JK_POOL_H */