File: pobj_list_head.3

package info (click to toggle)
pmdk 1.5.1-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 31,076 kB
  • sloc: ansic: 144,239; sh: 29,351; cpp: 10,136; perl: 5,122; makefile: 3,531; pascal: 1,383; python: 677
file content (295 lines) | stat: -rw-r--r-- 13,039 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
.\" Automatically generated by Pandoc 2.1.3
.\"
.TH "POBJ_LIST_HEAD" "3" "2018-07-18" "PMDK - pmemobj API version 2.3" "PMDK Programmer's Manual"
.hy
.\" Copyright 2014-2018, Intel Corporation
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\"
.\"     * Redistributions of source code must retain the above copyright
.\"       notice, this list of conditions and the following disclaimer.
.\"
.\"     * Redistributions in binary form must reproduce the above copyright
.\"       notice, this list of conditions and the following disclaimer in
.\"       the documentation and/or other materials provided with the
.\"       distribution.
.\"
.\"     * Neither the name of the copyright holder nor the names of its
.\"       contributors may be used to endorse or promote products derived
.\"       from this software without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
.\" "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
.\" LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
.\" A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
.\" OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
.\" LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
.\" OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.SH NAME
.PP
\f[B]POBJ_LIST_HEAD\f[](), \f[B]POBJ_LIST_ENTRY\f[](),
\f[B]POBJ_LIST_FIRST\f[](), \f[B]POBJ_LIST_LAST\f[](),
\f[B]POBJ_LIST_EMPTY\f[](), \f[B]POBJ_LIST_NEXT\f[](),
\f[B]POBJ_LIST_PREV\f[](),
.PP
\f[B]POBJ_LIST_FOREACH\f[](), \f[B]POBJ_LIST_FOREACH_REVERSE\f[](),
.PP
\f[B]POBJ_LIST_INSERT_HEAD\f[](), \f[B]POBJ_LIST_INSERT_TAIL\f[](),
\f[B]POBJ_LIST_INSERT_AFTER\f[](), \f[B]POBJ_LIST_INSERT_BEFORE\f[](),
\f[B]POBJ_LIST_INSERT_NEW_HEAD\f[](),
\f[B]POBJ_LIST_INSERT_NEW_TAIL\f[](),
\f[B]POBJ_LIST_INSERT_NEW_AFTER\f[](),
\f[B]POBJ_LIST_INSERT_NEW_BEFORE\f[](),
.PP
\f[B]POBJ_LIST_REMOVE\f[](), \f[B]POBJ_LIST_REMOVE_FREE\f[](),
.PP
\f[B]POBJ_LIST_MOVE_ELEMENT_HEAD\f[](),
\f[B]POBJ_LIST_MOVE_ELEMENT_TAIL\f[](),
\f[B]POBJ_LIST_MOVE_ELEMENT_AFTER\f[](),
\f[B]POBJ_LIST_MOVE_ELEMENT_BEFORE\f[]() \- type\-safe
non\-transactional persistent atomic lists
.SH SYNOPSIS
.IP
.nf
\f[C]
#include\ <libpmemobj.h>

POBJ_LIST_HEAD(HEADNAME,\ TYPE)
POBJ_LIST_ENTRY(TYPE)
POBJ_LIST_FIRST(POBJ_LIST_HEAD\ *head)
POBJ_LIST_LAST(POBJ_LIST_HEAD\ *head,\ POBJ_LIST_ENTRY\ FIELD)
POBJ_LIST_EMPTY(POBJ_LIST_HEAD\ *head)
POBJ_LIST_NEXT(TOID\ elm,\ POBJ_LIST_ENTRY\ FIELD)
POBJ_LIST_PREV(TOID\ elm,\ POBJ_LIST_ENTRY\ FIELD)

POBJ_LIST_FOREACH(TOID\ var,\ POBJ_LIST_HEAD\ *head,\ POBJ_LIST_ENTRY\ FIELD)
POBJ_LIST_FOREACH_REVERSE(TOID\ var,\ POBJ_LIST_HEAD\ *head,\ POBJ_LIST_ENTRY\ FIELD)

