~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

code clean move Item_func_abs, Item_func_int_exp, Item_func_ln, Item_func_log to functions directory

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., 59 Temple
15
 
Place, Suite 330, Boston, MA 02111-1307 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
 
        ulint   i,      /*!< in: index of buf_pool->zip_free[],
46
 
                        or BUF_BUDDY_SIZES */
47
 
        ibool*  lru)    /*!< in: pointer to a variable that will be assigned
48
 
                        TRUE if storage was allocated from the LRU list
49
 
                        and buf_pool_mutex was temporarily released,
50
 
                        or NULL if the LRU list should not be used */
51
 
        __attribute__((malloc));
52
 
 
53
 
/**********************************************************************//**
54
 
Deallocate a block. */
55
 
UNIV_INTERN
56
 
void
57
 
buf_buddy_free_low(
58
 
/*===============*/
59
 
        void*   buf,    /*!< in: block to be freed, must not be
60
 
                        pointed to by the buffer pool */
61
 
        ulint   i)      /*!< in: index of buf_pool->zip_free[],
62
 
                        or BUF_BUDDY_SIZES */
63
 
        __attribute__((nonnull));
64
 
 
65
 
/**********************************************************************//**
66
 
Get the index of buf_pool->zip_free[] for a given block size.
67
 
@return index of buf_pool->zip_free[], or BUF_BUDDY_SIZES */
68
 
UNIV_INLINE
69
 
ulint
70
 
buf_buddy_get_slot(
71
 
/*===============*/
72
 
        ulint   size)   /*!< in: block size */
73
 
{
74
 
        ulint   i;
75
 
        ulint   s;
76
 
 
77
 
        for (i = 0, s = BUF_BUDDY_LOW; s < size; i++, s <<= 1) {
78
 
        }
79
 
 
80
 
        ut_ad(i <= BUF_BUDDY_SIZES);
81
 
        return(i);
82
 
}
83
 
 
84
 
/**********************************************************************//**
85
 
Allocate a block.  The thread calling this function must hold
86
 
buf_pool_mutex and must not hold buf_pool_zip_mutex or any
87
 
block->mutex.  The buf_pool_mutex may only be released and reacquired
88
 
if lru != NULL.  This function should only be used for allocating
89
 
compressed page frames or control blocks (buf_page_t).  Allocated
90
 
control blocks must be properly initialized immediately after
91
 
buf_buddy_alloc() has returned the memory, before releasing
92
 
buf_pool_mutex.
93
 
@return allocated block, possibly NULL if lru == NULL */
94
 
UNIV_INLINE
95
 
void*
96
 
buf_buddy_alloc(
97
 
/*============*/
98
 
        ulint   size,   /*!< in: block size, up to UNIV_PAGE_SIZE */
99
 
        ibool*  lru)    /*!< in: pointer to a variable that will be assigned
100
 
                        TRUE if storage was allocated from the LRU list
101
 
                        and buf_pool_mutex was temporarily released,
102
 
                        or NULL if the LRU list should not be used */
103
 
{
104
 
        ut_ad(buf_pool_mutex_own());
105
 
 
106
 
        return(buf_buddy_alloc_low(buf_buddy_get_slot(size), lru));
107
 
}
108
 
 
109
 
/**********************************************************************//**
110
 
Deallocate a block. */
111
 
UNIV_INLINE
112
 
void
113
 
buf_buddy_free(
114
 
/*===========*/
115
 
        void*   buf,    /*!< in: block to be freed, must not be
116
 
                        pointed to by the buffer pool */
117
 
        ulint   size)   /*!< in: block size, up to UNIV_PAGE_SIZE */
118
 
{
119
 
        ut_ad(buf_pool_mutex_own());
120
 
 
121
 
        buf_buddy_free_low(buf, buf_buddy_get_slot(size));
122
 
}
123
 
 
124
 
#ifdef UNIV_MATERIALIZE
125
 
# undef UNIV_INLINE
126
 
# define UNIV_INLINE    UNIV_INLINE_ORIGINAL
127
 
#endif