~ubuntu-branches/ubuntu/trusty/mysql-5.6/trusty

« back to all changes in this revision

Viewing changes to storage/innobase/include/ut0list.h

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2014-02-12 11:54:27 UTC
  • Revision ID: package-import@ubuntu.com-20140212115427-oq6tfsqxl1wuwehi
Tags: upstream-5.6.15
ImportĀ upstreamĀ versionĀ 5.6.15

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*****************************************************************************
 
2
 
 
3
Copyright (c) 2006, 2009, 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/ut0list.h
 
21
A double-linked list
 
22
 
 
23
Created 4/26/2006 Osku Salerma
 
24
************************************************************************/
 
25
 
 
26
/*******************************************************************//**
 
27
A double-linked list. This differs from the one in ut0lst.h in that in this
 
28
one, each list node contains a pointer to the data, whereas the one in
 
29
ut0lst.h uses a strategy where the list pointers are embedded in the data
 
30
items themselves.
 
31
 
 
32
Use this one when you need to store arbitrary data in the list where you
 
33
can't embed the list pointers in the data, if a data item needs to be
 
34
stored in multiple lists, etc.
 
35
 
 
36
Note about the memory management: ib_list_t is a fixed-size struct whose
 
37
allocation/deallocation is done through ib_list_create/ib_list_free, but the
 
38
memory for the list nodes is allocated through a user-given memory heap,
 
39
which can either be the same for all nodes or vary per node. Most users will
 
40
probably want to create a memory heap to store the item-specific data, and
 
41
pass in this same heap to the list node creation functions, thus
 
42
automatically freeing the list node when the item's heap is freed.
 
43
 
 
44
************************************************************************/
 
45
 
 
46
#ifndef IB_LIST_H
 
47
#define IB_LIST_H
 
48
 
 
49
#include "mem0mem.h"
 
50
 
 
51
struct ib_list_t;
 
52
struct ib_list_node_t;
 
53
 
 
54
/****************************************************************//**
 
55
Create a new list using mem_alloc. Lists created with this function must be
 
56
freed with ib_list_free.
 
57
@return list */
 
58
UNIV_INTERN
 
59
ib_list_t*
 
60
ib_list_create(void);
 
61
/*=================*/
 
62
 
 
63
 
 
64
/****************************************************************//**
 
65
Create a new list using the given heap. ib_list_free MUST NOT BE CALLED for
 
66
lists created with this function.
 
67
@return list */
 
68
UNIV_INTERN
 
69
ib_list_t*
 
70
ib_list_create_heap(
 
71
/*================*/
 
72
        mem_heap_t*     heap);  /*!< in: memory heap to use */
 
73
 
 
74
/****************************************************************//**
 
75
Free a list. */
 
76
UNIV_INTERN
 
77
void
 
78
ib_list_free(
 
79
/*=========*/
 
80
        ib_list_t*      list);  /*!< in: list */
 
81
 
 
82
/****************************************************************//**
 
83
Add the data to the start of the list.
 
84
@return new list node */
 
85
UNIV_INTERN
 
86
ib_list_node_t*
 
87
ib_list_add_first(
 
88
/*==============*/
 
89
        ib_list_t*      list,   /*!< in: list */
 
90
        void*           data,   /*!< in: data */
 
91
        mem_heap_t*     heap);  /*!< in: memory heap to use */
 
92
 
 
93
/****************************************************************//**
 
94
Add the data to the end of the list.
 
95
@return new list node */
 
96
UNIV_INTERN
 
97
ib_list_node_t*
 
98
ib_list_add_last(
 
99
/*=============*/
 
100
        ib_list_t*      list,   /*!< in: list */
 
101
        void*           data,   /*!< in: data */
 
102
        mem_heap_t*     heap);  /*!< in: memory heap to use */
 
103
 
 
104
/****************************************************************//**
 
105
Add the data after the indicated node.
 
106
@return new list node */
 
107
UNIV_INTERN
 
108
ib_list_node_t*
 
109
ib_list_add_after(
 
110
/*==============*/
 
111
        ib_list_t*      list,           /*!< in: list */
 
112
        ib_list_node_t* prev_node,      /*!< in: node preceding new node (can
 
113
                                        be NULL) */
 
114
        void*           data,           /*!< in: data */
 
115
        mem_heap_t*     heap);          /*!< in: memory heap to use */
 
116
 
 
117
/****************************************************************//**
 
118
Remove the node from the list. */
 
119
UNIV_INTERN
 
120
void
 
121
ib_list_remove(
 
122
/*===========*/
 
123
        ib_list_t*      list,   /*!< in: list */
 
124
        ib_list_node_t* node);  /*!< in: node to remove */
 
125
 
 
126
/****************************************************************//**
 
127
Get the first node in the list.
 
128
@return first node, or NULL */
 
129
UNIV_INLINE
 
130
ib_list_node_t*
 
131
ib_list_get_first(
 
132
/*==============*/
 
133
        ib_list_t*      list);  /*!< in: list */
 
134
 
 
135
/****************************************************************//**
 
136
Get the last node in the list.
 
137
@return last node, or NULL */
 
138
UNIV_INLINE
 
139
ib_list_node_t*
 
140
ib_list_get_last(
 
141
/*=============*/
 
142
        ib_list_t*      list);  /*!< in: list */
 
143
 
 
144
/********************************************************************
 
145
Check if list is empty. */
 
146
UNIV_INLINE
 
147
ibool
 
148
ib_list_is_empty(
 
149
/*=============*/
 
150
                                        /* out: TRUE if empty else  */
 
151
        const ib_list_t*        list);  /* in: list */
 
152
 
 
153
/* List. */
 
154
struct ib_list_t {
 
155
        ib_list_node_t*         first;          /*!< first node */
 
156
        ib_list_node_t*         last;           /*!< last node */
 
157
        ibool                   is_heap_list;   /*!< TRUE if this list was
 
158
                                                allocated through a heap */
 
159
};
 
160
 
 
161
/* A list node. */
 
162
struct ib_list_node_t {
 
163
        ib_list_node_t*         prev;           /*!< previous node */
 
164
        ib_list_node_t*         next;           /*!< next node */
 
165
        void*                   data;           /*!< user data */
 
166
};
 
167
 
 
168
/* Quite often, the only additional piece of data you need is the per-item
 
169
memory heap, so we have this generic struct available to use in those
 
170
cases. */
 
171
struct ib_list_helper_t {
 
172
        mem_heap_t*     heap;           /*!< memory heap */
 
173
        void*           data;           /*!< user data */
 
174
};
 
175
 
 
176
#ifndef UNIV_NONINL
 
177
#include "ut0list.ic"
 
178
#endif
 
179
 
 
180
#endif