POBJ_LIST_INSERT_HEAD(PMEMobjpool\ *pop,\ POBJ_LIST_HEAD\ *head,
\ \ \ \ TOID\ elm,\ POBJ_LIST_ENTRY\ FIELD)
POBJ_LIST_INSERT_TAIL(PMEMobjpool\ *pop,\ POBJ_LIST_HEAD\ *head,
\ \ \ \ TOID\ elm,\ POBJ_LIST_ENTRY\ FIELD)
POBJ_LIST_INSERT_AFTER(PMEMobjpool\ *pop,\ POBJ_LIST_HEAD\ *head,
\ \ \ \ TOID\ listelm,\ TOID\ elm,\ POBJ_LIST_ENTRY\ FIELD)
POBJ_LIST_INSERT_BEFORE(PMEMobjpool\ *pop,\ POBJ_LIST_HEAD\ *head,
\ \ \ \ TOID\ listelm,\ TOID\ elm,\ POBJ_LIST_ENTRY\ FIELD)
POBJ_LIST_INSERT_NEW_HEAD(PMEMobjpool\ *pop,\ POBJ_LIST_HEAD\ *head,
\ \ \ \ POBJ_LIST_ENTRY\ FIELD,\ size_t\ size,
\ \ \ \ pmemobj_constr\ constructor,\ void\ *arg)
POBJ_LIST_INSERT_NEW_TAIL(PMEMobjpool\ *pop,\ POBJ_LIST_HEAD\ *head,
\ \ \ \ POBJ_LIST_ENTRY\ FIELD,\ size_t\ size,
\ \ \ \ pmemobj_constr\ constructor,\ void\ *arg)
POBJ_LIST_INSERT_NEW_AFTER(PMEMobjpool\ *pop,\ POBJ_LIST_HEAD\ *head,
\ \ \ \ TOID\ listelm,\ POBJ_LIST_ENTRY\ FIELD,\ size_t\ size,
\ \ \ \ pmemobj_constr\ constructor,\ void\ *arg)
POBJ_LIST_INSERT_NEW_BEFORE(PMEMobjpool\ *pop,\ POBJ_LIST_HEAD\ *head,
\ \ \ \ TOID\ listelm,\ POBJ_LIST_ENTRY\ FIELD,\ size_t\ size,
\ \ \ \ pmemobj_constr\ constructor,\ void\ *arg)

POBJ_LIST_REMOVE(PMEMobjpool\ *pop,\ POBJ_LIST_HEAD\ *head,
\ \ \ \ TOID\ elm,\ POBJ_LIST_ENTRY\ FIELD)
POBJ_LIST_REMOVE_FREE(PMEMobjpool\ *pop,\ POBJ_LIST_HEAD\ *head,
\ \ \ \ TOID\ elm,\ POBJ_LIST_ENTRY\ FIELD)

