Expose rdrand and f16c through cpuid also if the host only has avx.
[valgrind.git] / include / pub_tool_poolalloc.h
blobb4dd3a67c45f5ad1964bfd96eaa39cfece1498ac
2 /*--------------------------------------------------------------------*/
3 /*--- A simple pool (memory) allocator. pub_tool_poolalloc.h ---*/
4 /*--------------------------------------------------------------------*/
6 /*
7 This file is part of Valgrind, a dynamic binary instrumentation
8 framework.
10 Copyright (C) 2011-2017 OpenWorks LLP info@open-works.co.uk,
11 Philippe Waroquiers philippe.waroquiers@skynet.be
13 This program is free software; you can redistribute it and/or
14 modify it under the terms of the GNU General Public License as
15 published by the Free Software Foundation; either version 2 of the
16 License, or (at your option) any later version.
18 This program is distributed in the hope that it will be useful, but
19 WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, see <http://www.gnu.org/licenses/>.
26 The GNU General Public License is contained in the file COPYING.
29 #ifndef __PUB_TOOL_POOLALLOC_H
30 #define __PUB_TOOL_POOLALLOC_H
32 #include "pub_tool_basics.h" // UWord
34 //--------------------------------------------------------------------
35 // PURPOSE: Provides efficient allocation and free of elements of
36 // the same size.
37 // This pool allocator manages elements alloc/free by allocating
38 // "pools" of many elements from a lower level allocator (typically
39 // pub_tool_mallocfree.h).
40 // Single elements can then be allocated and released from these pools.
41 // A pool allocator is faster and has less memory overhead than
42 // calling directly pub_tool_mallocfree.h
43 // Note: the pools of elements are not freed, even if all the
44 // single elements have been freed. The only way to free the underlying
45 // pools of elements is to delete the pool allocator.
46 //--------------------------------------------------------------------
49 typedef struct _PoolAlloc PoolAlloc;
51 /* Create new PoolAlloc, using given allocation and free function, and
52 for elements of the specified size. alloc_fn must not return NULL (that
53 is, if it returns it must have succeeded.)
54 This function never returns NULL. */
55 extern PoolAlloc* VG_(newPA) ( UWord elemSzB,
56 UWord nPerPool,
57 Alloc_Fn_t alloc_fn,
58 const HChar* cc,
59 Free_Fn_t free_fn );
62 /* Free all memory associated with a PoolAlloc. */
63 extern void VG_(deletePA) ( PoolAlloc* pa);
65 /* Allocates an element from pa. The function never returns NULL. */
66 extern void* VG_(allocEltPA) ( PoolAlloc* pa);
68 /* Free element of pa. */
69 extern void VG_(freeEltPA) ( PoolAlloc* pa, void* p);
71 /* A pool allocator can be shared between multiple data structures.
72 For example, multiple OSet* can allocate/free nodes from the same
73 pool allocator.
74 The Pool Allocator provides support to use a ref counter
75 to detect a pool allocator is not needed anymore.
76 It is the caller responsibility to call VG_(addRefPA) for
77 each new reference to a pool and VG_(releasePA) when such a reference
78 disappears.
79 VG_(releasePA) will automatically call VG_(deletePA)
80 to delete the PA when the ref counter drops to 0. */
82 // VG_(addRefPA) indicates there is a new reference to pa.
83 extern void VG_(addRefPA) ( PoolAlloc* pa);
85 // VG_(releasePA) decrements the pa reference count and deletes the pa if that
86 // reference count has dropped to zero. Returns the new value of the reference
87 // count.
88 extern UWord VG_(releasePA) ( PoolAlloc* pa);
90 // How many elements are managed by the pool 'pa'. This includes
91 // the elements allocated by VG_(allocEltPA), the elements freed by
92 // VG_(freeEltPA) and the elements that are in a block and have not
93 // yet been allocated.
94 extern UWord VG_(sizePA) ( PoolAlloc* pa);
95 #endif // __PUB_TOOL_POOLALLOC_
97 /*--------------------------------------------------------------------*/
98 /*--- end pub_tool_poolalloc.h ---*/
99 /*--------------------------------------------------------------------*/