2
Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
4
This program is free software; you can redistribute it and/or modify
5
it under the terms of the GNU General Public License as published by
6
the Free Software Foundation; version 2 of the License.
8
This program is distributed in the hope that it will be useful,
9
but WITHOUT ANY WARRANTY; without even the implied warranty of
10
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
GNU General Public License for more details.
13
You should have received a copy of the GNU General Public License
14
along with this program; if not, write to the Free Software
15
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
#ifndef SLFIFOLIST_HPP
19
#define SLFIFOLIST_HPP
21
#include <ndb_global.h>
22
#include <kernel_types.h>
26
* Template class used for implementing an
27
* list of object retreived from a pool
29
template <typename P, typename T, typename U = T>
45
inline bool isEmpty() const { return firstItem == RNIL;}
48
struct Head : public HeadPOD
50
Head() { this->init();}
52
Head& operator=(const HeadPOD& src) {
53
this->firstItem = src.firstItem;
54
this->lastItem = src.lastItem;
56
this->in_use = src.in_use;
61
SLFifoListImpl(P & thePool);
63
bool seizeFirst(Ptr<T> &);
64
bool seizeLast(Ptr<T> &);
65
bool seize(Ptr<T> & ptr) { return seizeLast(ptr);}
67
void releaseFirst(Ptr<T> &);
69
void addFirst(Ptr<T> &);
70
void addLast(Ptr<T> &);
72
void removeFirst(Ptr<T> &);
73
void remove() { head.init(); }
76
* Update i & p value according to <b>i</b>
78
void getPtr(Ptr<T> &, Uint32 i) const;
81
* Update p value for ptr according to i value
83
void getPtr(Ptr<T> &) const ;
86
* Get pointer for i value
88
T * getPtr(Uint32 i) const ;
91
* Update ptr to first element in list
95
bool first(Ptr<T> &) const ;
98
* Update ptr to first element in list
102
bool last(Ptr<T> &) const ;
107
* NOTE ptr must be both p & i
109
bool next(Ptr<T> &) const ;
112
* Check if next exists i.e. this is not last
114
* NOTE ptr must be both p & i
116
bool hasNext(const Ptr<T> &) const;
118
inline bool isEmpty() const { return head.firstItem == RNIL;}
125
template <typename P, typename T, typename U = T>
126
class LocalSLFifoListImpl : public SLFifoListImpl<P,T,U>
129
LocalSLFifoListImpl(P & thePool, typename SLFifoListImpl<P,T,U>::HeadPOD&_src)
130
: SLFifoListImpl<P,T,U>(thePool), src(_src)
134
assert(src.in_use == false);
139
~LocalSLFifoListImpl(){
141
assert(src.in_use == true);
146
typename SLFifoListImpl<P,T,U>::HeadPOD & src;
149
template <typename P, typename T, typename U>
151
SLFifoListImpl<P,T,U>::SLFifoListImpl(P & _pool):
156
template <typename P, typename T, typename U>
159
SLFifoListImpl<P,T,U>::HeadPOD::init()
161
this->firstItem = RNIL;
162
this->lastItem = RNIL;
164
this->in_use = false;
168
template <typename P, typename T, typename U>
171
SLFifoListImpl<P,T,U>::seizeFirst(Ptr<T> & p)
173
if (likely(thePool.seize(p)))
182
template <typename P, typename T, typename U>
185
SLFifoListImpl<P,T,U>::seizeLast(Ptr<T> & p)
187
if (likely(thePool.seize(p)))
196
template <typename P, typename T, typename U>
199
SLFifoListImpl<P,T,U>::addFirst(Ptr<T> & p)
201
Uint32 first = head.firstItem;
202
head.firstItem = p.i;
207
p.p->U::nextList = first;
210
template <typename P, typename T, typename U>
213
SLFifoListImpl<P,T,U>::addLast(Ptr<T> & p)
216
Uint32 last = head.lastItem;
218
t->U::nextList = RNIL;
223
T * t2 = thePool.getPtr(last);
224
t2->U::nextList = p.i;
228
head.firstItem = p.i;
232
template <typename P, typename T, typename U>
235
SLFifoListImpl<P,T,U>::removeFirst(Ptr<T> & p)
237
Uint32 first = head.firstItem;
238
Uint32 last = head.lastItem;
239
assert(p.i == first);
242
head.firstItem = p.p->U::nextList;
246
head.firstItem = head.lastItem = RNIL;
250
template <typename P, typename T, typename U>
253
SLFifoListImpl<P,T,U>::releaseFirst(Ptr<T> & p)
259
template <typename P, typename T, typename U>
262
SLFifoListImpl<P,T,U>::getPtr(Ptr<T> & p, Uint32 i) const
265
p.p = thePool.getPtr(i);
268
template <typename P, typename T, typename U>
271
SLFifoListImpl<P,T,U>::getPtr(Ptr<T> & p) const
276
template <typename P, typename T, typename U>
279
SLFifoListImpl<P,T,U>::getPtr(Uint32 i) const
281
return thePool.getPtr(i);
285
* Update ptr to first element in list
289
template <typename P, typename T, typename U>
292
SLFifoListImpl<P,T,U>::first(Ptr<T> & p) const
294
p.i = head.firstItem;
297
p.p = thePool.getPtr(p.i);
304
template <typename P, typename T, typename U>
307
SLFifoListImpl<P,T,U>::last(Ptr<T> & p) const
312
p.p = thePool.getPtr(p.i);
319
template <typename P, typename T, typename U>
322
SLFifoListImpl<P,T,U>::next(Ptr<T> & p) const
324
p.i = p.p->U::nextList;
327
p.p = thePool.getPtr(p.i);
334
template <typename P, typename T, typename U>
337
SLFifoListImpl<P,T,U>::hasNext(const Ptr<T> & p) const
339
return p.p->U::nextList != RNIL;
344
template <typename T, typename U = T>
345
class SLFifoList : public SLFifoListImpl<ArrayPool<T>, T, U>
348
SLFifoList(ArrayPool<T> & p) : SLFifoListImpl<ArrayPool<T>, T, U>(p) {}
351
template <typename T, typename U = T>
352
class LocalSLFifoList : public LocalSLFifoListImpl<ArrayPool<T>,T,U> {
354
LocalSLFifoList(ArrayPool<T> & p, typename SLFifoList<T,U>::Head & _src)
355
: LocalSLFifoListImpl<ArrayPool<T>,T,U>(p, _src) {}