1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/glib/tsrc/BC/tests/memchunks.c Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,612 @@
1.4 +/* GLIB - Library of useful routines for C programming
1.5 + * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
1.6 + *
1.7 + * This library is free software; you can redistribute it and/or
1.8 + * modify it under the terms of the GNU Lesser General Public
1.9 + * License as published by the Free Software Foundation; either
1.10 + * version 2 of the License, or (at your option) any later version.
1.11 + *
1.12 + * This library is distributed in the hope that it will be useful,
1.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1.15 + * Lesser General Public License for more details.
1.16 + *
1.17 + * You should have received a copy of the GNU Lesser General Public
1.18 + * License along with this library; if not, write to the
1.19 + * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
1.20 + * Boston, MA 02111-1307, USA.
1.21 + */
1.22 +
1.23 +/*
1.24 + * Modified by the GLib Team and others 1997-2000. See the AUTHORS
1.25 + * file for a list of people on the GLib Team. See the ChangeLog
1.26 + * files for a list of changes. These files are distributed with
1.27 + * GLib at ftp://ftp.gtk.org/pub/gtk/.
1.28 + */
1.29 +
1.30 +/*
1.31 + * MT safe
1.32 + */
1.33 +
1.34 +#include "config.h"
1.35 +
1.36 +#include <stdlib.h>
1.37 +#include <string.h>
1.38 +#include <signal.h>
1.39 +
1.40 +#include "glib.h"
1.41 +
1.42 +/* notes on macros:
1.43 + * if ENABLE_GC_FRIENDLY is defined, freed memory should be 0-wiped.
1.44 + */
1.45 +
1.46 +#define MEM_PROFILE_TABLE_SIZE 4096
1.47 +
1.48 +#define MEM_AREA_SIZE 4L
1.49 +
1.50 +static guint mem_chunk_recursion = 0;
1.51 +# define MEM_CHUNK_ROUTINE_COUNT() (mem_chunk_recursion)
1.52 +# define ENTER_MEM_CHUNK_ROUTINE() (mem_chunk_recursion = MEM_CHUNK_ROUTINE_COUNT () + 1)
1.53 +# define LEAVE_MEM_CHUNK_ROUTINE() (mem_chunk_recursion = MEM_CHUNK_ROUTINE_COUNT () - 1)
1.54 +
1.55 +/* --- old memchunk prototypes --- */
1.56 +void old_mem_chunks_init (void);
1.57 +GMemChunk* old_mem_chunk_new (const gchar *name,
1.58 + gint atom_size,
1.59 + gulong area_size,
1.60 + gint type);
1.61 +void old_mem_chunk_destroy (GMemChunk *mem_chunk);
1.62 +gpointer old_mem_chunk_alloc (GMemChunk *mem_chunk);
1.63 +gpointer old_mem_chunk_alloc0 (GMemChunk *mem_chunk);
1.64 +void old_mem_chunk_free (GMemChunk *mem_chunk,
1.65 + gpointer mem);
1.66 +void old_mem_chunk_clean (GMemChunk *mem_chunk);
1.67 +void old_mem_chunk_reset (GMemChunk *mem_chunk);
1.68 +void old_mem_chunk_print (GMemChunk *mem_chunk);
1.69 +void old_mem_chunk_info (void);
1.70 +
1.71 +
1.72 +/* --- MemChunks --- */
1.73 +#ifndef G_ALLOC_AND_FREE
1.74 +typedef struct _GAllocator GAllocator;
1.75 +typedef struct _GMemChunk GMemChunk;
1.76 +#define G_ALLOC_ONLY 1
1.77 +#define G_ALLOC_AND_FREE 2
1.78 +#endif
1.79 +
1.80 +typedef struct _GFreeAtom GFreeAtom;
1.81 +typedef struct _GMemArea GMemArea;
1.82 +
1.83 +struct _GFreeAtom
1.84 +{
1.85 + GFreeAtom *next;
1.86 +};
1.87 +
1.88 +struct _GMemArea
1.89 +{
1.90 + GMemArea *next; /* the next mem area */
1.91 + GMemArea *prev; /* the previous mem area */
1.92 + gulong index; /* the current index into the "mem" array */
1.93 + gulong free; /* the number of free bytes in this mem area */
1.94 + gulong allocated; /* the number of atoms allocated from this area */
1.95 + gulong mark; /* is this mem area marked for deletion */
1.96 + gchar mem[MEM_AREA_SIZE]; /* the mem array from which atoms get allocated
1.97 + * the actual size of this array is determined by
1.98 + * the mem chunk "area_size". ANSI says that it
1.99 + * must be declared to be the maximum size it
1.100 + * can possibly be (even though the actual size
1.101 + * may be less).
1.102 + */
1.103 +};
1.104 +
1.105 +struct _GMemChunk
1.106 +{
1.107 + const gchar *name; /* name of this MemChunk...used for debugging output */
1.108 + gint type; /* the type of MemChunk: ALLOC_ONLY or ALLOC_AND_FREE */
1.109 + gint num_mem_areas; /* the number of memory areas */
1.110 + gint num_marked_areas; /* the number of areas marked for deletion */
1.111 + guint atom_size; /* the size of an atom */
1.112 + gulong area_size; /* the size of a memory area */
1.113 + GMemArea *mem_area; /* the current memory area */
1.114 + GMemArea *mem_areas; /* a list of all the mem areas owned by this chunk */
1.115 + GMemArea *free_mem_area; /* the free area...which is about to be destroyed */
1.116 + GFreeAtom *free_atoms; /* the free atoms list */
1.117 + GTree *mem_tree; /* tree of mem areas sorted by memory address */
1.118 + GMemChunk *next; /* pointer to the next chunk */
1.119 + GMemChunk *prev; /* pointer to the previous chunk */
1.120 +};
1.121 +
1.122 +
1.123 +static gulong old_mem_chunk_compute_size (gulong size,
1.124 + gulong min_size) G_GNUC_CONST;
1.125 +static gint old_mem_chunk_area_compare (GMemArea *a,
1.126 + GMemArea *b);
1.127 +static gint old_mem_chunk_area_search (GMemArea *a,
1.128 + gchar *addr);
1.129 +
1.130 +/* here we can't use StaticMutexes, as they depend upon a working
1.131 + * g_malloc, the same holds true for StaticPrivate
1.132 + */
1.133 +static GMutex *mem_chunks_lock = NULL;
1.134 +static GMemChunk *mem_chunks = NULL;
1.135 +
1.136 +void
1.137 +old_mem_chunks_init (void)
1.138 +{
1.139 + mem_chunks_lock = g_mutex_new ();
1.140 +}
1.141 +
1.142 +GMemChunk*
1.143 +old_mem_chunk_new (const gchar *name,
1.144 + gint atom_size,
1.145 + gulong area_size,
1.146 + gint type)
1.147 +{
1.148 + GMemChunk *mem_chunk;
1.149 + gulong rarea_size;
1.150 +
1.151 + g_return_val_if_fail (atom_size > 0, NULL);
1.152 + g_return_val_if_fail (area_size >= atom_size, NULL);
1.153 +
1.154 + ENTER_MEM_CHUNK_ROUTINE ();
1.155 +
1.156 + area_size = (area_size + atom_size - 1) / atom_size;
1.157 + area_size *= atom_size;
1.158 +
1.159 + mem_chunk = g_new (GMemChunk, 1);
1.160 + mem_chunk->name = name;
1.161 + mem_chunk->type = type;
1.162 + mem_chunk->num_mem_areas = 0;
1.163 + mem_chunk->num_marked_areas = 0;
1.164 + mem_chunk->mem_area = NULL;
1.165 + mem_chunk->free_mem_area = NULL;
1.166 + mem_chunk->free_atoms = NULL;
1.167 + mem_chunk->mem_tree = NULL;
1.168 + mem_chunk->mem_areas = NULL;
1.169 + mem_chunk->atom_size = atom_size;
1.170 +
1.171 + if (mem_chunk->type == G_ALLOC_AND_FREE)
1.172 + mem_chunk->mem_tree = g_tree_new ((GCompareFunc) old_mem_chunk_area_compare);
1.173 +
1.174 + if (mem_chunk->atom_size % G_MEM_ALIGN)
1.175 + mem_chunk->atom_size += G_MEM_ALIGN - (mem_chunk->atom_size % G_MEM_ALIGN);
1.176 +
1.177 + rarea_size = area_size + sizeof (GMemArea) - MEM_AREA_SIZE;
1.178 + rarea_size = old_mem_chunk_compute_size (rarea_size, atom_size + sizeof (GMemArea) - MEM_AREA_SIZE);
1.179 + mem_chunk->area_size = rarea_size - (sizeof (GMemArea) - MEM_AREA_SIZE);
1.180 +
1.181 + g_mutex_lock (mem_chunks_lock);
1.182 + mem_chunk->next = mem_chunks;
1.183 + mem_chunk->prev = NULL;
1.184 + if (mem_chunks)
1.185 + mem_chunks->prev = mem_chunk;
1.186 + mem_chunks = mem_chunk;
1.187 + g_mutex_unlock (mem_chunks_lock);
1.188 +
1.189 + LEAVE_MEM_CHUNK_ROUTINE ();
1.190 +
1.191 + return mem_chunk;
1.192 +}
1.193 +
1.194 +void
1.195 +old_mem_chunk_destroy (GMemChunk *mem_chunk)
1.196 +{
1.197 + GMemArea *mem_areas;
1.198 + GMemArea *temp_area;
1.199 +
1.200 + g_return_if_fail (mem_chunk != NULL);
1.201 +
1.202 + ENTER_MEM_CHUNK_ROUTINE ();
1.203 +
1.204 + mem_areas = mem_chunk->mem_areas;
1.205 + while (mem_areas)
1.206 + {
1.207 + temp_area = mem_areas;
1.208 + mem_areas = mem_areas->next;
1.209 + g_free (temp_area);
1.210 + }
1.211 +
1.212 + g_mutex_lock (mem_chunks_lock);
1.213 + if (mem_chunk->next)
1.214 + mem_chunk->next->prev = mem_chunk->prev;
1.215 + if (mem_chunk->prev)
1.216 + mem_chunk->prev->next = mem_chunk->next;
1.217 +
1.218 + if (mem_chunk == mem_chunks)
1.219 + mem_chunks = mem_chunks->next;
1.220 + g_mutex_unlock (mem_chunks_lock);
1.221 +
1.222 + if (mem_chunk->type == G_ALLOC_AND_FREE)
1.223 + g_tree_destroy (mem_chunk->mem_tree);
1.224 +
1.225 + g_free (mem_chunk);
1.226 +
1.227 + LEAVE_MEM_CHUNK_ROUTINE ();
1.228 +}
1.229 +
1.230 +gpointer
1.231 +old_mem_chunk_alloc (GMemChunk *mem_chunk)
1.232 +{
1.233 + GMemArea *temp_area;
1.234 + gpointer mem;
1.235 +
1.236 + ENTER_MEM_CHUNK_ROUTINE ();
1.237 +
1.238 + g_return_val_if_fail (mem_chunk != NULL, NULL);
1.239 +
1.240 + while (mem_chunk->free_atoms)
1.241 + {
1.242 + /* Get the first piece of memory on the "free_atoms" list.
1.243 + * We can go ahead and destroy the list node we used to keep
1.244 + * track of it with and to update the "free_atoms" list to
1.245 + * point to its next element.
1.246 + */
1.247 + mem = mem_chunk->free_atoms;
1.248 + mem_chunk->free_atoms = mem_chunk->free_atoms->next;
1.249 +
1.250 + /* Determine which area this piece of memory is allocated from */
1.251 + temp_area = g_tree_search (mem_chunk->mem_tree,
1.252 + (GCompareFunc) old_mem_chunk_area_search,
1.253 + mem);
1.254 +
1.255 + /* If the area has been marked, then it is being destroyed.
1.256 + * (ie marked to be destroyed).
1.257 + * We check to see if all of the segments on the free list that
1.258 + * reference this area have been removed. This occurs when
1.259 + * the ammount of free memory is less than the allocatable size.
1.260 + * If the chunk should be freed, then we place it in the "free_mem_area".
1.261 + * This is so we make sure not to free the mem area here and then
1.262 + * allocate it again a few lines down.
1.263 + * If we don't allocate a chunk a few lines down then the "free_mem_area"
1.264 + * will be freed.
1.265 + * If there is already a "free_mem_area" then we'll just free this mem area.
1.266 + */
1.267 + if (temp_area->mark)
1.268 + {
1.269 + /* Update the "free" memory available in that area */
1.270 + temp_area->free += mem_chunk->atom_size;
1.271 +
1.272 + if (temp_area->free == mem_chunk->area_size)
1.273 + {
1.274 + if (temp_area == mem_chunk->mem_area)
1.275 + mem_chunk->mem_area = NULL;
1.276 +
1.277 + if (mem_chunk->free_mem_area)
1.278 + {
1.279 + mem_chunk->num_mem_areas -= 1;
1.280 +
1.281 + if (temp_area->next)
1.282 + temp_area->next->prev = temp_area->prev;
1.283 + if (temp_area->prev)
1.284 + temp_area->prev->next = temp_area->next;
1.285 + if (temp_area == mem_chunk->mem_areas)
1.286 + mem_chunk->mem_areas = mem_chunk->mem_areas->next;
1.287 +
1.288 + if (mem_chunk->type == G_ALLOC_AND_FREE)
1.289 + g_tree_remove (mem_chunk->mem_tree, temp_area);
1.290 + g_free (temp_area);
1.291 + }
1.292 + else
1.293 + mem_chunk->free_mem_area = temp_area;
1.294 +
1.295 + mem_chunk->num_marked_areas -= 1;
1.296 + }
1.297 + }
1.298 + else
1.299 + {
1.300 + /* Update the number of allocated atoms count.
1.301 + */
1.302 + temp_area->allocated += 1;
1.303 +
1.304 + /* The area wasn't marked...return the memory
1.305 + */
1.306 + goto outa_here;
1.307 + }
1.308 + }
1.309 +
1.310 + /* If there isn't a current mem area or the current mem area is out of space
1.311 + * then allocate a new mem area. We'll first check and see if we can use
1.312 + * the "free_mem_area". Otherwise we'll just malloc the mem area.
1.313 + */
1.314 + if ((!mem_chunk->mem_area) ||
1.315 + ((mem_chunk->mem_area->index + mem_chunk->atom_size) > mem_chunk->area_size))
1.316 + {
1.317 + if (mem_chunk->free_mem_area)
1.318 + {
1.319 + mem_chunk->mem_area = mem_chunk->free_mem_area;
1.320 + mem_chunk->free_mem_area = NULL;
1.321 + }
1.322 + else
1.323 + {
1.324 +#ifdef ENABLE_GC_FRIENDLY
1.325 + mem_chunk->mem_area = (GMemArea*) g_malloc0 (sizeof (GMemArea) -
1.326 + MEM_AREA_SIZE +
1.327 + mem_chunk->area_size);
1.328 +#else /* !ENABLE_GC_FRIENDLY */
1.329 + mem_chunk->mem_area = (GMemArea*) g_malloc (sizeof (GMemArea) -
1.330 + MEM_AREA_SIZE +
1.331 + mem_chunk->area_size);
1.332 +#endif /* ENABLE_GC_FRIENDLY */
1.333 +
1.334 + mem_chunk->num_mem_areas += 1;
1.335 + mem_chunk->mem_area->next = mem_chunk->mem_areas;
1.336 + mem_chunk->mem_area->prev = NULL;
1.337 +
1.338 + if (mem_chunk->mem_areas)
1.339 + mem_chunk->mem_areas->prev = mem_chunk->mem_area;
1.340 + mem_chunk->mem_areas = mem_chunk->mem_area;
1.341 +
1.342 + if (mem_chunk->type == G_ALLOC_AND_FREE)
1.343 + g_tree_insert (mem_chunk->mem_tree, mem_chunk->mem_area, mem_chunk->mem_area);
1.344 + }
1.345 +
1.346 + mem_chunk->mem_area->index = 0;
1.347 + mem_chunk->mem_area->free = mem_chunk->area_size;
1.348 + mem_chunk->mem_area->allocated = 0;
1.349 + mem_chunk->mem_area->mark = 0;
1.350 + }
1.351 +
1.352 + /* Get the memory and modify the state variables appropriately.
1.353 + */
1.354 + mem = (gpointer) &mem_chunk->mem_area->mem[mem_chunk->mem_area->index];
1.355 + mem_chunk->mem_area->index += mem_chunk->atom_size;
1.356 + mem_chunk->mem_area->free -= mem_chunk->atom_size;
1.357 + mem_chunk->mem_area->allocated += 1;
1.358 +
1.359 + outa_here:
1.360 +
1.361 + LEAVE_MEM_CHUNK_ROUTINE ();
1.362 +
1.363 + return mem;
1.364 +}
1.365 +
1.366 +gpointer
1.367 +old_mem_chunk_alloc0 (GMemChunk *mem_chunk)
1.368 +{
1.369 + gpointer mem;
1.370 +
1.371 + mem = old_mem_chunk_alloc (mem_chunk);
1.372 + if (mem)
1.373 + {
1.374 + memset (mem, 0, mem_chunk->atom_size);
1.375 + }
1.376 +
1.377 + return mem;
1.378 +}
1.379 +
1.380 +void
1.381 +old_mem_chunk_free (GMemChunk *mem_chunk,
1.382 + gpointer mem)
1.383 +{
1.384 + GMemArea *temp_area;
1.385 + GFreeAtom *free_atom;
1.386 +
1.387 + g_return_if_fail (mem_chunk != NULL);
1.388 + g_return_if_fail (mem != NULL);
1.389 +
1.390 + ENTER_MEM_CHUNK_ROUTINE ();
1.391 +
1.392 +#ifdef ENABLE_GC_FRIENDLY
1.393 + memset (mem, 0, mem_chunk->atom_size);
1.394 +#endif /* ENABLE_GC_FRIENDLY */
1.395 +
1.396 + /* Don't do anything if this is an ALLOC_ONLY chunk
1.397 + */
1.398 + if (mem_chunk->type == G_ALLOC_AND_FREE)
1.399 + {
1.400 + /* Place the memory on the "free_atoms" list
1.401 + */
1.402 + free_atom = (GFreeAtom*) mem;
1.403 + free_atom->next = mem_chunk->free_atoms;
1.404 + mem_chunk->free_atoms = free_atom;
1.405 +
1.406 + temp_area = g_tree_search (mem_chunk->mem_tree,
1.407 + (GCompareFunc) old_mem_chunk_area_search,
1.408 + mem);
1.409 +
1.410 + temp_area->allocated -= 1;
1.411 +
1.412 + if (temp_area->allocated == 0)
1.413 + {
1.414 + temp_area->mark = 1;
1.415 + mem_chunk->num_marked_areas += 1;
1.416 + }
1.417 + }
1.418 +
1.419 + LEAVE_MEM_CHUNK_ROUTINE ();
1.420 +}
1.421 +
1.422 +/* This doesn't free the free_area if there is one */
1.423 +void
1.424 +old_mem_chunk_clean (GMemChunk *mem_chunk)
1.425 +{
1.426 + GMemArea *mem_area;
1.427 + GFreeAtom *prev_free_atom;
1.428 + GFreeAtom *temp_free_atom;
1.429 + gpointer mem;
1.430 +
1.431 + g_return_if_fail (mem_chunk != NULL);
1.432 +
1.433 + ENTER_MEM_CHUNK_ROUTINE ();
1.434 +
1.435 + if (mem_chunk->type == G_ALLOC_AND_FREE)
1.436 + {
1.437 + prev_free_atom = NULL;
1.438 + temp_free_atom = mem_chunk->free_atoms;
1.439 +
1.440 + while (temp_free_atom)
1.441 + {
1.442 + mem = (gpointer) temp_free_atom;
1.443 +
1.444 + mem_area = g_tree_search (mem_chunk->mem_tree,
1.445 + (GCompareFunc) old_mem_chunk_area_search,
1.446 + mem);
1.447 +
1.448 + /* If this mem area is marked for destruction then delete the
1.449 + * area and list node and decrement the free mem.
1.450 + */
1.451 + if (mem_area->mark)
1.452 + {
1.453 + if (prev_free_atom)
1.454 + prev_free_atom->next = temp_free_atom->next;
1.455 + else
1.456 + mem_chunk->free_atoms = temp_free_atom->next;
1.457 + temp_free_atom = temp_free_atom->next;
1.458 +
1.459 + mem_area->free += mem_chunk->atom_size;
1.460 + if (mem_area->free == mem_chunk->area_size)
1.461 + {
1.462 + mem_chunk->num_mem_areas -= 1;
1.463 + mem_chunk->num_marked_areas -= 1;
1.464 +
1.465 + if (mem_area->next)
1.466 + mem_area->next->prev = mem_area->prev;
1.467 + if (mem_area->prev)
1.468 + mem_area->prev->next = mem_area->next;
1.469 + if (mem_area == mem_chunk->mem_areas)
1.470 + mem_chunk->mem_areas = mem_chunk->mem_areas->next;
1.471 + if (mem_area == mem_chunk->mem_area)
1.472 + mem_chunk->mem_area = NULL;
1.473 +
1.474 + if (mem_chunk->type == G_ALLOC_AND_FREE)
1.475 + g_tree_remove (mem_chunk->mem_tree, mem_area);
1.476 + g_free (mem_area);
1.477 + }
1.478 + }
1.479 + else
1.480 + {
1.481 + prev_free_atom = temp_free_atom;
1.482 + temp_free_atom = temp_free_atom->next;
1.483 + }
1.484 + }
1.485 + }
1.486 + LEAVE_MEM_CHUNK_ROUTINE ();
1.487 +}
1.488 +
1.489 +void
1.490 +old_mem_chunk_reset (GMemChunk *mem_chunk)
1.491 +{
1.492 + GMemArea *mem_areas;
1.493 + GMemArea *temp_area;
1.494 +
1.495 + g_return_if_fail (mem_chunk != NULL);
1.496 +
1.497 + ENTER_MEM_CHUNK_ROUTINE ();
1.498 +
1.499 + mem_areas = mem_chunk->mem_areas;
1.500 + mem_chunk->num_mem_areas = 0;
1.501 + mem_chunk->mem_areas = NULL;
1.502 + mem_chunk->mem_area = NULL;
1.503 +
1.504 + while (mem_areas)
1.505 + {
1.506 + temp_area = mem_areas;
1.507 + mem_areas = mem_areas->next;
1.508 + g_free (temp_area);
1.509 + }
1.510 +
1.511 + mem_chunk->free_atoms = NULL;
1.512 +
1.513 + if (mem_chunk->mem_tree)
1.514 + {
1.515 + g_tree_destroy (mem_chunk->mem_tree);
1.516 + mem_chunk->mem_tree = g_tree_new ((GCompareFunc) old_mem_chunk_area_compare);
1.517 + }
1.518 +
1.519 + LEAVE_MEM_CHUNK_ROUTINE ();
1.520 +}
1.521 +
1.522 +void
1.523 +old_mem_chunk_print (GMemChunk *mem_chunk)
1.524 +{
1.525 + GMemArea *mem_areas;
1.526 + gulong mem;
1.527 +
1.528 + g_return_if_fail (mem_chunk != NULL);
1.529 +
1.530 + mem_areas = mem_chunk->mem_areas;
1.531 + mem = 0;
1.532 +
1.533 + while (mem_areas)
1.534 + {
1.535 + mem += mem_chunk->area_size - mem_areas->free;
1.536 + mem_areas = mem_areas->next;
1.537 + }
1.538 +
1.539 + g_log (G_LOG_DOMAIN, G_LOG_LEVEL_INFO,
1.540 + "%s: %ld bytes using %d mem areas",
1.541 + mem_chunk->name, mem, mem_chunk->num_mem_areas);
1.542 +}
1.543 +
1.544 +void
1.545 +old_mem_chunk_info (void)
1.546 +{
1.547 + GMemChunk *mem_chunk;
1.548 + gint count;
1.549 +
1.550 + count = 0;
1.551 + g_mutex_lock (mem_chunks_lock);
1.552 + mem_chunk = mem_chunks;
1.553 + while (mem_chunk)
1.554 + {
1.555 + count += 1;
1.556 + mem_chunk = mem_chunk->next;
1.557 + }
1.558 + g_mutex_unlock (mem_chunks_lock);
1.559 +
1.560 + g_log (G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "%d mem chunks", count);
1.561 +
1.562 + g_mutex_lock (mem_chunks_lock);
1.563 + mem_chunk = mem_chunks;
1.564 + g_mutex_unlock (mem_chunks_lock);
1.565 +
1.566 + while (mem_chunk)
1.567 + {
1.568 + old_mem_chunk_print ((GMemChunk*) mem_chunk);
1.569 + mem_chunk = mem_chunk->next;
1.570 + }
1.571 +}
1.572 +
1.573 +static gulong
1.574 +old_mem_chunk_compute_size (gulong size,
1.575 + gulong min_size)
1.576 +{
1.577 + gulong power_of_2;
1.578 + gulong lower, upper;
1.579 +
1.580 + power_of_2 = 16;
1.581 + while (power_of_2 < size)
1.582 + power_of_2 <<= 1;
1.583 +
1.584 + lower = power_of_2 >> 1;
1.585 + upper = power_of_2;
1.586 +
1.587 + if (size - lower < upper - size && lower >= min_size)
1.588 + return lower;
1.589 + else
1.590 + return upper;
1.591 +}
1.592 +
1.593 +static gint
1.594 +old_mem_chunk_area_compare (GMemArea *a,
1.595 + GMemArea *b)
1.596 +{
1.597 + if (a->mem > b->mem)
1.598 + return 1;
1.599 + else if (a->mem < b->mem)
1.600 + return -1;
1.601 + return 0;
1.602 +}
1.603 +
1.604 +static gint
1.605 +old_mem_chunk_area_search (GMemArea *a,
1.606 + gchar *addr)
1.607 +{
1.608 + if (a->mem <= addr)
1.609 + {
1.610 + if (addr < &a->mem[a->index])
1.611 + return 0;
1.612 + return 1;
1.613 + }
1.614 + return -1;
1.615 +}