~ubuntu-branches/ubuntu/hardy/apache2/hardy-proposed

« back to all changes in this revision

Viewing changes to srclib/apr/memory/unix/apr_pools.c

  • Committer: Bazaar Package Importer
  • Author(s): Stefan Fritsch
  • Date: 2008-01-17 20:27:56 UTC
  • mto: This revision was merged to the branch mainline in revision 26.
  • Revision ID: james.westby@ubuntu.com-20080117202756-hv38rjknhwa2ilwi
Tags: upstream-2.2.8
ImportĀ upstreamĀ versionĀ 2.2.8

Show diffs side-by-side

added added

removed removed

Lines of Context:
62
62
 
63
63
/*
64
64
 * Allocator
 
65
 *
 
66
 * @note The max_free_index and current_free_index fields are not really
 
67
 * indices, but quantities of BOUNDARY_SIZE big memory blocks.
65
68
 */
66
69
 
67
70
struct apr_allocator_t {
 
71
    /** largest used index into free[], always < MAX_INDEX */
68
72
    apr_uint32_t        max_index;
 
73
    /** Total size (in BOUNDARY_SIZE multiples) of unused memory before
 
74
     * blocks are given back. @see apr_allocator_max_free_set().
 
75
     * @note Initialized to APR_ALLOCATOR_MAX_FREE_UNLIMITED,
 
76
     * which means to never give back blocks.
 
77
     */
69
78
    apr_uint32_t        max_free_index;
 
79
    /**
 
80
     * Memory size (in BOUNDARY_SIZE multiples) that currently must be freed
 
81
     * before blocks are given back. Range: 0..max_free_index
 
82
     */
70
83
    apr_uint32_t        current_free_index;
71
84
#if APR_HAS_THREADS
72
85
    apr_thread_mutex_t *mutex;
73
86
#endif /* APR_HAS_THREADS */
74
87
    apr_pool_t         *owner;
 
88
    /**
 
89
     * Lists of free nodes. Slot 0 is used for oversized nodes,
 
90
     * and the slots 1..MAX_INDEX-1 contain nodes of sizes
 
91
     * (i+1) * BOUNDARY_SIZE. Example for BOUNDARY_INDEX == 12:
 
92
     * slot  0: nodes larger than 81920
 
93
     * slot  1: size  8192
 
94
     * slot  2: size 12288
 
95
     * ...
 
96
     * slot 19: size 81920
 
97
     */
75
98
    apr_memnode_t      *free[MAX_INDEX];
76
99
};
77
100
 
345
368
                max_index = index;
346
369
            }
347
370
            allocator->free[index] = node;
348
 
            current_free_index -= index;
 
371
            if (current_free_index >= index)
 
372
                current_free_index -= index;
 
373
            else
 
374
                current_free_index = 0;
349
375
        }
350
376
        else {
351
377
            /* This node is too large to keep in a specific size bucket,
353
379
             */
354
380
            node->next = allocator->free[0];
355
381
            allocator->free[0] = node;
356
 
            current_free_index -= index;
 
382
            if (current_free_index >= index)
 
383
                current_free_index -= index;
 
384
            else
 
385
                current_free_index = 0;
357
386
        }
358
387
    } while ((node = next) != NULL);
359
388