~ubuntu-branches/ubuntu/trusty/mariadb-5.5/trusty-proposed

« back to all changes in this revision

Viewing changes to storage/xtradb/include/dyn0dyn.h

  • Committer: Package Import Robot
  • Author(s): Otto Kekäläinen
  • Date: 2013-12-22 10:27:05 UTC
  • Revision ID: package-import@ubuntu.com-20131222102705-mndw7s12mz0szrcn
Tags: upstream-5.5.32
Import upstream version 5.5.32

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*****************************************************************************
 
2
 
 
3
Copyright (c) 1996, 2013, Oracle and/or its affiliates. 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.,
 
15
51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA
 
16
 
 
17
*****************************************************************************/
 
18
 
 
19
/**************************************************//**
 
20
@file include/dyn0dyn.h
 
21
The dynamically allocated array
 
22
 
 
23
Created 2/5/1996 Heikki Tuuri
 
24
*******************************************************/
 
25
 
 
26
#ifndef dyn0dyn_h
 
27
#define dyn0dyn_h
 
28
 
 
29
#include "univ.i"
 
30
#include "ut0lst.h"
 
31
#include "mem0mem.h"
 
32
 
 
33
/** A block in a dynamically allocated array */
 
34
typedef struct dyn_block_struct         dyn_block_t;
 
35
/** Dynamically allocated array */
 
36
typedef dyn_block_t                     dyn_array_t;
 
37
 
 
38
 
 
39
/** This is the initial 'payload' size of a dynamic array;
 
40
this must be > MLOG_BUF_MARGIN + 30! */
 
41
#define DYN_ARRAY_DATA_SIZE     512
 
42
 
 
43
/*********************************************************************//**
 
44
Initializes a dynamic array.
 
45
@return initialized dyn array */
 
46
UNIV_INLINE
 
47
dyn_array_t*
 
48
dyn_array_create(
 
49
/*=============*/
 
50
        dyn_array_t*    arr)    /*!< in/out memory buffer of
 
51
                                size sizeof(dyn_array_t) */
 
52
        __attribute__((nonnull));
 
53
/************************************************************//**
 
54
Frees a dynamic array. */
 
55
UNIV_INLINE
 
56
void
 
57
dyn_array_free(
 
58
/*===========*/
 
59
        dyn_array_t*    arr)    /*!< in,own: dyn array */
 
60
        __attribute__((nonnull));
 
61
/*********************************************************************//**
 
62
Makes room on top of a dyn array and returns a pointer to a buffer in it.
 
63
After copying the elements, the caller must close the buffer using
 
64
dyn_array_close.
 
65
@return pointer to the buffer */
 
66
UNIV_INLINE
 
67
byte*
 
68
dyn_array_open(
 
69
/*===========*/
 
70
        dyn_array_t*    arr,    /*!< in: dynamic array */
 
71
        ulint           size)   /*!< in: size in bytes of the buffer; MUST be
 
72
                                smaller than DYN_ARRAY_DATA_SIZE! */
 
73
        __attribute__((nonnull, warn_unused_result));
 
74
/*********************************************************************//**
 
75
Closes the buffer returned by dyn_array_open. */
 
76
UNIV_INLINE
 
77
void
 
78
dyn_array_close(
 
79
/*============*/
 
80
        dyn_array_t*    arr,    /*!< in: dynamic array */
 
81
        const byte*     ptr)    /*!< in: end of used space */
 
82
        __attribute__((nonnull));
 
83
/*********************************************************************//**
 
84
Makes room on top of a dyn array and returns a pointer to
 
85
the added element. The caller must copy the element to
 
86
the pointer returned.
 
87
@return pointer to the element */
 
88
UNIV_INLINE
 
89
void*
 
90
dyn_array_push(
 
91
/*===========*/
 
92
        dyn_array_t*    arr,    /*!< in/out: dynamic array */
 
93
        ulint           size)   /*!< in: size in bytes of the element */
 
94
        __attribute__((nonnull, warn_unused_result));
 
95
/************************************************************//**
 
96
Returns pointer to an element in dyn array.
 
97
@return pointer to element */
 
98
UNIV_INLINE
 
99
void*
 
100
dyn_array_get_element(
 
101
/*==================*/
 
102
        const dyn_array_t*      arr,    /*!< in: dyn array */
 
103
        ulint                   pos)    /*!< in: position of element
 
104
                                        in bytes from array start */
 
105
        __attribute__((nonnull, warn_unused_result));
 
