~ubuntu-branches/ubuntu/oneiric/libapache-mod-jk/oneiric

« back to all changes in this revision

Viewing changes to jk/native/common/jk_pool.h

  • Committer: Bazaar Package Importer
  • Author(s): Steve Kowalik
  • Date: 2006-08-05 16:30:53 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060805163053-myf66gm6j1a21ps6
Tags: 1:1.2.18-1ubuntu1
Merge from Debian unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 *  Copyright 1999-2004 The Apache Software Foundation
3
 
 *
4
 
 *  Licensed under the Apache License, Version 2.0 (the "License");
5
 
 *  you may not use this file except in compliance with the License.
6
 
 *  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
 
/***************************************************************************
18
 
 * Description: Memory Pool object header file                             *
19
 
 * Author:      Gal Shachor <shachor@il.ibm.com>                           *
20
 
 * Version:     $Revision: 1.10 $                                           *
21
 
 ***************************************************************************/
22
 
#ifndef _JK_POOL_H
23
 
#define _JK_POOL_H
24
 
 
25
 
#include "jk_global.h"
26
 
 
27
 
#ifdef __cplusplus
28
 
extern "C"
29
 
{
30
 
#endif                          /* __cplusplus */
31
 
 
32
 
/**
33
 
 * @file jk_pool.h
34
 
 * @brief Jk memory allocation
35
 
 *
36
 
 * Similar with apr_pools, but completely unsynchronized.
37
 
 * XXX use same names
38
 
 * 
39
 
 */
40
 
 
41
 
/*
42
 
 * The pool atom (basic pool alocation unit) is an 8 byte long. 
43
 
 * Each allocation (even for 1 byte) will return a round up to the 
44
 
 * number of atoms. 
45
 
 * 
46
 
 * This is to help in alignment of 32/64 bit machines ...
47
 
 * G.S
48
 
 */
49
 
#ifdef WIN32
50
 
    typedef __int64 jk_pool_atom_t;
51
 
#elif defined(AIX)
52
 
    typedef long long jk_pool_atom_t;
53
 
#elif defined(SOLARIS)
54
 
    typedef long long jk_pool_atom_t;
55
 
#elif defined(LINUX)
56
 
    typedef long long jk_pool_atom_t;
57
 
#elif defined(FREEBSD)
58
 
    typedef long long jk_pool_atom_t;
59
 
#elif defined(OS2)
60
 
    typedef long long jk_pool_atom_t;
61
 
#elif defined(NETWARE)
62
 
    typedef long long jk_pool_atom_t;
63
 
#elif defined(HPUX11)
64
 
    typedef long long jk_pool_atom_t;
65
 
#elif defined(IRIX)
66
 
    typedef long long jk_pool_atom_t;
67
 
#elif defined(AS400)
68
 
    typedef void *jk_pool_atom_t;
69
 
#else
70
 
    typedef long long jk_pool_atom_t;
71
 
#endif
72
 
 
73
 
/**
74
 
 * Alignment macros
75
 
 */
76
 
 
77
 
/* JK_ALIGN() is only to be used to align on a power of 2 boundary */
78
 
#define JK_ALIGN(size, boundary) \
79
 
    (((size) + ((boundary) - 1)) & ~((boundary) - 1))
80
 
 
81
 
/** Default alignment */
82
 
#ifdef AS400
83
 
#define JK_ALIGN_DEFAULT(size) JK_ALIGN(size, 16)
84
 
#else
85
 
#define JK_ALIGN_DEFAULT(size) JK_ALIGN(size, 8)
86
 
#endif
87
 
 
88
 
/* 
89
 
 * Pool size in number of pool atoms.
90
 
 */
91
 
#define TINY_POOL_SIZE 256      /* Tiny 1/4K atom pool. */
92
 
#define SMALL_POOL_SIZE 512     /* Small 1/2K atom pool. */
93
 
#define BIG_POOL_SIZE   2*SMALL_POOL_SIZE       /* Bigger 1K atom pool. */
94
 
#define HUGE_POOL_SIZE  2*BIG_POOL_SIZE /* Huge 2K atom pool. */
95
 
 
96
 
/** jk pool structure */
97
 
struct jk_pool
98
 
{
99
 
    size_t size;
100
 
    size_t pos;
101
 
    char *buf;
102
 
    size_t dyn_size;
103
 
    size_t dyn_pos;
104
 
    void **dynamic;
105
 
};
106
 
 
107
 
typedef struct jk_pool jk_pool_t;
108
 
 
109
 
void jk_open_pool(jk_pool_t *p, jk_pool_atom_t *buf, size_t size);
110
 
 
111
 
void jk_close_pool(jk_pool_t *p);
112
 
 
113
 
void jk_reset_pool(jk_pool_t *p);
114
 
 
115
 
void *jk_pool_alloc(jk_pool_t *p, size_t sz);
116
 
 
117
 
void *jk_pool_realloc(jk_pool_t *p,
118
 
                      size_t sz, const void *old, size_t old_sz);
119
 
 
120
 
void *jk_pool_strdup(jk_pool_t *p, const char *s);
121
 
 
122
 
#ifdef __cplusplus
123
 
}
124
 
#endif                          /* __cplusplus */
125
 
#endif                          /* _JK_POOL_H */