~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • 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:
1
 
/******************************************************
2
 
Binary buddy allocator for compressed pages
3
 
 
4
 
(c) 2006 Innobase Oy
5
 
 
6
 
Created December 2006 by Marko Makela
7
 
*******************************************************/
8
 
 
9
 
#ifdef UNIV_MATERIALIZE
10
 
# undef UNIV_INLINE
11
 
# define UNIV_INLINE
12
 
#endif
13
 
 
14
 
#include "buf0buf.h"
15
 
#include "buf0buddy.h"
16
 
#include "ut0ut.h"
17
 
#include "sync0sync.h"
18
 
 
19
 
/**************************************************************************
20
 
Allocate a block.  The thread calling this function must hold
21
 
buf_pool_mutex and must not hold buf_pool_zip_mutex or any block->mutex.
22
 
The buf_pool_mutex may only be released and reacquired if lru != NULL. */
23
 
UNIV_INTERN
24
 
void*
25
 
buf_buddy_alloc_low(
26
 
/*================*/
27
 
                        /* out: allocated block,
28
 
                        possibly NULL if lru==NULL */
29
 
        ulint   i,      /* in: index of buf_pool->zip_free[],
30
 
                        or BUF_BUDDY_SIZES */
31
 
        ibool*  lru)    /* in: pointer to a variable that will be assigned
32
 
                        TRUE if storage was allocated from the LRU list
33
 
                        and buf_pool_mutex was temporarily released,
34
 
                        or NULL if the LRU list should not be used */
35
 
        __attribute__((malloc));
36
 
 
37
 
/**************************************************************************
38
 
Deallocate a block. */
39
 
UNIV_INTERN
40
 
void
41
 
buf_buddy_free_low(
42
 
/*===============*/
43
 
        void*   buf,    /* in: block to be freed, must not be
44
 
                        pointed to by the buffer pool */
45
 
        ulint   i)      /* in: index of buf_pool->zip_free[],
46
 
                        or BUF_BUDDY_SIZES */
47
 
        __attribute__((nonnull));
48
 
 
49
 
/**************************************************************************
50
 
Get the index of buf_pool->zip_free[] for a given block size. */
51
 
UNIV_INLINE
52
 
ulint
53
 
buf_buddy_get_slot(
54
 
/*===============*/
55
 
                        /* out: index of buf_pool->zip_free[],
56
 
                        or BUF_BUDDY_SIZES */
57
 
        ulint   size)   /* in: block size */
58
 
{
59
 
        ulint   i;
60
 
        ulint   s;
61
 
 
62
 
        for (i = 0, s = BUF_BUDDY_LOW; s < size; i++, s <<= 1) {};
63
 
 
64
 
        ut_ad(i <= BUF_BUDDY_SIZES);
65
 
        return(i);
66
 
}
67
 
 
68
 
/**************************************************************************
69
 
Allocate a block.  The thread calling this function must hold
70
 
buf_pool_mutex and must not hold buf_pool_zip_mutex or any
71
 
block->mutex.  The buf_pool_mutex may only be released and reacquired
72
 
if lru != NULL.  This function should only be used for allocating
73
 
compressed page frames or control blocks (buf_page_t).  Allocated
74
 
control blocks must be properly initialized immediately after
75
 
buf_buddy_alloc() has returned the memory, before releasing
76
 
buf_pool_mutex. */
77
 
UNIV_INLINE
78
 
void*
79
 
buf_buddy_alloc(
80
 
/*============*/
81
 
                        /* out: allocated block,
82
 
                        possibly NULL if lru == NULL */
83
 
        ulint   size,   /* in: block size, up to UNIV_PAGE_SIZE */
84
 
        ibool*  lru)    /* in: pointer to a variable that will be assigned
85
 
                        TRUE if storage was allocated from the LRU list
86
 
                        and buf_pool_mutex was temporarily released,
87
 
                        or NULL if the LRU list should not be used */
88
 
{
89
 
        ut_ad(buf_pool_mutex_own());
90
 
 
91
 
        return(buf_buddy_alloc_low(buf_buddy_get_slot(size), lru));
92
 
}
93
 
 
94
 
/**************************************************************************
95
 
Deallocate a block. */
96
 
UNIV_INLINE
97
 
void
98
 
buf_buddy_free(
99
 
/*===========*/
100
 
        void*   buf,    /* in: block to be freed, must not be
101
 
                        pointed to by the buffer pool */
102
 
        ulint   size)   /* in: block size, up to UNIV_PAGE_SIZE */
103
 
{
104
 
        ut_ad(buf_pool_mutex_own());
105
 
 
106
 
        buf_buddy_free_low(buf, buf_buddy_get_slot(size));
107
 
}
108
 
 
109
 
#ifdef UNIV_MATERIALIZE
110
 
# undef UNIV_INLINE
111
 
# define UNIV_INLINE    UNIV_INLINE_ORIGINAL
112
 
#endif