KHtml

arena.h
1 /*
2  * Copyright (C) 1998-2000 Netscape Communications Corporation.
3  *
4  * Other contributors:
5  * Nick Blievers <[email protected]>
6  * Jeff Hostetler <[email protected]>
7  * Tom Rini <[email protected]>
8  * Raffaele Sena <[email protected]>
9  *
10  * This library is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public
12  * License as published by the Free Software Foundation; either
13  * version 2.1 of the License, or (at your option) any later version.
14  *
15  * This library is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  * Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public
21  * License along with this library; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23  *
24  * Alternatively, the contents of this file may be used under the terms
25  * of either the Mozilla Public License Version 1.1, found at
26  * http://www.mozilla.org/MPL/ (the "MPL") or the GNU General Public
27  * License Version 2.0, found at http://www.fsf.org/copyleft/gpl.html
28  * (the "GPL"), in which case the provisions of the MPL or the GPL are
29  * applicable instead of those above. If you wish to allow use of your
30  * version of this file only under the terms of one of those two
31  * licenses (the MPL or the GPL) and not to allow others to use your
32  * version of this file under the LGPL, indicate your decision by
33  * deletingthe provisions above and replace them with the notice and
34  * other provisions required by the MPL or the GPL, as the case may be.
35  * If you do not delete the provisions above, a recipient may use your
36  * version of this file under any of the LGPL, the MPL or the GPL.
37  */
38 
39 #ifndef ARENA_H
40 #define ARENA_H
41 
42 #include <config-khtml.h>
43 #include <QtGlobal>
44 
45 // VG annotations for arenas disabled since still buggy
46 #if 0 && HAVE_VALGRIND_MEMCHECK_H && !defined(NDEBUG)
47 
48 #include <valgrind/memcheck.h>
49 #define VALGRIND_SUPPORT
50 
51 #else
52 
53 #define VALGRIND_CREATE_MEMPOOL(base, redZone, zeroed)
54 #define VALGRIND_DESTROY_MEMPOOL(base)
55 #define VALGRIND_MEMPOOL_ALLOC(base, addr, size)
56 #define VALGRIND_MEMPOOL_FREE(base, addr)
57 
58 #endif
59 
60 #define ARENA_ALIGN_MASK 3
61 
62 typedef quintptr uword;
63 
64 namespace khtml
65 {
66 
67 struct Arena {
68  Arena *next; // next arena
69  uword base; // aligned base address
70  uword limit; // end of arena (1+last byte)
71  uword avail; // points to next available byte in arena
72 };
73 
74 struct ArenaPool {
75  Arena first; // first arena in pool list.
76  Arena *current; // current arena.
77  unsigned int arenasize;
78  unsigned int largealloc; // threshold for fractional allocation strategy
79  unsigned int cumul; // total bytes in pool.
80  uword mask; // Mask (power-of-2 - 1)
81 };
82 
83 void InitArenaPool(ArenaPool *pool, const char *name,
84  unsigned int size, unsigned int align);
85 void FinishArenaPool(ArenaPool *pool);
86 void FreeArenaPool(ArenaPool *pool);
87 void *ArenaAllocate(ArenaPool *pool, unsigned int nb);
88 void ArenaFinish(void);
89 
90 #define ARENA_ALIGN(pool, n) (((uword)(n) + ARENA_ALIGN_MASK) & ~ARENA_ALIGN_MASK)
91 #define INIT_ARENA_POOL(pool, name, size) \
92  InitArenaPool(pool, name, size, ARENA_ALIGN_MASK + 1)
93 
94 #define ARENA_ALLOCATE(p, pool, nb) \
95  Arena *_a = (pool)->current; \
96  unsigned int _nb = ARENA_ALIGN(pool, nb); \
97  uword _p = _a->avail; \
98  uword _q = _p + _nb; \
99  if (_q > _a->limit) \
100  _p = (uword)ArenaAllocate(pool, _nb); \
101  else { \
102  VALGRIND_MEMPOOL_ALLOC(_a->base, _p, _nb); \
103  _a->avail = _q; \
104  } \
105  p = (void *)_p;
106 
107 #define ARENA_MARK(pool) ((void *) (pool)->current->avail)
108 #define UPTRDIFF(p,q) ((uword)(p) - (uword)(q))
109 
110 #ifdef DEBUG
111 #define FREE_PATTERN 0xDA
112 #define CLEAR_UNUSED(a) (assert((a)->avail <= (a)->limit), \
113  memset((void*)(a)->avail, FREE_PATTERN, \
114  (a)->limit - (a)->avail))
115 #define CLEAR_ARENA(a) memset((void*)(a), FREE_PATTERN, \
116  (a)->limit - (uword)(a))
117 #else
118 #define CLEAR_UNUSED(a)
119 #define CLEAR_ARENA(a)
120 #endif
121 
122 } // namespace
123 
124 #endif
This file is part of the HTML rendering engine for KDE.
MESSAGECORE_EXPORT KMime::Content * next(KMime::Content *node, bool allowChildren=true)
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Mon Oct 25 2021 22:48:11 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.