~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/innobase/mem/mem0mem.cc

  • Committer: Monty Taylor
  • Date: 2011-02-13 17:26:39 UTC
  • mfrom: (2157.2.2 give-in-to-pkg-config)
  • mto: This revision was merged to the branch mainline in revision 2166.
  • Revision ID: mordred@inaugust.com-20110213172639-nhy7i72sfhoq13ms
Merged in pkg-config fixes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*****************************************************************************
2
2
 
3
 
Copyright (c) 1994, 2009, Innobase Oy. All Rights Reserved.
 
3
Copyright (C) 1994, 2010, Innobase Oy. All Rights Reserved.
4
4
 
5
5
This program is free software; you can redistribute it and/or modify it under
6
6
the terms of the GNU General Public License as published by the Free Software
11
11
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12
12
 
13
13
You should have received a copy of the GNU General Public License along with
14
 
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
15
 
Place, Suite 330, Boston, MA 02111-1307 USA
 
14
this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
 
15
St, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
*****************************************************************************/
18
18
 
24
24
*************************************************************************/
25
25
 
26
26
#include "mem0mem.h"
 
27
 
27
28
#ifdef UNIV_NONINL
28
29
#include "mem0mem.ic"
29
30
#endif
30
31
 
31
32
#include "buf0buf.h"
32
33
#include "srv0srv.h"
33
 
#include "mem0dbg.c"
 
34
#include "mem0dbg.cc"
34
35
#include <stdarg.h>
35
36
 
36
37
/*
108
109
        mem_heap_t*     heap,   /*!< in: memory heap where string is allocated */
109
110
        const char*     str)    /*!< in: string to be copied */
110
111
{
111
 
        return(mem_heap_dup(heap, str, strlen(str) + 1));
 
112
        return(static_cast<char *>(mem_heap_dup(heap, str, strlen(str) + 1)));
112
113
}
113
114
 
114
115
/**********************************************************************//**
140
141
        ulint   s1_len = strlen(s1);
141
142
        ulint   s2_len = strlen(s2);
142
143
 
143
 
        s = mem_heap_alloc(heap, s1_len + s2_len + 1);
 
144
        s = static_cast<char *>(mem_heap_alloc(heap, s1_len + s2_len + 1));
144
145
 
145
146
        memcpy(s, s1, s1_len);
146
147
        memcpy(s + s1_len, s2, s2_len);
285
286
        va_end(ap);
286
287
 
287
288
        /* Now create it for real. */
288
 
        str = mem_heap_alloc(heap, len);
 
289
        str = static_cast<char *>(mem_heap_alloc(heap, len));
289
290
        va_start(ap, format);
290
291
        mem_heap_printf_low(str, format, ap);
291
292
        va_end(ap);
330
331
 
331
332
                ut_ad(type == MEM_HEAP_DYNAMIC || n <= MEM_MAX_ALLOC_IN_BUF);
332
333
 
333
 
                block = mem_area_alloc(&len, mem_comm_pool);
 
334
                block = static_cast<mem_block_info_t *>(mem_area_alloc(&len, mem_comm_pool));
334
335
        } else {
335
336
                len = UNIV_PAGE_SIZE;
336
337
 
339
340
                        buffer pool, but must get the free block from
340
341
                        the heap header free block field */
341
342
 
342
 
                        buf_block = heap->free_block;
 
343
                        buf_block = static_cast<buf_block_t *>(heap->free_block);
343
344
                        heap->free_block = NULL;
344
345
 
345
346
                        if (UNIV_UNLIKELY(!buf_block)) {
347
348
                                return(NULL);
348
349
                        }
349
350
                } else {
350
 
                        buf_block = buf_block_alloc(0);
 
351
                        buf_block = buf_block_alloc(NULL, 0);
351
352
                }
352
353
 
353
354
                block = (mem_block_t*) buf_block->frame;
367
368
        block->line = line;
368
369
 
369
370
#ifdef MEM_PERIODIC_CHECK
370
 
        mem_pool_mutex_enter();
 
371
        mutex_enter(&(mem_comm_pool->mutex));
371
372
 