POBJ_LIST_MOVE_ELEMENT_HEAD(PMEMobjpool\ *pop,\ POBJ_LIST_HEAD\ *head,
\ \ \ \ POBJ_LIST_HEAD\ *head_new,\ TOID\ elm,\ POBJ_LIST_ENTRY\ FIELD,
\ \ \ \ POBJ_LIST_ENTRY\ field_new)
POBJ_LIST_MOVE_ELEMENT_TAIL(PMEMobjpool\ *pop,\ POBJ_LIST_HEAD\ *head,
\ \ \ \ POBJ_LIST_HEAD\ *head_new,\ TOID\ elm,\ POBJ_LIST_ENTRY\ FIELD,
\ \ \ \ POBJ_LIST_ENTRY\ field_new)
POBJ_LIST_MOVE_ELEMENT_AFTER(PMEMobjpool\ *pop,\ POBJ_LIST_HEAD\ *head,
\ \ \ \ POBJ_LIST_HEAD\ *head_new,\ TOID\ listelm,\ TOID\ elm,
\ \ \ \ POBJ_LIST_ENTRY\ FIELD,\ POBJ_LIST_ENTRY\ field_new)
POBJ_LIST_MOVE_ELEMENT_BEFORE(PMEMobjpool\ *pop,\ POBJ_LIST_HEAD\ *head,
\ \ \ \ POBJ_LIST_HEAD\ *head_new,\ TOID\ listelm,\ TOID\ elm,
\ \ \ \ POBJ_LIST_ENTRY\ FIELD,\ POBJ_LIST_ENTRY\ field_new)
\f[]
.fi
.SH DESCRIPTION
.PP
The following macros define and operate on a type\-safe persistent
atomic circular doubly linked list data structure that consist of a set
of persistent objects of a well\-known type.
Unlike the functions described in the previous section, these macros
provide type enforcement by requiring declaration of type of the objects
stored in given list, and not allowing mixing objects of different types
in a single list.
.PP
The functionality and semantics of those macros is similar to circular
queues defined in \f[B]queue\f[](3).
.PP
The majority of the macros must specify the handle to the memory pool
\f[I]pop\f[] and the name of the \f[I]field\f[] in the user\-defined
structure, which must be of type \f[I]POBJ_LIST_ENTRY\f[] and is used to
connect the elements in the list.
.PP
A list is headed by a structure defined by the \f[B]POBJ_LIST_HEAD\f[]()
macro.
This structure contains an object handle of the first element on the
list.
The elements are doubly linked so that an arbitrary element can be
removed without a need to traverse the list.
New elements can be added to the list before or after an existing
element, at the head of the list, or at the end of the list.
A list may be traversed in either direction.
A \f[I]POBJ_LIST_HEAD\f[] structure is declared as follows:
.IP
.nf
\f[C]
#define\ POBJ_LIST_HEAD(HEADNAME,\ TYPE)
struct\ HEADNAME
{
\ \ \ \ TOID(TYPE)\ pe_first;
\ \ \ \ PMEMmutex\ lock;
};
\f[]
.fi
.PP
In the macro definitions, \f[I]TYPE\f[] is the name of a user\-defined
structure, that must contain a field of type \f[I]POBJ_LIST_ENTRY\f[].
The argument \f[I]HEADNAME\f[] is the name of a user\-defined structure
that must be declared using the macro \f[I]POBJ_LIST_HEAD\f[].
See the examples below for further explanation of how these macros are
used.
.PP
The macro \f[I]POBJ_LIST_ENTRY\f[] declares a structure that connects
the elements in the list.
.IP
.nf
\f[C]
#define\ POBJ_LIST_ENTRY(TYPE)
struct
{
\ \ \ \ TOID(TYPE)\ pe_next;
\ \ \ \ TOID(TYPE)\ pe_prev;
};
\f[]
.fi
.PP
The macro \f[B]POBJ_LIST_FIRST\f[]() returns the first element on the
list referenced by \f[I]head\f[].
If the list is empty \f[B]OID_NULL\f[] is returned.
.PP
The macro \f[B]POBJ_LIST_LAST\f[]() returns the last element on the list
referenced by \f[I]head\f[].
If the list is empty \f[B]OID_NULL\f[] is returned.
.PP
The macro \f[B]POBJ_LIST_EMPTY\f[]() evaluates to 1 if the list
referenced by \f[I]head\f[] is empty.
Otherwise, 0 is returned.
.PP
The macro \f[B]POBJ_LIST_NEXT\f[]() returns the element next to the
element \f[I]elm\f[].
.PP
The macro \f[B]POBJ_LIST_PREV\f[]() returns the element preceding the
element \f[I]elm\f[].
.PP
The macro \f[B]POBJ_LIST_FOREACH\f[]() traverses the list referenced by
\f[I]head\f[] assigning a handle to each element in turn to \f[I]var\f[]
variable.
.PP
The macro \f[B]POBJ_LIST_FOREACH_REVERSE\f[]() traverses the list
referenced by \f[I]head\f[] in reverse order, assigning a handle to each
element in turn to \f[I]var\f[] variable.
The \f[I]field\f[] argument is the name of the field of type
\f[I]POBJ_LIST_ENTRY\f[] in the element structure.
.PP
The macro \f[B]POBJ_LIST_INSERT_HEAD\f[]() inserts the element
\f[I]elm\f[] at the head of the list referenced by \f[I]head\f[].
.PP
The macro \f[B]POBJ_LIST_INSERT_TAIL\f[]() inserts the element
\f[I]elm\f[] at the end of the list referenced by \f[I]head\f[].
.PP
The macro \f[B]POBJ_LIST_INSERT_AFTER\f[]() inserts the element
\f[I]elm\f[] into the list referenced by \f[I]head\f[] after the element
\f[I]listelm\f[].
If \f[I]listelm\f[] value is \f[B]TOID_NULL\f[], the object is inserted
at the end of the list.
.PP
The macro \f[B]POBJ_LIST_INSERT_BEFORE\f[]() inserts the element
\f[I]elm\f[] into the list referenced by \f[I]head\f[] before the
element \f[I]listelm\f[].
If \f[I]listelm\f[] value is \f[B]TOID_NULL\f[], the object is inserted
at the head of the list.
.PP
The macro \f[B]POBJ_LIST_INSERT_NEW_HEAD\f[]() atomically allocates a
new object of size \f[I]size\f[] and inserts it at the head of the list
referenced by \f[I]head\f[].
The newly allocated object is also added to the internal object
container associated with a type number which is retrieved from the
typed \f[I]OID\f[] of the first element on list.
.PP
The macro \f[B]POBJ_LIST_INSERT_NEW_TAIL\f[]() atomically allocates a
new object of size \f[I]size\f[] and inserts it at the tail of the list
referenced by \f[I]head\f[].
The newly allocated object is also added to the internal object
container associated with with a type number which is retrieved from the
typed \f[I]OID\f[] of the first element on list.
.PP
The macro \f[B]POBJ_LIST_INSERT_NEW_AFTER\f[]() atomically allocates a
new object of size \f[I]size\f[] and inserts it into the list referenced
by \f[I]head\f[] after the element \f[I]listelm\f[].
If \f[I]listelm\f[] value is \f[B]TOID_NULL\f[], the object is inserted
at the end of the list.
The newly allocated object is also added to the internal object
container associated with with a type number which is retrieved from the
typed \f[I]OID\f[] of the first element on list.
.PP
The macro \f[B]POBJ_LIST_INSERT_NEW_BEFORE\f[]() atomically allocates a
new object of size \f[I]size\f[] and inserts it into the list referenced
by \f[I]head\f[] before the element \f[I]listelm\f[].
If \f[I]listelm\f[] value is \f[B]TOID_NULL\f[], the object is inserted
at the head of the list.
The newly allocated object is also added to the internal object
container associated with with a type number which is retrieved from the
typed \f[I]OID\f[] of the first element on list.
.PP
The macro \f[B]POBJ_LIST_REMOVE\f[]() removes the element \f[I]elm\f[]
from the list referenced by \f[I]head\f[].
.PP
The macro \f[B]POBJ_LIST_REMOVE_FREE\f[]() removes the element
\f[I]elm\f[] from the list referenced by \f[I]head\f[] and frees the
memory space represented by this element.
.PP
The macro \f[B]POBJ_LIST_MOVE_ELEMENT_HEAD\f[]() moves the element
\f[I]elm\f[] from the list referenced by \f[I]head\f[] to the head of
the list \f[I]head_new\f[].
The \f[I]field\f[] and \f[I]field_new\f[] arguments are the names of the
fields of type \f[I]POBJ_LIST_ENTRY\f[] in the element structure that
are used to connect the elements in both lists.
.PP
The macro \f[B]POBJ_LIST_MOVE_ELEMENT_TAIL\f[]() moves the element
\f[I]elm\f[] from the list referenced by \f[I]head\f[] to the end of the
list \f[I]head_new\f[].
The \f[I]field\f[] and \f[I]field_new\f[] arguments are the names of the
fields of type \f[I]POBJ_LIST_ENTRY\f[] in the element structure that
are used to connect the elements in both lists.
.PP
The macro \f[B]POBJ_LIST_MOVE_ELEMENT_AFTER\f[]() atomically removes the
element \f[I]elm\f[] from the list referenced by \f[I]head\f[] and
inserts it into the list referenced by \f[I]head_new\f[] after the
element \f[I]listelm\f[].
If \f[I]listelm\f[] value is \f[I]TOID_NULL\f[], the object is inserted
at the end of the list.
The \f[I]field\f[] and \f[I]field_new\f[] arguments are the names of the
fields of type \f[I]POBJ_LIST_ENTRY\f[] in the element structure that
are used to connect the elements in both lists.
.PP
The macro \f[B]POBJ_LIST_MOVE_ELEMENT_BEFORE\f[]() atomically removes
the element \f[I]elm\f[] from the list referenced by \f[I]head\f[] and
inserts it into the list referenced by \f[I]head_new\f[] before the
element \f[I]listelm\f[].
If \f[I]listelm\f[] value is \f[B]TOID_NULL\f[], the object is inserted
at the head of the list.
The \f[I]field\f[] and \f[I]field_new\f[] arguments are the names of the
fields of type \f[I]POBJ_LIST_ENTRY\f[] in the element structure that
are used to connect the elements in both lists.
.SH SEE ALSO
.PP
\f[B]queue\f[](3), \f[B]libpmemobj\f[](7) and \f[B]<http://pmem.io>\f[]