~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/innobase/mem/mem0pool.c

  • Committer: Brian Aker
  • Date: 2008-09-04 19:31:00 UTC
  • Revision ID: brian@tangent.org-20080904193100-l849hgghfy4urj43
Changing default character set from this point on.

Show diffs side-by-side

added added

removed removed

Lines of Context:
94
94
};
95
95
 
96
96
/* The common memory pool */
97
 
UNIV_INTERN mem_pool_t* mem_comm_pool   = NULL;
 
97
mem_pool_t*     mem_comm_pool   = NULL;
98
98
 
99
99
/* We use this counter to check that the mem pool mutex does not leak;
100
100
this is to track a strange assertion failure reported at
101
101
mysql@lists.mysql.com */
102
102
 
103
 
UNIV_INTERN ulint       mem_n_threads_inside            = 0;
 
103
ulint           mem_n_threads_inside            = 0;
104
104
 
105
105
/************************************************************************
106
106
Reserves the mem pool mutex. */
107
 
UNIV_INTERN
 
107
 
108
108
void
109
109
mem_pool_mutex_enter(void)
110
110
/*======================*/
114
114
 
115
115
/************************************************************************
116
116
Releases the mem pool mutex. */
117
 
UNIV_INTERN
 
117
 
118
118
void
119
119
mem_pool_mutex_exit(void)
120
120
/*=====================*/
180
180
 
181
181
/************************************************************************
182
182
Creates a memory pool. */
183
 
UNIV_INTERN
 
183
 
184
184
mem_pool_t*
185
185
mem_pool_create(
186
186
/*============*/
261
261
 
262
262
        ut_ad(mutex_own(&(pool->mutex)));
263
263
 
264
 
        if (UNIV_UNLIKELY(i >= 63)) {
 
264
        if (i >= 63) {
265
265
                /* We come here when we have run out of space in the
266
266
                memory pool: */
267
267
 
293
293
                area = UT_LIST_GET_FIRST(pool->free_list[i + 1]);
294
294
        }
295
295
 
296
 
        if (UNIV_UNLIKELY(UT_LIST_GET_LEN(pool->free_list[i + 1]) == 0)) {
 
296
        if (UT_LIST_GET_LEN(pool->free_list[i + 1]) == 0) {
297
297
                mem_analyze_corruption(area);
298
298
 
299
299
                ut_error;
319
319
/************************************************************************
320
320
Allocates memory from a pool. NOTE: This low-level function should only be
321
321
used in mem0mem.*! */
322
 
UNIV_INTERN
 
322
 
323
323
void*
324
324
mem_area_alloc(
325
325
/*===========*/
326
326
                                /* out, own: allocated memory buffer */
327
 
        ulint*          psize,  /* in: requested size in bytes; for optimum
 
327
        ulint           size,   /* in: allocated size in bytes; for optimum
328
328
                                space usage, the size should be a power of 2
329
 
                                minus MEM_AREA_EXTRA_SIZE;
330
 
                                out: allocated size in bytes (greater than
331
 
                                or equal to the requested size) */
 
329
                                minus MEM_AREA_EXTRA_SIZE */
332
330
        mem_pool_t*     pool)   /* in: memory pool */
333
331
{
334
332
        mem_area_t*     area;
335
 
        ulint           size;
336
333
        ulint           n;
337
334
        ibool           ret;
338
335
 
339
 
        size = *psize;
340
336
        n = ut_2_log(ut_max(size + MEM_AREA_EXTRA_SIZE, MEM_AREA_MIN_SIZE));
341
337
 
342
338
        mutex_enter(&(pool->mutex));
407
403
        mutex_exit(&(pool->mutex));
408
404
 
409
405
        ut_ad(mem_pool_validate(pool));
410
 
 
411
 
        *psize = ut_2_exp(n) - MEM_AREA_EXTRA_SIZE;
412
 
        UNIV_MEM_ALLOC(MEM_AREA_EXTRA_SIZE + (byte*)area, *psize);
 
406
        UNIV_MEM_ALLOC(MEM_AREA_EXTRA_SIZE + (byte*)area,
 
407
                       ut_2_exp(n) - MEM_AREA_EXTRA_SIZE);
413
408
 
414
409
        return((void*)(MEM_AREA_EXTRA_SIZE + ((byte*)area)));
415
410
}
456
451
 
457
452
/************************************************************************
458
453
Frees memory to a pool. */
459
 
UNIV_INTERN
 
454
 
460
455
void
461
456
mem_area_free(
462
457
/*==========*/
511
506
 
512
507
                next_size = mem_area_get_size(
513
508
                        (mem_area_t*)(((byte*)area) + size));
514
 
                if (UNIV_UNLIKELY(!next_size || !ut_is_2pow(next_size))) {
 
509
                if (ut_2_power_up(next_size) != next_size) {
515
510
                        fprintf(stderr,
516
511
                                "InnoDB: Error: Memory area size %lu,"
517
512
                                " next area size %lu not a power of 2!\n"
579
574
 
580
575
/************************************************************************
581
576
Validates a memory pool. */
582
 
UNIV_INTERN
 
577
 
583
578
ibool
584
579
mem_pool_validate(
585
580
/*==============*/
625
620
 
626
621
/************************************************************************
627
622
Prints info of a memory pool. */
628
 
UNIV_INTERN
 
623
 
629
624
void
630
625
mem_pool_print_info(
631
626
/*================*/
658
653
 
659
654
/************************************************************************
660
655
Returns the amount of reserved memory. */
661
 
UNIV_INTERN
 
656
 
662
657
ulint
663
658
mem_pool_get_reserved(
664
659
/*==================*/