~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/innobase/include/buf0buddy.ic

  • Committer: Monty Taylor
  • Date: 2008-11-16 05:36:13 UTC
  • mto: (584.1.9 devel)
  • mto: This revision was merged to the branch mainline in revision 589.
  • Revision ID: monty@inaugust.com-20081116053613-bld4rqxhlkb49c02
Split out cache_row and type_holder.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*****************************************************************************
2
 
 
3
 
Copyright (C) 2006, 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., 51 Franklin
15
 
St, Fifth Floor, Boston, MA 02110-1301 USA
16
 
 
17
 
*****************************************************************************/
18
 
 
19
 
/**************************************************//**
20
 
@file include/buf0buddy.ic
21
 
Binary buddy allocator for compressed pages
22
 
 
23
 
Created December 2006 by Marko Makela
24
 
*******************************************************/
25
 
 
26
 
#ifdef UNIV_MATERIALIZE
27
 
# undef UNIV_INLINE
28
 
# define UNIV_INLINE
29
 
#endif
30
 
 
31
 
#include "buf0buf.h"
32
 
#include "buf0buddy.h"
33
 
#include "ut0ut.h"
34
 
#include "sync0sync.h"
35
 
 
36
 
/**********************************************************************//**
37
 
Allocate a block.  The thread calling this function must hold
38
 
buf_pool->mutex and must not hold buf_pool->zip_mutex or any block->mutex.
39
 
The buf_pool->mutex may only be released and reacquired if lru != NULL.
40
 
@return allocated block, possibly NULL if lru==NULL */
41
 
UNIV_INTERN
42
 
void*
43
 
buf_buddy_alloc_low(
44
 
/*================*/
45
 
        buf_pool_t*     buf_pool,
46
 
                        /*!< in: buffer pool in which the page resides */
47
 
        ulint   i,      /*!< in: index of buf_pool->zip_free[],
48
 
                        or BUF_BUDDY_SIZES */
49
 
        ibool*  lru)    /*!< in: pointer to a variable that will be assigned
50
 
                        TRUE if storage was allocated from the LRU list
51
 
                        and buf_pool->mutex was temporarily released,
52
 
                        or NULL if the LRU list should not be used */
53
 
        __attribute__((malloc));
54
 
 
55
 
/**********************************************************************//**
56
 
Deallocate a block. */
57
 
UNIV_INTERN
58
 
void
59
 
buf_buddy_free_low(
60
 
/*===============*/
61
 
        buf_pool_t*     buf_pool,       /*!< in: buffer pool instance */
62
 
        void*           buf,            /*!< in: block to be freed, must not be
63
 
                                        pointed to by the buffer pool */
64
 
        ulint           i)              /*!< in: index of buf_pool->zip_free[],
65
 
                                        or BUF_BUDDY_SIZES */
66
 
        __attribute__((nonnull));
67
 
 
68
 
/**********************************************************************//**
69
 
Get the index of buf_pool->zip_free[] for a given block size.
70
 
@return index of buf_pool->zip_free[], or BUF_BUDDY_SIZES */
71
 
UNIV_INLINE
72
 
ulint
73
 
buf_buddy_get_slot(
74
 
/*===============*/
75
 
        ulint   size)   /*!< in: block size */
76
 
{
77
 
        ulint   i;
78
 
        ulint   s;
79
 
 
80
 
        for (i = 0, s = BUF_BUDDY_LOW; s < size; i++, s <<= 1) {
81
 
        }
82
 
 
83
 
        ut_ad(i <= BUF_BUDDY_SIZES);
84
 
        return(i);
85
 
}
86
 
 
87
 
/**********************************************************************//**
88
 
Allocate a block.  The thread calling this function must hold
89
 
buf_pool->mutex and must not hold buf_pool->zip_mutex or any
90
 
block->mutex.  The buf_pool->mutex may only be released and reacquired
91
 
if lru != NULL.  This function should only be used for allocating
92
 
compressed page frames or control blocks (buf_page_t).  Allocated
93
 
control blocks must be properly initialized immediately after
94
 
buf_buddy_alloc() has returned the memory, before releasing
95
 
buf_pool->mutex.
96
 
@return allocated block, possibly NULL if lru == NULL */
97
 
UNIV_INLINE
98
 
void*
99
 
buf_buddy_alloc(
100
 
/*============*/
101
 
        buf_pool_t*     buf_pool,       /*!< in: buffer pool in which
102
 
                                        the page resides */
103
 
        ulint           size,           /*!< in: block size, up to
104
 
                                        UNIV_PAGE_SIZE */
105
 
        ibool*          lru)            /*!< in: pointer to a variable
106
 
                                        that will be assigned TRUE if
107
 
                                        storage was allocated from the
108
 
                                        LRU list and buf_pool->mutex was
109
 
                                        temporarily released, or NULL if
110
 
                                        the LRU list should not be used */
111
 
{
112
 
        ut_ad(buf_pool_mutex_own(buf_pool));
113
 
 
114
 
        return(buf_buddy_alloc_low(buf_pool, buf_buddy_get_slot(size), lru));
115
 
}
116
 
 
117
 
/**********************************************************************//**
118
 
Deallocate a block. */
119
 
UNIV_INLINE
120
 
void
121
 
buf_buddy_free(
122
 
/*===========*/
123
 
        buf_pool_t*     buf_pool,       /*!< in: buffer pool instance */
124
 
        void*           buf,            /*!< in: block to be freed, must not be
125
 
                                        pointed to by the buffer pool */
126
 
        ulint           size)           /*!< in: block size, up to
127
 
                                        UNIV_PAGE_SIZE */
128
 
{
129
 
        ut_ad(buf_pool_mutex_own(buf_pool));
130
 
 
131
 
        buf_buddy_free_low(buf_pool, buf, buf_buddy_get_slot(size));
132
 
}
133
 
 
134
 
#ifdef UNIV_MATERIALIZE
135
 
# undef UNIV_INLINE
136
 
# define UNIV_INLINE    UNIV_INLINE_ORIGINAL
137
 
#endif