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
|
/* Copyright (c) 2003, 2005, 2006 MySQL AB
Use is subject to license terms
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
#ifndef DLC_FIFOLIST_HPP
#define DLC_FIFOLIST_HPP
#include "DLFifoList.hpp"
#include <NdbOut.hpp>
// Adds "count" to DLFifoList
template <class T, class U = T>
class DLCFifoList : public DLFifoList<T, U> {
public:
// List head
struct Head : public DLFifoList<T, U>::Head {
Head() : m_count(0) {}
Uint32 m_count;
};
// Ctor
DLCFifoList(ArrayPool<T> & thePool) :
DLFifoList<T, U>(thePool)
{}
// Get count
Uint32 count() const { return head.m_count; }
// Redefine methods which do add or remove
bool seize(Ptr<T>& ptr) {
if (DLFifoList<T, U>::seize(ptr)) {
head.m_count++;
return true;
}
return false;
}
bool seizeId(Ptr<T>& ptr, Uint32 i) {
if (DLFifoList<T, U>::seizeId(ptr)) {
head.m_count++;
return true;
}
return false;
}
void add(Ptr<T>& ptr) {
DLFifoList<T, U>::add(ptr);
head.m_count++;
}
void remove(Ptr<T>& ptr) {
DLFifoList<T, U>::remove(ptr);
head.m_count--;
}
void release(Uint32 i) {
DLFifoList<T, U>::release(i);
head.m_count--;
}
void release(Ptr<T>& ptr) {
DLFifoList<T, U>::release(ptr);
head.m_count--;
}
void release() {
DLFifoList<T, U>::release();
head.m_count = 0;
}
DLCFifoList<T>& operator=(const DLCFifoList<T>& src){
assert(&this->thePool == &src.thePool);
this->head = src.head;
return * this;
}
protected:
Head head;
};
// Local variant
template <class T, class U = T>
class LocalDLCFifoList : public DLCFifoList<T, U> {
public:
LocalDLCFifoList(ArrayPool<T> & thePool,
typename DLCFifoList<T, U>::Head &_src)
: DLCFifoList<T, U>(thePool), src(_src)
{
this->head = src;
#ifdef VM_TRACE
assert(src.in_use == false);
src.in_use = true;
#endif
}
~LocalDLCFifoList() {
#ifdef VM_TRACE
assert(src.in_use == true);
#endif
src = this->head;
}
private:
typename DLCFifoList<T, U>::Head & src;
};
#endif
|