annotate src/lib/mempool.h @ 22664:fea53c2725c0

director: Fix director_max_parallel_moves/kicks type Should be uint, not time.
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Thu, 09 Nov 2017 12:24:16 +0200
parents 54260e47d2e1
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6410
e4eb71ae8e96 Changed .h ifdef/defines to use <NAME>_H format.
Timo Sirainen <tss@iki.fi>
parents: 5356
diff changeset
1 #ifndef MEMPOOL_H
e4eb71ae8e96 Changed .h ifdef/defines to use <NAME>_H format.
Timo Sirainen <tss@iki.fi>
parents: 5356
diff changeset
2 #define MEMPOOL_H
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
3
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
4 #include "macros.h"
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
5
4980
8e88ecc64563 debug: MEMPOOL_GROWING prefix in alloconly pool names means that when
Timo Sirainen <tss@iki.fi>
parents: 4781
diff changeset
6 /* When DEBUG is enabled, Dovecot warns whenever a memory pool is grown.
8e88ecc64563 debug: MEMPOOL_GROWING prefix in alloconly pool names means that when
Timo Sirainen <tss@iki.fi>
parents: 4781
diff changeset
7 This is done so that the initial pool size could be set large enough so that
8e88ecc64563 debug: MEMPOOL_GROWING prefix in alloconly pool names means that when
Timo Sirainen <tss@iki.fi>
parents: 4781
diff changeset
8 it wouldn't grow in normal use. For some memory pools it's too difficult
8e88ecc64563 debug: MEMPOOL_GROWING prefix in alloconly pool names means that when
Timo Sirainen <tss@iki.fi>
parents: 4781
diff changeset
9 to calculate a good initial size, so this prefix should be used with those
8e88ecc64563 debug: MEMPOOL_GROWING prefix in alloconly pool names means that when
Timo Sirainen <tss@iki.fi>
parents: 4781
diff changeset
10 pools to disable the warning. */
8e88ecc64563 debug: MEMPOOL_GROWING prefix in alloconly pool names means that when
Timo Sirainen <tss@iki.fi>
parents: 4781
diff changeset
11 #define MEMPOOL_GROWING "GROWING-"
8e88ecc64563 debug: MEMPOOL_GROWING prefix in alloconly pool names means that when
Timo Sirainen <tss@iki.fi>
parents: 4781
diff changeset
12
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
13 /* Memory allocated and reallocated (the new data in it) in pools is always
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
14 zeroed, it will cost only a few CPU cycles and may well save some debug
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
15 time. */
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
16
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 857
diff changeset
17 typedef struct pool *pool_t;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
18
5026
d7e064f77f79 Don't keep the memory pool virtual functions in the pool structure itself,
Timo Sirainen <tss@iki.fi>
parents: 4980
diff changeset
19 struct pool_vfuncs {
1489
826bed85c807 Added pool_get_name(), for debugging mostly.
Timo Sirainen <tss@iki.fi>
parents: 944
diff changeset
20 const char *(*get_name)(pool_t pool);
826bed85c807 Added pool_get_name(), for debugging mostly.
Timo Sirainen <tss@iki.fi>
parents: 944
diff changeset
21
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 857
diff changeset
22 void (*ref)(pool_t pool);
3878
bf0a03691989 pool_unref(): set the pool pointer to NULL, so if we're trying to unref it
Timo Sirainen <tss@iki.fi>
parents: 3234
diff changeset
23 void (*unref)(pool_t *pool);
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
24
17502
6abf982c268d lib: Use __attribute__((returns_nonnull)) for the common memory/string functions.
Timo Sirainen <tss@iki.fi>
parents: 17501
diff changeset
25 void *(*malloc)(pool_t pool, size_t size) ATTR_RETURNS_NONNULL;
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 857
diff changeset
26 void (*free)(pool_t pool, void *mem);
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
27
941
4d6b69558add Added old_size parameter to p_realloc() - we rarely need it and this way
Timo Sirainen <tss@iki.fi>
parents: 903
diff changeset
28 /* memory in old_size..new_size will be zeroed */
4d6b69558add Added old_size parameter to p_realloc() - we rarely need it and this way
Timo Sirainen <tss@iki.fi>
parents: 903
diff changeset
29 void *(*realloc)(pool_t pool, void *mem,
4720
b0daeec3d416 Use malloc attribute for the most commonly used memory and string allocation
Timo Sirainen <tss@iki.fi>
parents: 4633
diff changeset
30 size_t old_size, size_t new_size)
17502
6abf982c268d lib: Use __attribute__((returns_nonnull)) for the common memory/string functions.
Timo Sirainen <tss@iki.fi>
parents: 17501
diff changeset
31 ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
32
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
33 /* Frees all the memory in pool. NOTE: system_pool doesn't support
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
34 this and crashes if it's used */
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 857
diff changeset
35 void (*clear)(pool_t pool);
944
4f38538aa4a1 Added alloconly_pool field for checking if pool supports free()
Timo Sirainen <tss@iki.fi>
parents: 941
diff changeset
36
3233
6396b4c0a721 Added p_get_max_easy_alloc_size().
Timo Sirainen <tss@iki.fi>
parents: 1905
diff changeset
37 /* Returns the maximum amount of bytes that can be allocated with
6396b4c0a721 Added p_get_max_easy_alloc_size().
Timo Sirainen <tss@iki.fi>
parents: 1905
diff changeset
38 minimal trouble. If there's no such concept, always returns 0. */
6396b4c0a721 Added p_get_max_easy_alloc_size().
Timo Sirainen <tss@iki.fi>
parents: 1905
diff changeset
39 size_t (*get_max_easy_alloc_size)(pool_t pool);
5026
d7e064f77f79 Don't keep the memory pool virtual functions in the pool structure itself,
Timo Sirainen <tss@iki.fi>
parents: 4980
diff changeset
40 };
d7e064f77f79 Don't keep the memory pool virtual functions in the pool structure itself,
Timo Sirainen <tss@iki.fi>
parents: 4980
diff changeset
41
d7e064f77f79 Don't keep the memory pool virtual functions in the pool structure itself,
Timo Sirainen <tss@iki.fi>
parents: 4980
diff changeset
42 struct pool {
d7e064f77f79 Don't keep the memory pool virtual functions in the pool structure itself,
Timo Sirainen <tss@iki.fi>
parents: 4980
diff changeset
43 const struct pool_vfuncs *v;
3233
6396b4c0a721 Added p_get_max_easy_alloc_size().
Timo Sirainen <tss@iki.fi>
parents: 1905
diff changeset
44
944
4f38538aa4a1 Added alloconly_pool field for checking if pool supports free()
Timo Sirainen <tss@iki.fi>
parents: 941
diff changeset
45 unsigned int alloconly_pool:1;
1782
2f3d906d99d8 data_stack_pool split into two: unsafe_data_stack_pool which works like
Timo Sirainen <tss@iki.fi>
parents: 1489
diff changeset
46 unsigned int datastack_pool:1;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
47 };
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
48
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
49 /* system_pool uses calloc() + realloc() + free() */
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 857
diff changeset
50 extern pool_t system_pool;
5356
48fe4fe9ef64 Added system_clean_pool. default_pool is now set statically, so it can be
Timo Sirainen <tss@iki.fi>
parents: 5026
diff changeset
51 extern struct pool static_system_pool;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
52
1782
2f3d906d99d8 data_stack_pool split into two: unsafe_data_stack_pool which works like
Timo Sirainen <tss@iki.fi>
parents: 1489
diff changeset
53 /* memory allocated from data_stack is valid only until next t_pop() call.
2f3d906d99d8 data_stack_pool split into two: unsafe_data_stack_pool which works like
Timo Sirainen <tss@iki.fi>
parents: 1489
diff changeset
54 No checks are performed. */
2f3d906d99d8 data_stack_pool split into two: unsafe_data_stack_pool which works like
Timo Sirainen <tss@iki.fi>
parents: 1489
diff changeset
55 extern pool_t unsafe_data_stack_pool;
402
e90b95f6d962 s/t_try_grow/t_try_realloc/
Timo Sirainen <tss@iki.fi>
parents: 183
diff changeset
56
825
8afbafd5deac We don't have separate read-write pools, so renamed pool_create(.., FALSE)
Timo Sirainen <tss@iki.fi>
parents: 743
diff changeset
57 /* Create a new alloc-only pool. Note that `size' specifies the initial
8afbafd5deac We don't have separate read-write pools, so renamed pool_create(.., FALSE)
Timo Sirainen <tss@iki.fi>
parents: 743
diff changeset
58 malloc()ed block size, part of it is used internally. */
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 857
diff changeset
59 pool_t pool_alloconly_create(const char *name, size_t size);
21534
576ae10cd6cc lib: Add pool_alloconly_create_clean()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21320
diff changeset
60 /* Like alloconly pool, but clear the memory before freeing it. The idea is
576ae10cd6cc lib: Add pool_alloconly_create_clean()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21320
diff changeset
61 that you could allocate memory for storing sensitive information from this
576ae10cd6cc lib: Add pool_alloconly_create_clean()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21320
diff changeset
62 pool, and be sure that it gets cleared from the memory when it's no longer
576ae10cd6cc lib: Add pool_alloconly_create_clean()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21320
diff changeset
63 needed. */
576ae10cd6cc lib: Add pool_alloconly_create_clean()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21320
diff changeset
64 pool_t pool_alloconly_create_clean(const char *name, size_t size);
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
65
1782
2f3d906d99d8 data_stack_pool split into two: unsafe_data_stack_pool which works like
Timo Sirainen <tss@iki.fi>
parents: 1489
diff changeset
66 /* When allocating memory from returned pool, the data stack frame must be
2f3d906d99d8 data_stack_pool split into two: unsafe_data_stack_pool which works like
Timo Sirainen <tss@iki.fi>
parents: 1489
diff changeset
67 the same as it was when calling this function. pool_unref() also checks
2f3d906d99d8 data_stack_pool split into two: unsafe_data_stack_pool which works like
Timo Sirainen <tss@iki.fi>
parents: 1489
diff changeset
68 that the stack frame is the same. This should make it quite safe to use. */
2f3d906d99d8 data_stack_pool split into two: unsafe_data_stack_pool which works like
Timo Sirainen <tss@iki.fi>
parents: 1489
diff changeset
69 pool_t pool_datastack_create(void);
2f3d906d99d8 data_stack_pool split into two: unsafe_data_stack_pool which works like
Timo Sirainen <tss@iki.fi>
parents: 1489
diff changeset
70
3234
06f9da4ff7a5 Added pool_get_exp_grown_size(). Use it for buffers, istreams and ostreams
Timo Sirainen <tss@iki.fi>
parents: 3233
diff changeset
71 /* Similar to nearest_power(), but try not to exceed buffer's easy
06f9da4ff7a5 Added pool_get_exp_grown_size(). Use it for buffers, istreams and ostreams
Timo Sirainen <tss@iki.fi>
parents: 3233
diff changeset
72 allocation size. If you don't have any explicit minimum size, use
06f9da4ff7a5 Added pool_get_exp_grown_size(). Use it for buffers, istreams and ostreams
Timo Sirainen <tss@iki.fi>
parents: 3233
diff changeset
73 old_size + 1. */
06f9da4ff7a5 Added pool_get_exp_grown_size(). Use it for buffers, istreams and ostreams
Timo Sirainen <tss@iki.fi>
parents: 3233
diff changeset
74 size_t pool_get_exp_grown_size(pool_t pool, size_t old_size, size_t min_size);
06f9da4ff7a5 Added pool_get_exp_grown_size(). Use it for buffers, istreams and ostreams
Timo Sirainen <tss@iki.fi>
parents: 3233
diff changeset
75
22138
54260e47d2e1 lib: Add i_realloc_type() for i_realloc() that checks for overflows
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21534
diff changeset
76 /* We require sizeof(type) to be <= UINT_MAX. This allows compiler to optimize
54260e47d2e1 lib: Add i_realloc_type() for i_realloc() that checks for overflows
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21534
diff changeset
77 away the entire MALLOC_MULTIPLY() call on 64bit systems. */
1784
0e72d6ab85ad Make i_free(), p_free() and pool_unref() calls also set the given parameter
Timo Sirainen <tss@iki.fi>
parents: 1783
diff changeset
78 #define p_new(pool, type, count) \
21320
1bdfc555f6a3 lib: *_new(): Use the new MALLOC_MULTIPLY() macro to avoid overflows
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 17638
diff changeset
79 ((type *) p_malloc(pool, MALLOC_MULTIPLY((unsigned int)sizeof(type), (count))) + \
1bdfc555f6a3 lib: *_new(): Use the new MALLOC_MULTIPLY() macro to avoid overflows
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 17638
diff changeset
80 COMPILE_ERROR_IF_TRUE(sizeof(type) > UINT_MAX))
22138
54260e47d2e1 lib: Add i_realloc_type() for i_realloc() that checks for overflows
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21534
diff changeset
81
54260e47d2e1 lib: Add i_realloc_type() for i_realloc() that checks for overflows
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21534
diff changeset
82 #define p_realloc_type(pool, mem, type, old_count, new_count) \
54260e47d2e1 lib: Add i_realloc_type() for i_realloc() that checks for overflows
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21534
diff changeset
83 ((type *) p_realloc(pool, mem, \
54260e47d2e1 lib: Add i_realloc_type() for i_realloc() that checks for overflows
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21534
diff changeset
84 MALLOC_MULTIPLY((unsigned int)sizeof(type), (old_count)), \
54260e47d2e1 lib: Add i_realloc_type() for i_realloc() that checks for overflows
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21534
diff changeset
85 MALLOC_MULTIPLY((unsigned int)sizeof(type), (new_count))) + \
54260e47d2e1 lib: Add i_realloc_type() for i_realloc() that checks for overflows
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21534
diff changeset
86 COMPILE_ERROR_IF_TRUE(sizeof(type) > UINT_MAX))
54260e47d2e1 lib: Add i_realloc_type() for i_realloc() that checks for overflows
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21534
diff changeset
87
17502
6abf982c268d lib: Use __attribute__((returns_nonnull)) for the common memory/string functions.
Timo Sirainen <tss@iki.fi>
parents: 17501
diff changeset
88 static inline void * ATTR_MALLOC ATTR_RETURNS_NONNULL
17501
5de6a5f241db lib: Changed mempool.h to use inline functions instead of macros.
Timo Sirainen <tss@iki.fi>
parents: 12074
diff changeset
89 p_malloc(pool_t pool, size_t size)
5de6a5f241db lib: Changed mempool.h to use inline functions instead of macros.
Timo Sirainen <tss@iki.fi>
parents: 12074
diff changeset
90 {
5de6a5f241db lib: Changed mempool.h to use inline functions instead of macros.
Timo Sirainen <tss@iki.fi>
parents: 12074
diff changeset
91 return pool->v->malloc(pool, size);
5de6a5f241db lib: Changed mempool.h to use inline functions instead of macros.
Timo Sirainen <tss@iki.fi>
parents: 12074
diff changeset
92 }
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
93
17502
6abf982c268d lib: Use __attribute__((returns_nonnull)) for the common memory/string functions.
Timo Sirainen <tss@iki.fi>
parents: 17501
diff changeset
94 static inline void * ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL
17501
5de6a5f241db lib: Changed mempool.h to use inline functions instead of macros.
Timo Sirainen <tss@iki.fi>
parents: 12074
diff changeset
95 p_realloc(pool_t pool, void *mem, size_t old_size, size_t new_size)
5de6a5f241db lib: Changed mempool.h to use inline functions instead of macros.
Timo Sirainen <tss@iki.fi>
parents: 12074
diff changeset
96 {
5de6a5f241db lib: Changed mempool.h to use inline functions instead of macros.
Timo Sirainen <tss@iki.fi>
parents: 12074
diff changeset
97 return pool->v->realloc(pool, mem, old_size, new_size);
5de6a5f241db lib: Changed mempool.h to use inline functions instead of macros.
Timo Sirainen <tss@iki.fi>
parents: 12074
diff changeset
98 }
4633
9de853d23279 Added p_free_and_null() and did some cleanups.
Timo Sirainen <tss@iki.fi>
parents: 3878
diff changeset
99
9de853d23279 Added p_free_and_null() and did some cleanups.
Timo Sirainen <tss@iki.fi>
parents: 3878
diff changeset
100 /* Free the memory. Currently it also sets memory to NULL, but that shouldn't
9de853d23279 Added p_free_and_null() and did some cleanups.
Timo Sirainen <tss@iki.fi>
parents: 3878
diff changeset
101 be relied on as it's only an extra safety check. It might as well be later
9de853d23279 Added p_free_and_null() and did some cleanups.
Timo Sirainen <tss@iki.fi>
parents: 3878
diff changeset
102 changed to some invalid pointer causing a segfault, or removed completely
9de853d23279 Added p_free_and_null() and did some cleanups.
Timo Sirainen <tss@iki.fi>
parents: 3878
diff changeset
103 in some "optimization".. */
1784
0e72d6ab85ad Make i_free(), p_free() and pool_unref() calls also set the given parameter
Timo Sirainen <tss@iki.fi>
parents: 1783
diff changeset
104 #define p_free(pool, mem) \
0e72d6ab85ad Make i_free(), p_free() and pool_unref() calls also set the given parameter
Timo Sirainen <tss@iki.fi>
parents: 1783
diff changeset
105 STMT_START { \
17638
a5f479be46b9 lib: cosmetic - whitespace cleanup in allocator/memory-related code
Phil Carmody <phil@dovecot.fi>
parents: 17502
diff changeset
106 p_free_internal(pool, mem); \
a5f479be46b9 lib: cosmetic - whitespace cleanup in allocator/memory-related code
Phil Carmody <phil@dovecot.fi>
parents: 17502
diff changeset
107 (mem) = NULL; \
1784
0e72d6ab85ad Make i_free(), p_free() and pool_unref() calls also set the given parameter
Timo Sirainen <tss@iki.fi>
parents: 1783
diff changeset
108 } STMT_END
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
109
4633
9de853d23279 Added p_free_and_null() and did some cleanups.
Timo Sirainen <tss@iki.fi>
parents: 3878
diff changeset
110 /* A macro that's guaranteed to set mem = NULL. */
9de853d23279 Added p_free_and_null() and did some cleanups.
Timo Sirainen <tss@iki.fi>
parents: 3878
diff changeset
111 #define p_free_and_null(pool, mem) p_free(pool, mem)
9de853d23279 Added p_free_and_null() and did some cleanups.
Timo Sirainen <tss@iki.fi>
parents: 3878
diff changeset
112
17501
5de6a5f241db lib: Changed mempool.h to use inline functions instead of macros.
Timo Sirainen <tss@iki.fi>
parents: 12074
diff changeset
113 static inline void p_free_internal(pool_t pool, void *mem)
5de6a5f241db lib: Changed mempool.h to use inline functions instead of macros.
Timo Sirainen <tss@iki.fi>
parents: 12074
diff changeset
114 {
5de6a5f241db lib: Changed mempool.h to use inline functions instead of macros.
Timo Sirainen <tss@iki.fi>
parents: 12074
diff changeset
115 pool->v->free(pool, mem);
5de6a5f241db lib: Changed mempool.h to use inline functions instead of macros.
Timo Sirainen <tss@iki.fi>
parents: 12074
diff changeset
116 }
5de6a5f241db lib: Changed mempool.h to use inline functions instead of macros.
Timo Sirainen <tss@iki.fi>
parents: 12074
diff changeset
117
5de6a5f241db lib: Changed mempool.h to use inline functions instead of macros.
Timo Sirainen <tss@iki.fi>
parents: 12074
diff changeset
118 static inline void p_clear(pool_t pool)
5de6a5f241db lib: Changed mempool.h to use inline functions instead of macros.
Timo Sirainen <tss@iki.fi>
parents: 12074
diff changeset
119 {
5de6a5f241db lib: Changed mempool.h to use inline functions instead of macros.
Timo Sirainen <tss@iki.fi>
parents: 12074
diff changeset
120 pool->v->clear(pool);
5de6a5f241db lib: Changed mempool.h to use inline functions instead of macros.
Timo Sirainen <tss@iki.fi>
parents: 12074
diff changeset
121 }
5de6a5f241db lib: Changed mempool.h to use inline functions instead of macros.
Timo Sirainen <tss@iki.fi>
parents: 12074
diff changeset
122
5de6a5f241db lib: Changed mempool.h to use inline functions instead of macros.
Timo Sirainen <tss@iki.fi>
parents: 12074
diff changeset
123 static inline size_t p_get_max_easy_alloc_size(pool_t pool)
5de6a5f241db lib: Changed mempool.h to use inline functions instead of macros.
Timo Sirainen <tss@iki.fi>
parents: 12074
diff changeset
124 {
5de6a5f241db lib: Changed mempool.h to use inline functions instead of macros.
Timo Sirainen <tss@iki.fi>
parents: 12074
diff changeset
125 return pool->v->get_max_easy_alloc_size(pool);
5de6a5f241db lib: Changed mempool.h to use inline functions instead of macros.
Timo Sirainen <tss@iki.fi>
parents: 12074
diff changeset
126 }
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
127
17501
5de6a5f241db lib: Changed mempool.h to use inline functions instead of macros.
Timo Sirainen <tss@iki.fi>
parents: 12074
diff changeset
128 static inline const char *pool_get_name(pool_t pool)
5de6a5f241db lib: Changed mempool.h to use inline functions instead of macros.
Timo Sirainen <tss@iki.fi>
parents: 12074
diff changeset
129 {
5de6a5f241db lib: Changed mempool.h to use inline functions instead of macros.
Timo Sirainen <tss@iki.fi>
parents: 12074
diff changeset
130 return pool->v->get_name(pool);
5de6a5f241db lib: Changed mempool.h to use inline functions instead of macros.
Timo Sirainen <tss@iki.fi>
parents: 12074
diff changeset
131 }
5de6a5f241db lib: Changed mempool.h to use inline functions instead of macros.
Timo Sirainen <tss@iki.fi>
parents: 12074
diff changeset
132
5de6a5f241db lib: Changed mempool.h to use inline functions instead of macros.
Timo Sirainen <tss@iki.fi>
parents: 12074
diff changeset
133 static inline void pool_ref(pool_t pool)
5de6a5f241db lib: Changed mempool.h to use inline functions instead of macros.
Timo Sirainen <tss@iki.fi>
parents: 12074
diff changeset
134 {
5de6a5f241db lib: Changed mempool.h to use inline functions instead of macros.
Timo Sirainen <tss@iki.fi>
parents: 12074
diff changeset
135 pool->v->ref(pool);
5de6a5f241db lib: Changed mempool.h to use inline functions instead of macros.
Timo Sirainen <tss@iki.fi>
parents: 12074
diff changeset
136 }
5de6a5f241db lib: Changed mempool.h to use inline functions instead of macros.
Timo Sirainen <tss@iki.fi>
parents: 12074
diff changeset
137
5de6a5f241db lib: Changed mempool.h to use inline functions instead of macros.
Timo Sirainen <tss@iki.fi>
parents: 12074
diff changeset
138 static inline void pool_unref(pool_t *pool)
5de6a5f241db lib: Changed mempool.h to use inline functions instead of macros.
Timo Sirainen <tss@iki.fi>
parents: 12074
diff changeset
139 {
5de6a5f241db lib: Changed mempool.h to use inline functions instead of macros.
Timo Sirainen <tss@iki.fi>
parents: 12074
diff changeset
140 (*pool)->v->unref(pool);
5de6a5f241db lib: Changed mempool.h to use inline functions instead of macros.
Timo Sirainen <tss@iki.fi>
parents: 12074
diff changeset
141 }
3233
6396b4c0a721 Added p_get_max_easy_alloc_size().
Timo Sirainen <tss@iki.fi>
parents: 1905
diff changeset
142
10787
d7108785c40a liblib: Added pool_alloconly_get_total_used/alloc_size() functions.
Timo Sirainen <tss@iki.fi>
parents: 6428
diff changeset
143 /* These functions are only for pools created with pool_alloconly_create(): */
d7108785c40a liblib: Added pool_alloconly_get_total_used/alloc_size() functions.
Timo Sirainen <tss@iki.fi>
parents: 6428
diff changeset
144
d7108785c40a liblib: Added pool_alloconly_get_total_used/alloc_size() functions.
Timo Sirainen <tss@iki.fi>
parents: 6428
diff changeset
145 /* Returns how much memory has been allocated from this pool. */
d7108785c40a liblib: Added pool_alloconly_get_total_used/alloc_size() functions.
Timo Sirainen <tss@iki.fi>
parents: 6428
diff changeset
146 size_t pool_alloconly_get_total_used_size(pool_t pool);
d7108785c40a liblib: Added pool_alloconly_get_total_used/alloc_size() functions.
Timo Sirainen <tss@iki.fi>
parents: 6428
diff changeset
147 /* Returns how much system memory has been allocated for this pool. */
d7108785c40a liblib: Added pool_alloconly_get_total_used/alloc_size() functions.
Timo Sirainen <tss@iki.fi>
parents: 6428
diff changeset
148 size_t pool_alloconly_get_total_alloc_size(pool_t pool);
d7108785c40a liblib: Added pool_alloconly_get_total_used/alloc_size() functions.
Timo Sirainen <tss@iki.fi>
parents: 6428
diff changeset
149
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
150 #endif