~ubuntu-branches/ubuntu/maverick/drizzle/maverick

« back to all changes in this revision

Viewing changes to plugin/innobase/include/mem0pool.h

  • Committer: Bazaar Package Importer
  • Author(s): Monty Taylor
  • Date: 2010-03-18 12:12:31 UTC
  • Revision ID: james.westby@ubuntu.com-20100318121231-k6g1xe6cshbwa0f8
Tags: upstream-2010.03.1347
ImportĀ upstreamĀ versionĀ 2010.03.1347

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*****************************************************************************
 
2
 
 
3
Copyright (c) 1994, 2009, Innobase Oy. All Rights Reserved.
 
4
 
 
5
This program is free software; you can redistribute it and/or modify it under
 
6
the terms of the GNU General Public License as published by the Free Software
 
7
Foundation; version 2 of the License.
 
8
 
 
9
This program is distributed in the hope that it will be useful, but WITHOUT
 
10
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 
11
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 
12
 
 
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
 
16
 
 
17
*****************************************************************************/
 
18
 
 
19
/**************************************************//**
 
20
@file include/mem0pool.h
 
21
The lowest-level memory management
 
22
 
 
23
Created 6/9/1994 Heikki Tuuri
 
24
*******************************************************/
 
25
 
 
26
#ifndef mem0pool_h
 
27
#define mem0pool_h
 
28
 
 
29
#include "univ.i"
 
30
#include "os0file.h"
 
31
#include "ut0lst.h"
 
32
 
 
33
/** Memory area header */
 
34
typedef struct mem_area_struct  mem_area_t;
 
35
/** Memory pool */
 
36
typedef struct mem_pool_struct  mem_pool_t;
 
37
 
 
38
/** The common memory pool */
 
39
extern mem_pool_t*      mem_comm_pool;
 
40
 
 
41
/** Memory area header */
 
42
 
 
43
struct mem_area_struct{
 
44
        ulint           size_and_free;  /*!< memory area size is obtained by
 
45
                                        anding with ~MEM_AREA_FREE; area in
 
46
                                        a free list if ANDing with
 
47
                                        MEM_AREA_FREE results in nonzero */
 
48
        UT_LIST_NODE_T(mem_area_t)
 
49
                        free_list;      /*!< free list node */
 
50
};
 
51
 
 
52
/** Each memory area takes this many extra bytes for control information */
 
53
#define MEM_AREA_EXTRA_SIZE     (ut_calc_align(sizeof(struct mem_area_struct),\
 
54
                        UNIV_MEM_ALIGNMENT))
 
55
 
 
56
/********************************************************************//**
 
57
Creates a memory pool.
 
58
@return memory pool */
 
59
UNIV_INTERN
 
60
mem_pool_t*
 
61
mem_pool_create(
 
62
/*============*/
 
63
        ulint   size);  /*!< in: pool size in bytes */
 
64
/********************************************************************//**
 
65
Allocates memory from a pool. NOTE: This low-level function should only be
 
66
used in mem0mem.*!
 
67
@return own: allocated memory buffer */
 
68
UNIV_INTERN
 
69
void*
 
70
mem_area_alloc(
 
71
/*===========*/
 
72
        ulint*          psize,  /*!< in: requested size in bytes; for optimum
 
73
                                space usage, the size should be a power of 2
 
74
                                minus MEM_AREA_EXTRA_SIZE;
 
75
                                out: allocated size in bytes (greater than
 
76
                                or equal to the requested size) */
 
77
        mem_pool_t*     pool);  /*!< in: memory pool */
 
78
/********************************************************************//**
 
79
Frees memory to a pool. */
 
80
UNIV_INTERN
 
81
void
 
82
mem_area_free(
 
83
/*==========*/
 
84
        void*           ptr,    /*!< in, own: pointer to allocated memory
 
85
                                buffer */
 
86
        mem_pool_t*     pool);  /*!< in: memory pool */
 
87
/********************************************************************//**
 
88
Returns the amount of reserved memory.
 
89
@return reserved mmeory in bytes */
 
90
UNIV_INTERN
 
91
ulint
 
92
mem_pool_get_reserved(
 
93
/*==================*/
 
94
        mem_pool_t*     pool);  /*!< in: memory pool */
 
95
/********************************************************************//**
 
96
Reserves the mem pool mutex. */
 
97
UNIV_INTERN
 
98
void
 
99
mem_pool_mutex_enter(void);
 
100
/*======================*/
 
101
/********************************************************************//**
 
102
Releases the mem pool mutex. */
 
103
UNIV_INTERN
 
104
void
 
105
mem_pool_mutex_exit(void);
 
106
/*=====================*/
 
107
/********************************************************************//**
 
108
Validates a memory pool.
 
109
@return TRUE if ok */
 
110
UNIV_INTERN
 
111
ibool
 
112
mem_pool_validate(
 
113
/*==============*/
 
114
        mem_pool_t*     pool);  /*!< in: memory pool */
 
115
/********************************************************************//**
 
116
Prints info of a memory pool. */
 
117
UNIV_INTERN
 
118
void
 
119
mem_pool_print_info(
 
120
/*================*/
 
121
        FILE*           outfile,/*!< in: output file to write to */
 
122
        mem_pool_t*     pool);  /*!< in: memory pool */
 
123
 
 
124
 
 
125
#ifndef UNIV_NONINL
 
126
#include "mem0pool.ic"
 
127
#endif
 
128
 
 
129
#endif