106
/************************************************************//**
 
107
Returns the size of stored data in a dyn array.
 
108
@return data size in bytes */
 
109
UNIV_INLINE
 
110
ulint
 
111
dyn_array_get_data_size(
 
112
/*====================*/
 
113
        const dyn_array_t*      arr)    /*!< in: dyn array */
 
114
        __attribute__((nonnull, warn_unused_result, pure));
 
115
/************************************************************//**
 
116
Gets the first block in a dyn array.
 
117
@param arr      dyn array
 
118
@return         first block */
 
119
#define dyn_array_get_first_block(arr) (arr)
 
120
/************************************************************//**
 
121
Gets the last block in a dyn array.
 
122
@param arr      dyn array
 
123
@return         last block */
 
124
#define dyn_array_get_last_block(arr)                           \
 
125
        ((arr)->heap ? UT_LIST_GET_LAST((arr)->base) : (arr))
 
126
/********************************************************************//**
 
127
Gets the next block in a dyn array.
 
128
@param arr      dyn array
 
129
@param block    dyn array block
 
130
@return         pointer to next, NULL if end of list */
 
131
#define dyn_array_get_next_block(arr, block)                    \
 
132
        ((arr)->heap ? UT_LIST_GET_NEXT(list, block) : NULL)
 
133
/********************************************************************//**
 
134
Gets the previous block in a dyn array.
 
135
@param arr      dyn array
 
136
@param block    dyn array block
 
137
@return         pointer to previous, NULL if end of list */
 
138
#define dyn_array_get_prev_block(arr, block)                    \
 
139
        ((arr)->heap ? UT_LIST_GET_PREV(list, block) : NULL)
 
140
/********************************************************************//**
 
141
Gets the number of used bytes in a dyn array block.
 
142
@return number of bytes used */
 
143
UNIV_INLINE
 
144
ulint
 
145
dyn_block_get_used(
 
146
/*===============*/
 
147
        const dyn_block_t*      block)  /*!< in: dyn array block */
 
148
        __attribute__((nonnull, warn_unused_result, pure));
 
149
/********************************************************************//**
 
150
Gets pointer to the start of data in a dyn array block.
 
151
@return pointer to data */
 
152
UNIV_INLINE
 
153
byte*
 
154
dyn_block_get_data(
 
155
/*===============*/
 
156
        const dyn_block_t*      block)  /*!< in: dyn array block */
 
157
        __attribute__((nonnull, warn_unused_result, pure));
 
158
/********************************************************//**
 
159
Pushes n bytes to a dyn array. */
 
160
UNIV_INLINE
 
161
void
 
162
dyn_push_string(
 
163
/*============*/
 
164
        dyn_array_t*    arr,    /*!< in/out: dyn array */
 
165
        const byte*     str,    /*!< in: string to write */
 
166
        ulint           len)    /*!< in: string length */
 
167
        __attribute__((nonnull));
 
168
 
 
169
/*#################################################################*/
 
170
 
 
171
/** @brief A block in a dynamically allocated array.
 
172
NOTE! Do not access the fields of the struct directly: the definition
 
173
appears here only for the compiler to know its size! */
 
174
struct dyn_block_struct{
 
175
        mem_heap_t*     heap;   /*!< in the first block this is != NULL
 
176
                                if dynamic allocation has been needed */
 
177
        ulint           used;   /*!< number of data bytes used in this block;
 
178
                                DYN_BLOCK_FULL_FLAG is set when the block
 
179
                                becomes full */
 
180
        byte            data[DYN_ARRAY_DATA_SIZE];
 
181
                                /*!< storage for array elements */
 
182
        UT_LIST_BASE_NODE_T(dyn_block_t) base;
 
183
                                /*!< linear list of dyn blocks: this node is
 
184
                                used only in the first block */
 
185
        UT_LIST_NODE_T(dyn_block_t) list;
 
186
                                /*!< linear list node: used in all blocks */
 
187
#ifdef UNIV_DEBUG
 
188
        ulint           buf_end;/*!< only in the debug version: if dyn
 
189
                                array is opened, this is the buffer
 
190
                                end offset, else this is 0 */
 
191
        ulint           magic_n;/*!< magic number (DYN_BLOCK_MAGIC_N) */
 
192
#endif
 
193
};
 
194
 
 
195
 
 
196
#ifndef UNIV_NONINL
 
197
#include "dyn0dyn.ic"
 
198
#endif
 
199
 
 
200
#endif