~ubuntu-branches/ubuntu/precise/mysql-5.1/precise

« back to all changes in this revision

Viewing changes to storage/ndb/src/kernel/vm/DLCFifoList.hpp

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Tretkowski
  • Date: 2010-03-17 14:56:02 UTC
  • Revision ID: james.westby@ubuntu.com-20100317145602-x7e30l1b2sb5s6w6
Tags: upstream-5.1.45
ImportĀ upstreamĀ versionĀ 5.1.45

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2003 MySQL AB
 
2
 
 
3
   This program is free software; you can redistribute it and/or modify
 
4
   it under the terms of the GNU General Public License as published by
 
5
   the Free Software Foundation; version 2 of the License.
 
6
 
 
7
   This program is distributed in the hope that it will be useful,
 
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
10
   GNU General Public License for more details.
 
11
 
 
12
   You should have received a copy of the GNU General Public License
 
13
   along with this program; if not, write to the Free Software
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
15
 
 
16
#ifndef DLC_FIFOLIST_HPP
 
17
#define DLC_FIFOLIST_HPP
 
18
 
 
19
#include "DLFifoList.hpp"
 
20
#include <NdbOut.hpp>
 
21
 
 
22
// Adds "count" to DLFifoList
 
23
template <class T, class U = T>
 
24
class DLCFifoList : public DLFifoList<T, U> {
 
25
public:
 
26
  // List head
 
27
  struct Head : public DLFifoList<T, U>::Head {
 
28
    Head() : m_count(0) {}
 
29
    Uint32 m_count;
 
30
  };
 
31
  
 
32
  // Ctor
 
33
  DLCFifoList(ArrayPool<T> & thePool) :
 
34
    DLFifoList<T, U>(thePool)
 
35
  {}
 
36
 
 
37
  // Get count
 
38
  Uint32 count() const { return head.m_count; }
 
39
 
 
40
  // Redefine methods which do add or remove
 
41
  
 
42
  bool seize(Ptr<T>& ptr) {
 
43
    if (DLFifoList<T, U>::seize(ptr)) {
 
44
      head.m_count++;
 
45
      return true;
 
46
    }
 
47
    return false;
 
48
  }
 
49
 
 
50
  bool seizeId(Ptr<T>& ptr, Uint32 i) {
 
51
    if (DLFifoList<T, U>::seizeId(ptr)) {
 
52
      head.m_count++;
 
53
      return true;
 
54
    }
 
55
    return false;
 
56
  }
 
57
  
 
58
  void add(Ptr<T>& ptr) {
 
59
    DLFifoList<T, U>::add(ptr);
 
60
    head.m_count++;
 
61
  }
 
62
 
 
63
  void remove(Ptr<T>& ptr) {
 
64
    DLFifoList<T, U>::remove(ptr);
 
65
    head.m_count--;
 
66
  }
 
67
 
 
68
  void release(Uint32 i) {
 
69
    DLFifoList<T, U>::release(i);
 
70
    head.m_count--;
 
71
  }
 
72
  
 
73
  void release(Ptr<T>& ptr) {
 
74
    DLFifoList<T, U>::release(ptr);
 
75
    head.m_count--;
 
76
  }
 
77
 
 
78
  void release() {
 
79
    DLFifoList<T, U>::release();
 
80
    head.m_count = 0;
 
81
  }
 
82
 
 
83
  DLCFifoList<T>& operator=(const DLCFifoList<T>& src){
 
84
    assert(&this->thePool == &src.thePool);
 
85
    this->head = src.head;
 
86
    return * this;
 
87
  }
 
88
 
 
89
protected:
 
90
  Head head;
 
91
};
 
92
 
 
93
// Local variant
 
94
template <class T, class U = T>
 
95
class LocalDLCFifoList : public DLCFifoList<T, U> {
 
96
public:
 
97
  LocalDLCFifoList(ArrayPool<T> & thePool,
 
98
                   typename DLCFifoList<T, U>::Head &_src)
 
99
    : DLCFifoList<T, U>(thePool), src(_src)
 
100
  {
 
101
    this->head = src;
 
102
#ifdef VM_TRACE
 
103
    assert(src.in_use == false);
 
104
    src.in_use = true;
 
105
#endif
 
106
  }
 
107
  
 
108
  ~LocalDLCFifoList() {
 
109
#ifdef VM_TRACE
 
110
    assert(src.in_use == true);
 
111
#endif
 
112
    src = this->head;
 
113
  }
 
114
private:
 
115
  typename DLCFifoList<T, U>::Head & src;
 
116
};
 
117
 
 
118
#endif