372
373
        if (!mem_block_list_inited) {
373
374
                mem_block_list_inited = TRUE;
376
377
 
377
378
        UT_LIST_ADD_LAST(mem_block_list, mem_block_list, block);
378
379
 
379
 
        mem_pool_mutex_exit();
 
380
        mutex_exit(&(mem_comm_pool->mutex));
380
381
#endif
381
382
        mem_block_set_len(block, len);
382
383
        mem_block_set_type(block, type);
383
384
        mem_block_set_free(block, MEM_BLOCK_HEADER_SIZE);
384
385
        mem_block_set_start(block, MEM_BLOCK_HEADER_SIZE);
385
386
 
 
387
        if (UNIV_UNLIKELY(heap == NULL)) {
 
388
                /* This is the first block of the heap. The field
 
389
                total_size should be initialized here */
 
390
                block->total_size = len;
 
391
        } else {
 
392
                /* Not the first allocation for the heap. This block's
 
393
                total_length field should be set to undefined. */
 
394
                ut_d(block->total_size = ULINT_UNDEFINED);
 
395
                UNIV_MEM_INVALID(&block->total_size,
 
396
                                 sizeof block->total_size);
 
397
 
 
398
                heap->total_size += len;
 
399
        }
 
400
 
386
401
        ut_ad((ulint)MEM_BLOCK_HEADER_SIZE < len);
387
402
 
388
403
        return(block);
455
470
        ulint           type;
456
471
        ulint           len;
457
472
#ifndef UNIV_HOTBACKUP
458
 
        buf_block_t*    buf_block       = block->buf_block;
 
473
        buf_block_t*    buf_block       = static_cast<buf_block_t *>(block->buf_block);
459
474
#endif /* !UNIV_HOTBACKUP */
460
475
 
461
476
        if (block->magic_n != MEM_BLOCK_MAGIC_N) {
465
480
        UT_LIST_REMOVE(list, heap->base, block);
466
481
 
467
482
#ifdef MEM_PERIODIC_CHECK
468
 
        mem_pool_mutex_enter();
 
483
        mutex_enter(&(mem_comm_pool->mutex));
469
484
 
470
485
        UT_LIST_REMOVE(mem_block_list, mem_block_list, block);
471
486
 
472
 
        mem_pool_mutex_exit();
 
487
        mutex_exit(&(mem_comm_pool->mutex));
473
488
#endif
 
489
 
 
490
        ut_ad(heap->total_size >= block->len);
 
491
        heap->total_size -= block->len;
 
492
 
474
493
        type = heap->type;
475
494
        len = block->len;
476
495
        block->magic_n = MEM_FREED_BLOCK_MAGIC_N;
477
496
 
 
497
#ifndef UNIV_HOTBACKUP
478
498
#ifdef UNIV_MEM_DEBUG
479
499
        /* In the debug version we set the memory to a random combination
480
500
        of hex 0xDE and 0xAD. */
484
504
        UNIV_MEM_ASSERT_AND_FREE(block, len);
485
505
#endif /* UNIV_MEM_DEBUG */
486
506
 
487
 
#ifndef UNIV_HOTBACKUP
488
507
        if (type == MEM_HEAP_DYNAMIC || len < UNIV_PAGE_SIZE / 2) {
489
508
 
490
509
                ut_ad(!buf_block);
495
514
                buf_block_free(buf_block);
496
515
        }
497
516
#else /* !UNIV_HOTBACKUP */
 
517
#ifdef UNIV_MEM_DEBUG
 
518
        /* In the debug version we set the memory to a random
 
519
        combination of hex 0xDE and 0xAD. */
 
520
 
 
521
        mem_erase_buf((byte*)block, len);
 
522
#else /* UNIV_MEM_DEBUG */
 
523
        UNIV_MEM_ASSERT_AND_FREE(block, len);
 
524
#endif /* UNIV_MEM_DEBUG */
498
525
        ut_free(block);
499
526
#endif /* !UNIV_HOTBACKUP */
500
527
}
510
537
{
511
538
        if (UNIV_LIKELY_NULL(heap->free_block)) {
512
539
 
513
 
                buf_block_free(heap->free_block);
 
540
                buf_block_free(static_cast<buf_block_t *>(heap->free_block));
514
541
 
515
542
                heap->free_block = NULL;
516
543
        }
528
555
{
529
556
        mem_block_t*    block;
530
557
 
531
 
        mem_pool_mutex_enter();
 
558
        mutex_enter(&(mem_comm_pool->mutex));
532
559
 
533
560
        block = UT_LIST_GET_FIRST(mem_block_list);
534
561
 
540
567
                block = UT_LIST_GET_NEXT(mem_block_list, block);
541
568
        }
542
569
 
543
 
        mem_pool_mutex_exit();
 
570
        mutex_exit(&(mem_comm_pool->mutex));
544
571
}
545
572
#endif