Mercurial > hg
annotate mcabber/libjabber/pool.c @ 1064:516b5f7d1023
Fix some UTF-8 related problems
When the jid is invalid, it is displayed in the error messages.
However, in non-UTF-8 locales the LPRINT_NOTUTF8 must be provided
because we call scr_LogPrint() before the UTF-8 conversion.
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Fri, 01 Dec 2006 23:50:52 +0100 |
parents | c3ae9251c197 |
children | 3df441efb7c2 |
rev | line source |
---|---|
25 | 1 /* |
417
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
2 * pool.c |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
3 * This code comes from jabberd - Jabber Open Source Server |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
4 * Copyright (c) 2002 Jeremie Miller, Thomas Muldowney, |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
5 * Ryan Eatmon, Robert Norris |
25 | 6 * Copyright (C) 1998-1999 The Jabber Team http://jabber.org/ |
414
ec86d759ed54
Trailing whitespace cleanup
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
7 * |
417
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
8 * This program is free software; you can redistribute it and/or modify |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
9 * it under the terms of the GNU General Public License as published by |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
10 * the Free Software Foundation; either version 2 of the License, or |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
11 * (at your option) any later version. |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
12 * |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
13 * This program is distributed in the hope that it will be useful, |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
16 * GNU General Public License for more details. |
414
ec86d759ed54
Trailing whitespace cleanup
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
17 * |
417
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
18 * You should have received a copy of the GNU General Public License |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
19 * along with this program; if not, write to the Free Software |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307USA |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
21 * |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
22 * Copyrights |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
23 * |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
24 * Portions created by or assigned to Jabber.com, Inc. are |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
25 * Copyright (c) 1999-2002 Jabber.com, Inc. All Rights Reserved. Contact |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
26 * information for Jabber.com, Inc. is available at http://www.jabber.com/. |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
27 * |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
28 * Portions Copyright (c) 1998-1999 Jeremie Miller. |
414
ec86d759ed54
Trailing whitespace cleanup
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
29 * |
417
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
30 * Acknowledgements |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
31 * |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
32 * Special thanks to the Jabber Open Source Contributors for their |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
33 * suggestions and support of Jabber. |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
34 * |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
35 */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
36 |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
37 /** |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
38 * @file pool.c |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
39 * @brief Handling of memory pools |
414
ec86d759ed54
Trailing whitespace cleanup
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
40 * |
417
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
41 * Jabberd handles its memory allocations in pools. You create a pool, can |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
42 * allocate memory from it and all allocations will be freed if you free |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
43 * the pool. Therefore you don't have to care that each malloc is freed, |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
44 * you only have to take care that the pool is freed. |
414
ec86d759ed54
Trailing whitespace cleanup
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
45 * |
417
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
46 * The normal call-flow for pools is: |
414
ec86d759ed54
Trailing whitespace cleanup
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
47 * |
417
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
48 * pool p = pool_new(); |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
49 * struct mystruct *allocation1 = pmalloc(sizeof(struct mystruct)); |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
50 * struct myotherstruct *allocation2 = pmalloc(sizeof(struct myotherstruct)); |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
51 * ... |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
52 * pool_free(p); |
25 | 53 */ |
54 | |
55 #include "libxode.h" | |
56 | |
417
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
57 #define MAX_MALLOC_TRIES 10 /**< how many seconds we try to allocate memory */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
58 |
25 | 59 #ifdef POOL_DEBUG |
417
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
60 int pool__total = 0; /**< how many memory blocks are allocated */ |
25 | 61 int pool__ltotal = 0; |
417
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
62 xht pool__disturbed = NULL; |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
63 |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
64 /** |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
65 * create a new memory allocation and increment the pool__total counter |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
66 * |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
67 * only used if POOL_DEBUG is defined, else it is an alias for malloc |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
68 * |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
69 * @param size size of the memory to allocate |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
70 * @return pointer to the allocated memory |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
71 */ |
25 | 72 void *_pool__malloc(size_t size) |
73 { | |
74 pool__total++; | |
75 return malloc(size); | |
76 } | |
417
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
77 |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
78 /** |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
79 * free memory and decrement the pool__total counter |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
80 * |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
81 * only used if POOL_DEBUG is defined, else it is an alias for free |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
82 * |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
83 * @param block pointer to the memory allocation that should be freed |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
84 */ |
25 | 85 void _pool__free(void *block) |
86 { | |
87 pool__total--; | |
88 free(block); | |
89 } | |
90 #else | |
417
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
91 #define _pool__malloc malloc /**< _pool__malloc updates pool__total counter if POOL_DEBUG is defined */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
92 #define _pool__free free /**< _pool__free updates pool__total counter if POOL_DEBUG is defined */ |
25 | 93 #endif |
94 | |
417
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
95 /** |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
96 * try to allocate memory |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
97 * |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
98 * If allocation fails, it will be retries for MAX_MALLOC_TRIES seconds. |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
99 * If it still fails, we exit the process |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
100 * |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
101 * @param size how many bytes of memory we allocate |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
102 * @return pointer to the allocated memory |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
103 */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
104 inline void *_retried__malloc(size_t size) { |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
105 void *allocated_memory; |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
106 int malloc_tries = 0; |
25 | 107 |
417
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
108 while ((allocated_memory=_pool__malloc(size)) == NULL) { |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
109 if (malloc_tries++ > MAX_MALLOC_TRIES) { |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
110 exit(999); |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
111 } |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
112 |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
113 sleep(1); //pth_sleep(1); |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
114 } |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
115 |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
116 return allocated_memory; |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
117 } |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
118 |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
119 /** |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
120 * make an empty pool |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
121 * |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
122 * Use the macro pool_new() instead of a direct call to this function. The |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
123 * macro will create the parameters for you. |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
124 * |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
125 * @param zone the file in which the pool_new macro is called |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
126 * @param line the line in the file in which the pool_new macro is called |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
127 * @return the new allocated memory pool |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
128 */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
129 pool _pool_new(char *zone, int line) |
25 | 130 { |
417
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
131 // int malloc_tries = 0; |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
132 #ifdef POOL_DEBUG |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
133 int old__pool__total; |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
134 #endif |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
135 |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
136 pool p = _retried__malloc(sizeof(_pool)); |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
137 |
25 | 138 p->cleanup = NULL; |
139 p->heap = NULL; | |
140 p->size = 0; | |
141 | |
142 #ifdef POOL_DEBUG | |
143 p->lsize = -1; | |
144 p->zone[0] = '\0'; | |
145 strcat(p->zone,zone); | |
417
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
146 snprintf(p->zone, sizeof(p->zone), "%s:%i", zone, line); |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
147 snprintf(p->name, sizeof(p->name), "%X", p); |
25 | 148 |
149 if(pool__disturbed == NULL) | |
417
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
150 { |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
151 pool__disturbed = (xht)1; /* reentrancy flag! */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
152 pool__disturbed = ghash_create(POOL_DEBUG,(KEYHASHFUNC)str_hash_code,(KEYCOMPAREFUNC)j_strcmp); |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
153 } |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
154 if(pool__disturbed != (xht)1) |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
155 ghash_put(pool__disturbed,p->name,p); |
25 | 156 #endif |
157 | |
158 return p; | |
159 } | |
160 | |
417
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
161 /** |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
162 * free a memory heap (struct pheap) |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
163 * |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
164 * @param arg which heep should be freed |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
165 */ |
25 | 166 void _pool_heap_free(void *arg) |
167 { | |
168 struct pheap *h = (struct pheap *)arg; | |
169 | |
170 _pool__free(h->block); | |
171 _pool__free(h); | |
172 } | |
173 | |
417
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
174 /** |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
175 * append a pool_cleaner function (callback) to a pool |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
176 * |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
177 * mem should always be freed last |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
178 * |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
179 * All appended pool_cleaner functions will be called if a pool is freed. |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
180 * This might be used to clean logically subpools. |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
181 * |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
182 * @param p to which pool the pool_cleaner should be added |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
183 * @param pf structure containing the reference to the pool_cleaner and links for the list |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
184 */ |
25 | 185 void _pool_cleanup_append(pool p, struct pfree *pf) |
186 { | |
187 struct pfree *cur; | |
188 | |
189 if(p->cleanup == NULL) | |
190 { | |
417
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
191 p->cleanup = pf; |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
192 return; |
25 | 193 } |
194 | |
195 /* fast forward to end of list */ | |
196 for(cur = p->cleanup; cur->next != NULL; cur = cur->next); | |
197 | |
198 cur->next = pf; | |
199 } | |
200 | |
417
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
201 /** |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
202 * create a cleanup tracker |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
203 * |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
204 * this function is used to create a pfree structure that can be passed to _pool_cleanup_append() |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
205 * |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
206 * @param p the pool to which the pool_cleaner should be added |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
207 * @param f the function that should be called if the pool is freed |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
208 * @param arg the parameter that should be passed to the pool_cleaner function |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
209 * @return pointer to the new pfree structure |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
210 */ |
25 | 211 struct pfree *_pool_free(pool p, pool_cleaner f, void *arg) |
212 { | |
213 struct pfree *ret; | |
214 | |
215 /* make the storage for the tracker */ | |
417
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
216 ret = _retried__malloc(sizeof(struct pfree)); |
25 | 217 ret->f = f; |
218 ret->arg = arg; | |
219 ret->next = NULL; | |
220 | |
221 return ret; | |
222 } | |
223 | |
417
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
224 /** |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
225 * create a heap and make sure it get's cleaned up |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
226 * |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
227 * pheaps are used by memory pools internally to handle the memory allocations |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
228 * |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
229 * @note the macro pool_heap calls _pool_new_heap and NOT _pool_heap |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
230 * |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
231 * @param p for which pool the heap should be created |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
232 * @param size how big the pool should be |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
233 * @return pointer to the new pheap |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
234 */ |
25 | 235 struct pheap *_pool_heap(pool p, int size) |
236 { | |
237 struct pheap *ret; | |
238 struct pfree *clean; | |
239 | |
240 /* make the return heap */ | |
417
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
241 ret = _retried__malloc(sizeof(struct pheap)); |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
242 ret->block = _retried__malloc(size); |
25 | 243 ret->size = size; |
244 p->size += size; | |
245 ret->used = 0; | |
246 | |
247 /* append to the cleanup list */ | |
248 clean = _pool_free(p, _pool_heap_free, (void *)ret); | |
249 clean->heap = ret; /* for future use in finding used mem for pstrdup */ | |
250 _pool_cleanup_append(p, clean); | |
251 | |
252 return ret; | |
253 } | |
254 | |
417
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
255 /** |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
256 * create a new memory pool and set the initial heap size |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
257 * |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
258 * @note you should not call this function but use the macro pool_heap instead which fills zone and line automatically |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
259 * |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
260 * @param size the initial size of the memory pool |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
261 * @param zone the file where this function is called (for debugging) |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
262 * @param line the line in the file where this function is called |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
263 * @return the new memory pool |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
264 */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
265 pool _pool_new_heap(int size, char *zone, int line) |
25 | 266 { |
267 pool p; | |
417
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
268 p = _pool_new(zone, line); |
25 | 269 p->heap = _pool_heap(p,size); |
270 return p; | |
271 } | |
272 | |
417
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
273 /** |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
274 * allocate memory from a memory pool |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
275 * |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
276 * @param p the pool to use |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
277 * @param size how much memory to allocate |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
278 * @return pointer to the allocated memory |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
279 */ |
25 | 280 void *pmalloc(pool p, int size) |
281 { | |
282 void *block; | |
283 | |
284 if(p == NULL) | |
285 { | |
417
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
286 fprintf(stderr,"Memory Leak! [pmalloc received NULL pool, unable to track allocation, exiting]\n"); |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
287 abort(); |
25 | 288 } |
289 | |
290 /* if there is no heap for this pool or it's a big request, just raw, I like how we clean this :) */ | |
291 if(p->heap == NULL || size > (p->heap->size / 2)) | |
292 { | |
417
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
293 block = _retried__malloc(size); |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
294 p->size += size; |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
295 _pool_cleanup_append(p, _pool_free(p, _pool__free, block)); |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
296 return block; |
25 | 297 } |
298 | |
299 /* we have to preserve boundaries, long story :) */ | |
300 if(size >= 4) | |
417
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
301 while(p->heap->used&7) p->heap->used++; |
25 | 302 |
303 /* if we don't fit in the old heap, replace it */ | |
304 if(size > (p->heap->size - p->heap->used)) | |
417
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
305 p->heap = _pool_heap(p, p->heap->size); |
25 | 306 |
307 /* the current heap has room */ | |
308 block = (char *)p->heap->block + p->heap->used; | |
309 p->heap->used += size; | |
310 return block; | |
311 } | |
312 | |
417
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
313 /** |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
314 * allocate memory and initialize the memory with the given char c |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
315 * |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
316 * @deprecated jabberd does use pmalloco instead, this function will be removed |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
317 * |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
318 * @param p which pool to use |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
319 * @param size the size of the allocation |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
320 * @param c the initialization character |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
321 * @return pointer to the allocated memory |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
322 */ |
25 | 323 void *pmalloc_x(pool p, int size, char c) |
324 { | |
325 void* result = pmalloc(p, size); | |
326 if (result != NULL) | |
417
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
327 memset(result, c, size); |
25 | 328 return result; |
414
ec86d759ed54
Trailing whitespace cleanup
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
329 } |
25 | 330 |
417
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
331 /** |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
332 * allocate memory and initialize the memory with zero bytes |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
333 * |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
334 * easy safety utility (for creating blank mem for structs, etc) |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
335 * |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
336 * @param p which pool to use |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
337 * @param size the size of the allocation |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
338 * @return pointer to the allocated memory |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
339 */ |
25 | 340 void *pmalloco(pool p, int size) |
341 { | |
342 void *block = pmalloc(p, size); | |
343 memset(block, 0, size); | |
344 return block; | |
414
ec86d759ed54
Trailing whitespace cleanup
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
345 } |
25 | 346 |
417
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
347 /** |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
348 * duplicate a string and allocate memory for it |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
349 * |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
350 * @todo efficient: move this to const char* and then loop through the existing heaps to see if src is within a block in this pool |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
351 * |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
352 * @param p the pool to use |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
353 * @param src the string that should be duplicated |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
354 * @return the duplicated string |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
355 */ |
25 | 356 char *pstrdup(pool p, const char *src) |
357 { | |
358 char *ret; | |
359 | |
360 if(src == NULL) | |
417
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
361 return NULL; |
25 | 362 |
363 ret = pmalloc(p,strlen(src) + 1); | |
364 strcpy(ret,src); | |
365 | |
366 return ret; | |
367 } | |
368 | |
417
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
369 /** |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
370 * when pstrdup() is moved to "const char*", this one would actually return a new block |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
371 */ |
25 | 372 char *pstrdupx(pool p, const char *src) |
373 { | |
374 return pstrdup(p, src); | |
375 } | |
376 | |
417
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
377 /** |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
378 * get the size of a memory pool |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
379 * |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
380 * @param p the pool |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
381 * @return the size |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
382 */ |
25 | 383 int pool_size(pool p) |
384 { | |
385 if(p == NULL) return 0; | |
386 | |
387 return p->size; | |
388 } | |
389 | |
417
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
390 /** |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
391 * free a pool (and all memory that is allocated in it) |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
392 * |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
393 * @param p which pool to free |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
394 */ |
25 | 395 void pool_free(pool p) |
396 { | |
397 struct pfree *cur, *stub; | |
398 | |
399 if(p == NULL) return; | |
400 | |
401 cur = p->cleanup; | |
402 while(cur != NULL) | |
403 { | |
417
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
404 (*cur->f)(cur->arg); |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
405 stub = cur->next; |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
406 _pool__free(cur); |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
407 cur = stub; |
25 | 408 } |
409 | |
410 #ifdef POOL_DEBUG | |
411 ghash_remove(pool__disturbed,p->name); | |
412 #endif | |
413 | |
414 _pool__free(p); | |
415 | |
416 } | |
417 | |
417
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
418 /** |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
419 * public cleanup utils, insert in a way that they are run FIFO, before mem frees |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
420 */ |
25 | 421 void pool_cleanup(pool p, pool_cleaner f, void *arg) |
422 { | |
423 struct pfree *clean; | |
424 | |
425 clean = _pool_free(p, f, arg); | |
426 clean->next = p->cleanup; | |
427 p->cleanup = clean; | |
428 } | |
429 | |
430 #ifdef POOL_DEBUG | |
431 void debug_log(char *zone, const char *msgfmt, ...); | |
417
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
432 void _pool_stat(xht h, const char *key, void *data, void *arg) |
25 | 433 { |
434 pool p = (pool)data; | |
435 | |
436 if(p->lsize == -1) | |
417
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
437 debug_log("pool_debug","%s: %s is a new pool",p->zone, p->name); |
25 | 438 else if(p->size > p->lsize) |
417
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
439 debug_log("pool_debug","%s: %s grew %d",p->zone, p->name, p->size - p->lsize); |
25 | 440 else if((int)arg) |
417
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
441 debug_log("pool_debug","%s: %s exists %d",p->zone,p->name, p->size); |
25 | 442 p->lsize = p->size; |
443 } | |
444 | |
417
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
445 /** |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
446 * print memory pool statistics (for debugging purposes) |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
447 * |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
448 * @param full make a full report? (0 = no, 1 = yes) |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
449 */ |
25 | 450 void pool_stat(int full) |
451 { | |
417
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
452 if (pool__disturbed == NULL || pool__disturbed == (xht)1) |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
453 return; |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
454 |
25 | 455 ghash_walk(pool__disturbed,_pool_stat,(void *)full); |
456 if(pool__total != pool__ltotal) | |
417
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
457 debug_log("pool_debug","%d\ttotal missed mallocs",pool__total); |
25 | 458 pool__ltotal = pool__total; |
417
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
459 |
25 | 460 return; |
461 } | |
462 #else | |
417
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
463 /** |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
464 * dummy implementation: print memory pool statistics (for debugging purposes, real implementation if POOL_DEBUG is defined) |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
465 * |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
466 * @param full make a full report? (0 = no, 1 = yes) |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
414
diff
changeset
|
467 */ |
25 | 468 void pool_stat(int full) |
469 { | |
470 return; | |
471 } | |
472 #endif |